Talend i18n scripts
The i18n process has multiple steps
1- Extract and upload
2- Translation within the cloud system
3- Download and versionning to github
4- Download translated files to the bundle
The @talend/i18n-scripts module targets steps 1 - 2 - 3.
Installation
yarn global install @talend/i18n-scripts
or
npm install -g @talend/i18n-scripts
Now the cli talend-i18n
is available.
Actions
There are 4 actions you can perform
talend-i18n extract
talend-i18n upload
talend-i18n download
talend-i18n deploy
Configuration
The scripts are based on a talend-i18n.json
configuration file at project root.
This step will extract the i18n files from the project and create a zip.
All the files will be wrapped in a folder with your app extracted version.
The version (major.minor) is taken from files at project root.
- lerna.json
- pom.xml
- package.json
There are 4 methods of extraction
- npm : run an npm script
- yarn : same as npm but with yarn
- files : get the files from a list of path
- expression : get the files matching an expression, starting with a provided folder
Npm/Yarn
{
"extract": {
"method": "npm",
"script": "extract-i18n",
"target": "./i18n",
"transform": "flatten"
}
}
Configuration | Description |
---|
method | npm or yarn |
script | The npm script name |
target | The folder where the npm script will gather the translation files. This is used to create the zip file. |
transform | Optional. Transformation to apply to file hierarchy. For now only flatten is accepted, putting all file directly under the target language folder. |
Files
{
"extract": {
"method": "files",
"files": ["./src/i18n/translation.json", "./src/app/other.json"],
"target": "./i18n"
}
}
Configuration | Description |
---|
method | npm or yarn |
files | The list of files to extract. |
target | The folder where the script will gather the translation files. This is used to create the zip file. Note that the files folder hierarchy is preserved. |
Expression
{
"extract": {
"method": "expression",
"rootPath": "./src",
"expression": "message*.json",
"target": "./i18n"
}
}
Configuration | Description |
---|
method | expression |
rootPath | The folder to start the search.
Note that mvnModules is a special value, that will get the folders from pom.xml modules definition. |
expression | Expression describing the files name.
It accepts glob format, you can use * as wildcard. message*.json means every files that start with message and end with .json (ex: message-errors.json, message.json, ...), whereas message.json matches only the message.json files. |
target | The folder where the script will gather the translation files. This is used to create the zip file. Note that the files folder hierarchy is preserved. |
Upload/Download
You need to pass xtm information as environment variables
> XTM_API_URL=https://XXX \
XTM_CUSTOMER_ID=YYY \
XTM_TOKEN=ZZZ \
talend-i18n <upload|download>
Variable | Description |
---|
XTM_API_URL | The XTM api url |
XTM_CUSTOMER_ID | The XTM customer ID |
XTM_TOKEN | The XTM authentication token |
Upload
This step will upload previously created i18n zip to XTM.
{
"load": {
"project": "UI"
}
}
Configuration | Description |
---|
project | The XTM project name. |
Download
This step will download, unzip and transform files from XTM.
{
"load": {
"project": "UI"
}
}
Configuration | Description |
---|
project | The XTM project name. |
It will download only the files corresponding to the current version of your project (version extracted). If no version is detected, all versions will be downloaded.
Deploy
This step will push downloaded i18n files to github. Files will be generated to create a npm or maven module. For now, no module is deployed on npm/mvn repositories.
You need to pass github credentials as environment variables.
> GITHUB_LOGIN=XXX \
GITHUB_TOKEN=YYY \
talend-i18n deploy
Variable | Description |
---|
GITHUB_LOGIN | Github username that will be used to push to the locales repo |
GITHUB_TOKEN | Github token |
talend-i18n.json
configuration
{
"github": {
"url": "https://github.com/Talend/locales.git"
},
"module": {
"type": "mvn",
"private": true,
"repository": {
"id": "private-releases",
"url": "https://mydomain.com/nexus/content/repositories/MyPrivateSourceRelease"
}
}
}
Configuration | Type | Description |
---|
github.url | string | The https git url. |
module.type | string | The module type to deploy (npm |
module.private | boolean | If the module should be private. |
module.repository | object | This will be set in pom.xml for mvn modules. It should reflect the repository this module should be released. |
module.repository.id | string | The repository id. |
module.repository.url | string | The repository url. |
The i18n files will be pushed to a branch {XTM_project}/{version}
.
With this branch structure, the locales for your project can be downloaded from a defined url.
https://github.com/{github_org}/{repo_name}/archive/{XTM_project}/{version}.zip
In the example :
https://github.com/Talend/locales/archive/UI/1.10.zip