@guestlinelabs/onekey
v3.1.2
Published
Utility to download translations from the [OneSky](https://www.oneskyapp.com/) and generate typed keys in Typescript for having typed translations.
Downloads
1,582
Maintainers
Keywords
Readme
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;