npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zendesk-translations-writer

v0.1.0

Published

Transpile Readme into manifest and translations.

Downloads

9

Readme

Overview

This package will allow you to write your Zendesk manifest from a Readme file. This makes reviewing layout, spelling, and grammar much easier (since it isn't all in one long JSON string). This package also includes the ability to automatically update your translations files (and make them available in an importable JS file) from Google's Translate API.

To see how this works, check out the Zendesk Awesomeness App. The app doesn't do anything meaningful, but it does show how to leverage this package in your build process (and automate the compilation of a Zendesk App using NPM scripts).

Setup

You will need four environment variables, or you will need to pass these values in as command line arguments in the order they are listed.

  • GOOGLE_CLIENT_ID - Client ID for Google OAuth App
  • GOOGLE_CLIENT_SECRET - Client Secret for Google OAuth App
  • GOOGLE_REDIRECT_URI - Redirect URI used to generate below refresh token
  • GOOGLE_REFRESH_TOKEN - Refresh Token with https://www.googleapis.com/auth/cloud-translation scope. Note: when retrieving an authorization code, pass in access_type=offline to get a refresh token.

Use

Once you install the package in your app development project, npm i -D zendesk-translations-writer, you can use it in your build process. For example, here we define a translate script and call it as part of our build:

"scripts": {
    "translate": "zendesk-translations-writer",
    "build": "npm run translate && rollup -c"
}

In order for this package to work[^todo-tests] right[^todo-config] you will need:

  • A src/ directory where translations.js will be saved.
  • A translations/ directory with JSON files for each locale you want to support. (They can be blank to start.)
  • A translations/en.json file with the defaults section populated with the default translations.[^todo-config]
  • A manifest.json file
  • A README.md file

The translations.js file exports all of the "default" values from your assorted translations JSON files. For example, given two defaults in the en.json file and a de.json file, this package will get the German translations from the Google Translate API, update the de.json accordingly, and create a translations.js file similar to:

export const translations = {
    "de": {
        "default": {
            "awesome": "Eindrucksvoll",
            "rateyour": "Bewerten Sie Ihr tolles"
        }
    },
    "en": {
        "default": {
            "awesome": "Awesome",
            "rateyour": "Rate your awesome"
        }
    }
};

The Readme File Format

You will want to have the following sections in your readme file:

  • Name
  • Short Description
  • Long Description
  • Installation Instructions

These are well documented here.

In the Installation Instructions section I recommend documenting your parameters as well (at least, for the purposes of this package, it is otherwise optional). Parameters will be documented under a Configuration Options subsection (proceeded with two hash-marks). Within this subsection you will document your parameters thusly:

<!-- parameter_name -->
* **Label**: Help Text
<!-- other_parameter_name -->
* **Other Label**: Other Help Text
.
.
.

Manifest updates

You can have optional sections for:

  • Author - this section is described below
  • TermsConditionsURL - this section would only have the URL (not formatted as a link using markdown).

These will update the manifest.json file.[^todo-manifest] The author section is special and should be formatted thusly:

# Author
Name: {{author's name}}
Email: {{author's email}}
URL: {{author's url}}

[^todo-tests]: Assuming everything functions as designed as there are no unit tests right now. This is a todo. [^todo-config]: At least until I update it to allow more robust configuration, such as setting file locations and the default locale. [^todo-manifest]: It is an outstanding TODO to expand this package to support a complete generation of the manifest from the readme file.