feat(lang) add helper script for manual translations

It updates the main language file for a given locale from the canonical one and
sets the empty string on the missing keys. No longer used keys are discarded.
This commit is contained in:
Saúl Ibarra Corretgé 2021-09-28 11:57:01 +02:00 committed by Saúl Ibarra Corretgé
parent 7b0dccdad1
commit 7546db53e4
4 changed files with 61 additions and 10 deletions

View File

@ -1,15 +1,25 @@
Jitsi Meet Translation
==========================
# Jitsi Meet Translation
Jitsi Meet uses [i18next](http://i18next.com) library for translation.
i18next uses separate json files for each language.
Translating Jitsi Meet
======================
## Translating Jitsi Meet
The translation of Jitsi Meet is handled editing manually the language files.
Development
===========
You can use the `update-translation.js` script as follows to help you with that:
```js
cd lang
node update-translation.js main-es.json
```
That will cause the `main-es.json` file to be updated with all the missing keys set as empty
strings. All that's missing is for you to fill in the blanks!
## Development
If you want to add new functionality for Jitsi Meet and you have texts that need to be translated you must add key and value in main.json file in English for each translatable text.
Than you can use the key to get the translated text for the current language.
@ -43,7 +53,3 @@ You can add translatable text in the HTML:
For the available values of ``options`` parameter for the above methods of translation module see [i18next documentation](http://i18next.com/pages/doc_features).
**Note:** It is useful to add attributes in the HTML for persistent HTML elements because when the language is changed the text will be automatically translated.

View File

@ -0,0 +1,38 @@
/* eslint-disable */
const fs = require('fs');
const process = require('process');
const traverse = require('traverse');
const mainLang = require('./main.json');
const [ targetLangFile ] = process.argv.slice(-1);
if (!targetLangFile) {
console.log('No target language file specified');
process.exit(1);
}
const targetLang = require(`./${targetLangFile}`);
const paths = traverse(mainLang).reduce(function(acc, item) {
if (this.isLeaf) {
acc.push(this.path);
}
return acc;
}, []);
const result = {};
for (const path of paths) {
if (traverse(targetLang).has(path)) {
traverse(result).set(path, traverse(targetLang).get(path));
} else {
//console.log(`${path.join('.')} is missing`);
traverse(result).set(path, '');
}
}
const data = JSON.stringify(result, undefined, 4);
fs.writeFileSync(`./${targetLangFile}`, data);

6
package-lock.json generated
View File

@ -17777,6 +17777,12 @@
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
"dev": true
},
"traverse": {
"version": "0.6.6",
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz",
"integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=",
"dev": true
},
"trim-right": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",

View File

@ -146,6 +146,7 @@
"sass": "1.26.8",
"string-replace-loader": "2.1.1",
"style-loader": "0.19.0",
"traverse": "0.6.6",
"unorm": "1.6.0",
"webpack": "4.43.0",
"webpack-bundle-analyzer": "3.4.1",