Explorar el Código

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.
master
Saúl Ibarra Corretgé hace 3 años
padre
commit
7546db53e4
Se han modificado 4 ficheros con 61 adiciones y 10 borrados
  1. 16
    10
      lang/readme.md
  2. 38
    0
      lang/update-translation.js
  3. 6
    0
      package-lock.json
  4. 1
    0
      package.json

+ 16
- 10
lang/readme.md Ver fichero

1
-Jitsi Meet Translation
2
-==========================
1
+# Jitsi Meet Translation
2
+
3
 Jitsi Meet uses [i18next](http://i18next.com) library for translation.
3
 Jitsi Meet uses [i18next](http://i18next.com) library for translation.
4
 i18next uses separate json files for each language.
4
 i18next uses separate json files for each language.
5
 
5
 
6
 
6
 
7
-Translating Jitsi Meet
8
-======================
7
+## Translating Jitsi Meet
8
+
9
 The translation of Jitsi Meet is handled editing manually the language files.
9
 The translation of Jitsi Meet is handled editing manually the language files.
10
 
10
 
11
-Development
12
-===========
11
+You can use the `update-translation.js` script as follows to help you with that:
12
+
13
+```js
14
+cd lang
15
+node update-translation.js main-es.json
16
+```
17
+
18
+That will cause the `main-es.json` file to be updated with all the missing keys set as empty
19
+strings. All that's missing is for you to fill in the blanks!
20
+
21
+## Development
22
+
13
 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.
23
 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.
14
 Than you can use the key to get the translated text for the current language.
24
 Than you can use the key to get the translated text for the current language.
15
 
25
 
43
 For the available values of ``options`` parameter for the above methods of translation module see [i18next documentation](http://i18next.com/pages/doc_features).
53
 For the available values of ``options`` parameter for the above methods of translation module see [i18next documentation](http://i18next.com/pages/doc_features).
44
 
54
 
45
 **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.
55
 **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.
46
-
47
-
48
-
49
-

+ 38
- 0
lang/update-translation.js Ver fichero

1
+/* eslint-disable */
2
+
3
+const fs = require('fs');
4
+const process = require('process');
5
+const traverse = require('traverse');
6
+const mainLang = require('./main.json');
7
+
8
+const [ targetLangFile ] = process.argv.slice(-1);
9
+
10
+if (!targetLangFile) {
11
+    console.log('No target language file specified');
12
+    process.exit(1);
13
+}
14
+
15
+const targetLang = require(`./${targetLangFile}`);
16
+
17
+const paths = traverse(mainLang).reduce(function(acc, item) {
18
+    if (this.isLeaf) {
19
+        acc.push(this.path);
20
+    }
21
+
22
+    return acc;
23
+}, []);
24
+
25
+const result = {};
26
+
27
+for (const path of paths) {
28
+    if (traverse(targetLang).has(path)) {
29
+        traverse(result).set(path, traverse(targetLang).get(path));
30
+    } else {
31
+        //console.log(`${path.join('.')} is missing`);
32
+        traverse(result).set(path, '');
33
+    }
34
+}
35
+
36
+const data = JSON.stringify(result, undefined, 4);
37
+
38
+fs.writeFileSync(`./${targetLangFile}`, data);

+ 6
- 0
package-lock.json Ver fichero

17777
       "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
17777
       "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
17778
       "dev": true
17778
       "dev": true
17779
     },
17779
     },
17780
+    "traverse": {
17781
+      "version": "0.6.6",
17782
+      "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz",
17783
+      "integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=",
17784
+      "dev": true
17785
+    },
17780
     "trim-right": {
17786
     "trim-right": {
17781
       "version": "1.0.1",
17787
       "version": "1.0.1",
17782
       "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
17788
       "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",

+ 1
- 0
package.json Ver fichero

146
     "sass": "1.26.8",
146
     "sass": "1.26.8",
147
     "string-replace-loader": "2.1.1",
147
     "string-replace-loader": "2.1.1",
148
     "style-loader": "0.19.0",
148
     "style-loader": "0.19.0",
149
+    "traverse": "0.6.6",
149
     "unorm": "1.6.0",
150
     "unorm": "1.6.0",
150
     "webpack": "4.43.0",
151
     "webpack": "4.43.0",
151
     "webpack-bundle-analyzer": "3.4.1",
152
     "webpack-bundle-analyzer": "3.4.1",

Loading…
Cancelar
Guardar