Przeglądaj źródła

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é 3 lat temu
rodzic
commit
7546db53e4
4 zmienionych plików z 61 dodań i 10 usunięć
  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 Wyświetl plik

@@ -1,15 +1,25 @@
1
-Jitsi Meet Translation
2
-==========================
1
+# Jitsi Meet Translation
2
+
3 3
 Jitsi Meet uses [i18next](http://i18next.com) library for translation.
4 4
 i18next uses separate json files for each language.
5 5
 
6 6
 
7
-Translating Jitsi Meet
8
-======================
7
+## Translating Jitsi Meet
8
+
9 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 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 24
 Than you can use the key to get the translated text for the current language.
15 25
 
@@ -43,7 +53,3 @@ You can add translatable text in the HTML:
43 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 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 Wyświetl plik

@@ -0,0 +1,38 @@
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 Wyświetl plik

@@ -17777,6 +17777,12 @@
17777 17777
       "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
17778 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 17786
     "trim-right": {
17781 17787
       "version": "1.0.1",
17782 17788
       "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",

+ 1
- 0
package.json Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz