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

twitch-intl-cli1

v4.4.0

Published

CLI tools for i18n message extraction and smartling upload/download

Downloads

8

Readme

Twitch Intl CLI

A CLI utility for managing managing localized in typescript code, uploading and downloading from smartling (via Loom).

A primary feature is the ability to identify and extract strings from uses of formatMessage() function calls in typescript+react code, but flat string dictionaries in JSON format are also supported.

Background

This is a tool originally developed for the Twilight project. It is designed to work with the runtime package twitch-intl and handle the work of getting the strings in your Typescript code translated, and those translations back into your project. A core expectation is that your strings are tracked by your source control: either in code as function calls, or in a flat JSON file. If your strings exist in some other format, or simply don't live in source control, this isn't the tool for you.

This is published as an NPM package to the private Twitch NPM repository. Installing it locally to your project is recommended (yarn add --dev twitch-intl-cli) after which you may use it in your package.json scripts or via npx twitch-intl.

All sub-commands deal with "extracting" strings from your project, so you will be using one of either the --source-files or --strings-dict options to specify where your strings can be found.

All sub-commands besides extract require connectivity to Loom. The CLI will default to assuming AWS credentials with permissions to invoke Loom API endpoints are present in your environment. When running from a developer laptop, it is far easier to simply include the --midway flag to switch to Midway cookie-based authentication.

CLI Usage

The CLI is broken into several sub-commands, the primary two being upload and download.

Detailed help is available for each command in the shell.

Usage: twitch-intl [options] [command]

A simple CLI to manage localization. Uses `git` style subcommands.

Options:
  -V, --version               output the version number
  -h, --help                  display help for command

Commands:
  extract [options]           Extract messages found in formatMessage() calls.
  upload [options]            Upload extracted messages to Loom, optionally submitting them for translation
  download [options]          Download translated messages from smartling.
  submission-check [options]  Check for unsubmitted strings and fail if any are found
  help [command]              display help for command

twitch-intl upload

Usage: twitch-intl upload [options]

Upload extracted messages to Loom, optionally submitting them for translation

Options:
  -V, --version                  output the version number
  --exclude-from <remotebranch>  exclude strings committed in this git branch (e.g. "origin/main")
  --exclude-uploaded             exclude strings previously uploaded to Loom
  --jira-ticket <ticket>         produces a fatal error if not formatted like a JIRA ticket
  -P, --prompt                   display new/changed strings for confirmation before uploading, allowing for entry of
                                 context
  --submit                       submits strings for translation after uploading
  --force-submit                 (use with --submit) will overwrite all existing strings for given jira ticket
  --strings-dict <filePath>      Path to a flat JSON file of strings to use for the project
  -S, --source-files <fileGlob>  Glob matching TS files containing formatMessage calls
  --allow-top-level              Allow formatMessage to be called from a file-level context. (potentially before intl
                                 has initialized)
  --debug                        Enables debug output
  --format-func <func-name>      Set the name of the function used to translate strings (default: "formatMessage")
  -p, --project-id <id>          loom project id
  -m, --midway                   connect to Loom using Midway cookies over HTTPS instead of using local AWS credentials
                                 for direct lambda calls
  --loom-dev                     perform operations talking to loom-dev instead of loom-prod
  -h, --help                     display help for command

Typical usage of the upload command will probably look like:

twitch-intl upload --project-id moonlight --source-files "src/**/*.ts?(x)" --exclude-from origin/main --submit --prompt --jira-ticket LOC-9999

This will extract and submit any new/changed strings on disk for translation and comment on the corresponding Jira ticket.

twitch-intl download

Usage: twitch-intl download [options]

Download translated messages from Loom into a JSON file per locale

Options:
  -V, --version                  output the version number
  -o, --outfile <filename>       name of the output file to be created in each locale folder (default: "messages.json")
  -d, --outdir <path>            path to folder where language json folders will be saved (default: "./")
  --strings-dict <filePath>      Path to a flat JSON file of strings to use for the project
  -S, --source-files <fileGlob>  Glob matching TS files containing formatMessage calls
  --allow-top-level              Allow formatMessage to be called from a file-level context. (potentially before intl
                                 has initialized)
  --debug                        Enables debug output
  --format-func <func-name>      Set the name of the function used to translate strings (default: "formatMessage")
  -p, --project-id <id>          loom project id
  -m, --midway                   connect to i18n service using Midway authentication
  --loom-dev                     perform operations talking to loom-dev instead of loom-prod
  -h, --help                     display help for command

Typical useage of the download command will often look like:

twitch-intl download --project-id moonlight --source-files "src/**/*.ts?(x)" --outdir locales

This will extract the set of messages in use in the current codebase, then download and output JSON files into ./locales/<LOCALE>/messages.json for each enabled locale of the corresponding Smartling project.

twitch-intl submission-check

Usage: twitch-intl submission-check [options]

Check for unsubmitted strings and fail if any are found

Options:
  -V, --version                  output the version number
  -i, --invert                   Instead, fail when any strings found have been submitted (use with --format-func
                                 formatMessageDraft)
  --strings-dict <filePath>      Path to a flat JSON file of strings to use for the project
  -S, --source-files <fileGlob>  Glob matching TS files containing formatMessage calls
  --allow-top-level              Allow formatMessage to be called from a file-level context. (potentially before intl
                                 has initialized)
  --debug                        Enables debug output
  --format-func <func-name>      Set the name of the function used to translate strings (default: "formatMessage")
  -p, --project-id <id>          loom project id
  -m, --midway                   connect to i18n service using Midway authentication
  --loom-dev                     perform operations talking to loom-dev instead of loom-prod
  -h, --help                     display help for command

Example:

twitch-intl submission-check --project-id moonlight --source-files "src/**/*.ts?(x)"

This exits with a non-zero status code if any strings found in the current codebase are unknown to Loom. This is most useful for a CI check to prevent merges with untranslated strings.

Developing

yarn start will spin up a local dev server for working on the web UI for string confirmation. yarn build compiles the code into a shipable dist folder. yarn test runs all the tests!

Releasing

  1. Update src/config.ts with the new version, commit to git.
  2. Run yarn version to set the new version to match. (creates git commit and tags)
  3. Push with tags git push --follow-tags and publish npm publish