Skip to content

guestlinelabs/onekey

Repository files navigation

onekey

Utility to download translations from OneSky and generate typed keys in Typescript for having typed translations.

Installation

npm install @guestlinelabs/onekey

Usage

There are two main commands to use: Fetch translations and Generate translation keys

Fetch translations

Usage: onekey fetch [options]

Options:

  -o, --out      Path where translations will be saved
  -p, --project  Numeric id of the OneSky project
  -f, --files    Names of the files to download from the OneSky project separated by commas
  -s, --secret   OneSky private key (it can be read from environment variable ONESKY_PRIVATE_KEY)
  -k, --apiKey   OneSky API key (it can be read from environment variable ONESKY_PUBLIC_KEY)
  -c, --prettier [OPTIONAL] Path for the prettier config

Generate translation keys

Usage: onekey generate [options]

Options:

  -i, --input    Path for the json translations to read from
  -l, --locale   [OPTIONAL] Default locale to use (en-GB by default)
  -c, --prettier [OPTIONAL] Path for the prettier config

Generated output

This will generate a TypeScript type union with all the possible translation keys for your jsons (appended with the namespace that comes from the name of the file).

So if your translation files look like this

// main.json
{
  "hello": "Hello, friend",
  "friendly_hello": "Hello, {{name}}",
  "goodbye": "See you soon!",
}
// errors.json
{
  "hello": "Hello, seems there is a problem here!",
  "unknown": "I don't know what happened, but looks bad!",
}

Generate will give you something closer to this:

type TranslationKeyWithoutOptions =
  | 'main:hello'
  | 'main:goodbye'
  | 'errors:hello'
  | 'errors:unknown';
type TranslationWithOptions = {
  'main:friendly_hello': { name: string };
};
type TranslationKeyWithOptions = keyof TranslationWithOptions;

export type TranslationKey =
  | TranslationKeyWithoutOptions
  | TranslationKeyWithOptions;

About

Utility to download translations from the OneSky and generate a TypeScript union string type with all the translation keys.

Resources

License

Stars

Watchers

Forks

Packages

No packages published