@deriv-com/translations 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,9 +4,29 @@
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const crc32 = require("crc-32").str;
|
|
6
6
|
const fs = require("fs");
|
|
7
|
-
const program = require("commander");
|
|
8
7
|
const glob = require("glob");
|
|
9
|
-
const DOMParser = require("@xmldom/xmldom")
|
|
8
|
+
const { DOMParser } = require("@xmldom/xmldom");
|
|
9
|
+
const { Command } = require("commander");
|
|
10
|
+
|
|
11
|
+
const program = new Command();
|
|
12
|
+
|
|
13
|
+
let SOURCE_DIRECTORY = 'src'
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.version("0.1.0")
|
|
17
|
+
.description("Build translation source.")
|
|
18
|
+
.option("-v, --verbose", "Displays the list of paths to be compiled and shows all the message and it's hash.")
|
|
19
|
+
.argument('<srcDir>', "source directory path i.e './src' which is by default './src'")
|
|
20
|
+
.description('source directory of the app from where the script will start finding for strings.')
|
|
21
|
+
.action((str) => {
|
|
22
|
+
SOURCE_DIRECTORY = str.replace(/^\.*\/+|\/+$/g, '');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
program.parse(process.argv);
|
|
27
|
+
|
|
28
|
+
const options = program.opts();
|
|
29
|
+
|
|
10
30
|
|
|
11
31
|
const getRegexPattern = () =>
|
|
12
32
|
/(i18n_default_text={?|localize\()\s*(['"])\s*(.*?)(?<!\\)\2\s*/gs;
|
|
@@ -42,27 +62,14 @@ const getStringsFromXmlFile = (input) => {
|
|
|
42
62
|
};
|
|
43
63
|
|
|
44
64
|
const getTranslatableFiles = () => {
|
|
45
|
-
const packages_with_translations = [
|
|
46
|
-
"account",
|
|
47
|
-
"appstore",
|
|
48
|
-
"cashier",
|
|
49
|
-
"bot-web-ui",
|
|
50
|
-
"core",
|
|
51
|
-
"cfd",
|
|
52
|
-
"trader",
|
|
53
|
-
"bot-skeleton",
|
|
54
|
-
"reports",
|
|
55
|
-
"shared",
|
|
56
|
-
];
|
|
57
65
|
const globs = ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/xml/*.xml"];
|
|
58
66
|
const file_paths = [];
|
|
59
67
|
|
|
60
|
-
for (let i = 0; i < packages_with_translations.length; i++) {
|
|
61
68
|
for (let j = 0; j < globs.length; j++) {
|
|
62
69
|
let files_found = glob.sync(
|
|
63
|
-
|
|
70
|
+
`./${SOURCE_DIRECTORY}/${globs[j]}`,
|
|
64
71
|
{
|
|
65
|
-
root: path.resolve(
|
|
72
|
+
root: path.resolve("."),
|
|
66
73
|
}
|
|
67
74
|
);
|
|
68
75
|
files_found = files_found.filter(
|
|
@@ -70,17 +77,10 @@ const getTranslatableFiles = () => {
|
|
|
70
77
|
);
|
|
71
78
|
file_paths.push(...files_found);
|
|
72
79
|
}
|
|
73
|
-
}
|
|
74
80
|
|
|
75
81
|
return file_paths;
|
|
76
82
|
};
|
|
77
83
|
|
|
78
|
-
program
|
|
79
|
-
.version("0.1.0")
|
|
80
|
-
.description("Build translation source.")
|
|
81
|
-
.option("-v, --verbose", "Displays the list of paths to be compiled")
|
|
82
|
-
.parse(process.argv);
|
|
83
|
-
|
|
84
84
|
/** *********************************************
|
|
85
85
|
* Common
|
|
86
86
|
*/
|
|
@@ -99,6 +99,11 @@ const getKeyHash = (string) => crc32(string);
|
|
|
99
99
|
for (let i = 0; i < file_paths.length; i++) {
|
|
100
100
|
const file_path = file_paths[i];
|
|
101
101
|
|
|
102
|
+
if(options.verbose) {
|
|
103
|
+
console.log(file_path);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
102
107
|
try {
|
|
103
108
|
const file = fs.readFileSync(file_path, "utf8");
|
|
104
109
|
messages.push(
|
|
@@ -113,17 +118,32 @@ const getKeyHash = (string) => crc32(string);
|
|
|
113
118
|
|
|
114
119
|
// Hash the messages and set the key-value pair for json
|
|
115
120
|
for (let i = 0; i < messages.length; i++) {
|
|
116
|
-
|
|
121
|
+
const keyHash = getKeyHash(messages[i])
|
|
122
|
+
messages_json[keyHash] = messages[i];
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if(options.verbose) {
|
|
126
|
+
console.log('** key_hash : ', keyHash, ' ** message : ',messages[i]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// check if the directory of crowdin exist, if not create the directory of the crowdin first in the root
|
|
131
|
+
const crowdinDir = path.resolve("./crowdin");
|
|
132
|
+
|
|
133
|
+
if (!fs.existsSync(crowdinDir)) {
|
|
134
|
+
fs.mkdirSync(crowdinDir)
|
|
117
135
|
}
|
|
118
136
|
|
|
119
137
|
// Add to messages.json
|
|
120
138
|
fs.writeFileSync(
|
|
121
|
-
path.resolve(
|
|
139
|
+
path.resolve("./crowdin/messages.json"),
|
|
122
140
|
JSON.stringify(messages_json),
|
|
123
141
|
"utf8",
|
|
124
142
|
(err) => console.log(err)
|
|
125
143
|
);
|
|
144
|
+
|
|
145
|
+
console.log("********* Translation strings compiled successfully *********")
|
|
126
146
|
} catch (e) {
|
|
127
|
-
|
|
147
|
+
program.error(e);
|
|
128
148
|
}
|
|
129
149
|
})();
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"bin": {
|
|
10
|
-
"extract-translations": "./dist/extract-translations.cjs"
|
|
10
|
+
"deriv-extract-translations": "./dist/deriv-extract-translations.cjs"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"private": false,
|
|
19
|
-
"version": "1.
|
|
19
|
+
"version": "1.1.1",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "vite",
|
|
22
|
-
"build": "tsc && vite build && cp ./src/scripts/extract-translations.cjs ./dist/extract-translations.cjs",
|
|
22
|
+
"build": "tsc && vite build && cp ./src/scripts/deriv-extract-translations.cjs ./dist/deriv-extract-translations.cjs",
|
|
23
23
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
24
24
|
"test": "vitest ./src/__tests__/*.test.tsx",
|
|
25
25
|
"prepublish": "npm run test && npm run build"
|