@guestlinelabs/onekey
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

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;

Readme

Keywords

none

Package Sidebar

Install

npm i @guestlinelabs/onekey

Weekly Downloads

539

Version

3.1.0

License

ISC

Unpacked Size

104 kB

Total Files

42

Last publish

Collaborators

  • imperium02
  • davethemac
  • mkredz
  • dave-hillier
  • missbruni
  • rameshanandakrishnan
  • pbazydlo
  • guru_fordy
  • greg.plenzler
  • rachel.sinclair