0.5.8 • Published 6 months ago
@targetprocess/translation-tools v0.5.8
Description
Library contains tools to build end-to-end translation process inside CI pipeline.
Install
npm install @targetprocess/translation-tools
yarn add @targetprocess/translation-tools
Prerequisites
Localizable solution has to include the following parts:
- Git repository with localization dictionaries.
- Source project which contains strings in localizable format inside its source code. Project uses localization dictionaries to take string's translated value according to the current locale.
Translation process
- Scan source project and extract localizable strings.
- Send extracted strings to localization dictionaries repository.
Format of localizable strings
tau-extract-gettext is used to extract localizable strings from the source project. Please refer to this library for information about the format of localizable strings.
Example of usage
- Add translations-uploader script.
scripts/localization/translations-uploader.js
const process = require('process');
// Function to perform end-to-end translation of the source project
// See "Translation process" section and function documentation for more details
const uploader = require('@targetprocess/translation-tools');
// Path to the source project with localizable strings
const [, , sourcePath] = process.argv;
// Each service has it's own folder in localization dictionaries repository. For instance: 'show-relations
const dictionariesFolder = process.env.DICTIONARIES_FOLDER;
uploader(sourcePath, dictionariesFolder)
.catch(error => {
console.error(error);
return process.exit(1);
});
- Add .gitlab-ci localization job definition.
Localization dictionaries repository can be updated during this job. Therefore localization stage should precede libraries installation stage for the source project.
localization:
stage: localization
image: targetprocess/docker-node-alpine-build:carbon
only:
- master
script:
# Add SSH key to access localization dictionaries repo
- chmod +x scripts/ci/add-gitlab-ssh.sh
- ./scripts/ci/add-gitlab-ssh.sh
# Configure Git to push translated resources to localization dictionaries repo
- git config --global user.email "myproject@targetprocess.com"
- git config --global user.name "Translation bot"
# Execute translation script
- cd scripts/localization
- yarn add @targetprocess/translation-tools
- node translations-uploader.js path-to-the-source-project
- Make sure to upgrade the reference to localization dictionaries repository.
...
- yarn upgrade localization-dictionaries
- yarn install
...