A tool for efficient usage of translations stored in google spreadsheet
$ npm install -g lokse
$ lokse COMMAND
running command...
$ lokse (-v|--version|version)
lokse/3.0.0 darwin-arm64 node-v20.11.1
$ lokse --help [COMMAND]
USAGE
$ lokse COMMAND
...
The last version of Google Spreadsheets API requires us to be authenticated to allow fetching spreadsheet data. Read more about authentication here
CLI uses Cosmiconfig
which means you can hold the configuration in any format it supports.
So just create lokse.config.js
, .lokserc
, .lokserc.yml
, .lokserc.json
or add lokse
property into the package.json
and there you can setup on of the options:
Spreadsheet id. When you open your spreadsheet it's this string
Output directory where generated translation files will be written to.
List of languages you want to generate translations for. Also names of columns in spreadsheet.
Name of spreadsheet columm containing translation ids.
Format of output translation file.
Target spreadsheet can contain more than one sheet and default behaviour is to use all of them, but sometimes you need only some of them. This option determines sheets to fetch translations from. You can define sheets you want to use or those you don't want to or combine these definition.
You can choose from various formats to define sheets to use
-
Special value
*
means to include all sheets and is the default behaviour when you omit thesheets
option.{ "sheets": "*", }
-
Titles of sheets to use. Can be string or array of strings
{ "sheets": "Web translations", } // or { "sheets": ["App translations", "Legal docs"] }
-
Definition of sheets to include or exclude from the list of all sheets. Can be one of formats mentioned above
{ "sheets": { "include": ["Web translations", "Legal docs"], "exclude": "CMS translations" } } // or { "sheets": { "exclude": ["CMS translations"] } } // or { "sheets": { "include": ["Web translations", "Legal docs"], } }
Enables splitting translations into multiple files which is useful for lazy loading of some big parts of translations (eg. translation of the whole legal document).
You have two ways of how to split your translations:
-
Split by sheets -
splitTranslations: true
- each sheet means one translations file and name of file is determined by sheet title. Given 3 sheets in yout spreadsheet named "App translations", "Legal docs", "Landing Page" the result will be 3 files namedapp-translations.cs.json
,legal-docs.cs.json
,landing-page.cs.json
(of course the language and format depends on your settings). -
Split by domains -
splitTranslations: string[]
- this configuration expects an array of domain names. Domain is a first part of your translation id, given translation idnews.mostRead.error.text
the domain isnews
. The domain name determines also the filename,news.cs.json
in our example.
Translations that starts with domainnews.
will be written into thenews.cs.json
, other translations that does not belong to any other group will be saved into general translations in filecs.json
.
The splitTranslations
option can be provided only through configuration not inline CLI parameter.
List of plugins to use. Plugin can be either name of plugin, or object containing name and options. You must install first.
$ yarn add -D @lokse/plugin-prettify @lokse/plugin-transform-values
plugins: [
"@lokse/plugin-prettify",
{
"name": "@lokse/plugin-transform-values",
"options": {
"uppercase": "true"
}
}
],
{
"sheetId": "1HKjvejcuHIY73WvEkipD7_dmF9dFeNLji3nS2RXcIzk",
"dir": "locales",
"languages": ["cs", "en", "fr"],
"column": "key_web",
"format": "json",
"sheets": ["App translations", "Legal docs"],
"splitTranslations": ["news", "documents"],
"plugins": []
}
display help for lokse
USAGE
$ lokse help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
See code: @oclif/plugin-help
create a new config file
USAGE
$ lokse init
OPTIONS
-h, --help show CLI help
EXAMPLE
$ lokse init
See code: lib/commands/init.js
open localization spreadsheet in default browser
USAGE
$ lokse open
OPTIONS
-h, --help show CLI help
-i, --id=id spreadsheet id
EXAMPLE
$ lokse open -i 1HKjvejcuHIY73WvEkipD7_dmF9dFeNLji3nS2RXcIzk
See code: lib/commands/open.js
update translations from localization spreadsheet
USAGE
$ lokse update
OPTIONS
-c, --col=col column containing translations keys. For example key_web.
-d, --dir=dir output folder
-f, --format=(json|android|ios) output format. Default is json.
-h, --help show CLI help
-i, --id=id spreadsheet id
-l, --languages=languages translation columns languages. Multiple values are comma separated. For example
cs,en,fr
-s, --sheets=sheets sheets to get translations from. Name or list of names, comma separated. For example
Translations1,Translations2
EXAMPLES
$ lokse update
$ lokse update -i 1HKjvejcuHIY73WvEkipD7_dmF9dFeNLji3nS2RXcIzk -d locales -l cz,en,fr -t key_web
See code: lib/commands/update.js