@ciortanmadalina/angular2-translations-synchroniser
v1.0.19
Published
Downloads
7
Readme
Angular 2 translations synchroniser
This project offers the following translation management functionalities for angular2 projects.
Install
npm install -g @ciortanmadalina/angular2-translations-synchroniser
Synchronise HTML translation placeholders used in given folder with json translations files
This command line tool can be used like:
synchroniseTranslations --scanFolder ./src --translationFolder ./src/i18n --preferredLanguage en --missingLabel ##
It performs the following 3 steps:
Parses all html files found in given scanFolder and extracts all translation placeholders. It exports these keys as a Map of custom type TranslationCollection with default values missingLabel + key value.
For instance if an html file uses {{'mykey' | translate}} the map will hold {'mykey': '##mykey'} (missingLabel + key)For all json files found in translationFolder, adds the above missing labels {'mykey': '##mykey'}
Parses all translations files from translation folder and generates more meaningful placeholders for the keys which were defined in one file and missing in others. For instance if we have 3 translation files and the key was added to only one of them ({'mykey': 'Value'}), the other files will be updated with ({'mykey': '##Value'}). The file which will provide the reference values will be the one corresonding to the input preferred language (en.json by default), but if it doesn't have a declared value the script will pick one from any other file.
Update translation files with new content as json/csv/xls
This functionality facilitates the global update of translated labels with content managed by business, which can be provided as json/CSV/xls.
The command line tool can be used like:
mergeTranslations --translationFolder ./src/i18n --updateFolder ./updateFolder
This script updates translation files found in given translationFolder with new lables from given updateFolder.
It takes all json files found in updateFolder and merges them with corresonding files in translationFolder, by name.
Thus, the en.json in updateFolder will overwrite en.json in translationFolder, etc.
If updateFolder contains CSV files, the first step is to convert them to json. For instance
key1,Value Key 1
key2,Value Key 2
Becomes :
{
'key1':'Value Key 1',
'key2':'Value Key 2'
}
Alternatively, updateFolder may contain xls files which will be parsed.
One single xls file may contain the labels for all languges, as the parser will aggregate all excel sheets named after an existing language (2 letters lowercase iso code).
For instance, an excel file may contain on sheet en the following values under a key - value header :
| key | value |
|---|---|
| key1 | Translated value for key 1 |
| key2 | Translated value for key 2 |
This will generate a json like :
{
"key1" : "Translated value for key 1",
"key2" : "Translated value for key 2"
}
These Json files with overwrite the values found in corresonding json translation files in translationFolder.
The code uses https://github.com/ciortanmadalina/angular2-translations-synchroniser.
Export Json files to Excel
This functionality exports all content of json files to one excel sheet with columns for each supported language. It can be called from the command line:
jsonToExcel --jsonInputFolder ./src/i18n --outputExcelFile ./input/labels.xlsx
Excel file will look like:
| key | en | fr | nl | |---|---| ---|---|---| | key1 | Key 1 in English | Key 1 in French | Key 1 in Nl | | key2 | Key 2 in English | Key 2 in French | Key 2 in Nl |
Update Json files from Excel
This functionality updates json translation files with content from the excel file.
It can be called from the command line:
excelToJson --inputExcelFile ./input/labels.xlsx --outputJsonFolder ./src/i18n
Excel file has the following format:
| key | en | fr | nl | |---|---| ---|---|---| | key1 | Key 1 in English | Key 1 in French | Key 1 in Nl | | key2 | Key 2 in English | Key 2 in French | Key 2 in Nl |