1.3.3 • Published 1 year ago

goe-localization-cli v1.3.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

goe-localization-cli

CLI for updating translation files provided by Lokalise tool

Description

The package is intended for projects using Lokalise tool. The CLI allows to communicate with Lokalise. Namely, you can download files with translations after they have been updated in Lokalise. You can also initiate translation update locally. To do that you have to change the base (English) translation file and upload it to Lokalise. When the tool has completed translating, you have then to download the rest translations.

The first iteration (goe-localization-cli@^1.0.0) supports the following structure of translation files:

path/to/translations/<language-ISO-code>/<translation-file-name>.json

where language-ISO-code represent codes like en, de, fr, etc., while translation-file-name is an arbitrary name same for all translation files. In other words, you have as many translation folders as you have languages in your application.

Installation

The package should be added as develop dependency:

yarn add goe-localization-cli -D

or

npm install goe-localization-cli --save-dev

To configure the package, you should add environment variables. The package allows to split the variables between two files. One of them, named .env, is optional. It can be public and kept directly in the repo. This file is designed to keep non-critical data. The other one, called .env.secret, is mandatory. It is designed to hold the variables which should not be compromised, so it is better to excluded this file from version control.

These files should contain the following variables the package will use:

LOKALISE_TOKEN This is a personal token to access Lokalise. To get this token:

It is strongly discouraged to keep the secret token a public .env.

LOKALISE_PROJECT_ID The identifier for the project within Lokalise

LOCALIZATION_FOLDER_PATH Path to folder with translations (relative of the project root)

LOCALIZATION_FILE_NAME (optional) Name of the JSON files with translations (including file extention).

If this parameter is provided, it will be used as the name of translation files for all languages, while each translation file will be placed inside folder named according to the language locale name.

If this parameter is not provided, each translation file will be named according to its language locale, while all files will be placed in a single folder.

Examples

LOCALIZATION_FILE_NAME set to translation.json

translation_folder (named as in `LOCALIZATION_FOLDER_PATH`)
 |
 |___en
 |    |
 |	  |___translation.json
 |
 |___de
      |
	  |___translation.json

LOCALIZATION_FILE_NAME not provided

translation_folder (named as in `LOCALIZATION_FOLDER_PATH`)
 |
 |___en.json
 |___de.json

The variables in .env files should be assigned according to the following rule:

<VARIABLE_NAME>=<value>

Usage

To upload updated English translation to Lokalise, run the following command:

translations upload

To get the updated translations from Lokalise, run the following command:

translations download

In case your system cannot find the translations command name, use the full path for binaries:

./node_modules/.bin/translations

If you need to sort keys in translation files in the alphabetical order regardless of keys' case (high or low), add sort_alphabetically line to the download command:

translations download sort_alphabetically

Known Issues

Currently there is a bug in "@lokalise/node-api". This bug converts "\n" for new line to "\n". To avoid this replace_breaks should be set to false.

By default replace_breaks is true, to set it to false use no_replace_breaks in download/upload command.

translations download no_replace_breaks
translations upload no_replace_breaks
1.3.3

1 year ago

1.3.1

1 year ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago