@deriv-com/translations 0.0.0-development → 1.0.0

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.
package/README.md CHANGED
@@ -42,7 +42,7 @@ npm install @deriv-com/translations
42
42
  - pass default language to the `TranslationProvider` component.
43
43
 
44
44
  ```jsx
45
- import { initializeI18n, TranslationProvider } from '@deriv/translations';
45
+ import { initializeI18n, TranslationProvider } from '@deriv-com/translations';
46
46
  ...
47
47
  const i18nInstance = initializeI18n({ cdnUrl: 'https://cdn.example.com' })
48
48
 
@@ -101,7 +101,7 @@ The useTranslations hook is a custom hook that adds some more returned values on
101
101
  Example usage:
102
102
 
103
103
  ```javascript
104
- import { useTranslations } from "@username/package";
104
+ import { useTranslations } from "@deriv-com/package";
105
105
 
106
106
  const MyComponent = () => {
107
107
  const { localize, switchLanguage, currentLang } = useTranslations();
@@ -128,7 +128,7 @@ The action takes following inputs:
128
128
  - `R2_SECRET_ACCESS_KEY`: R2 secret access key from the Cloudflare R2 dashboard
129
129
  - `R2_BUCKET_NAME`: R2 bucket name from the Cloudflare R2 dashboard
130
130
 
131
- Refer to the action file [here](https://github.com/deriv-com/shared-actions/blob/master/.github/actions/sync_crowdin_translation_with_cloudflare/action.yml)
131
+ Refer to the action file [here](https://github.com/deriv-com/translations/blob/main/.github/actions/extract_and_sync_translations/action.yml)
132
132
 
133
133
  ## Contributing
134
134
 
package/package.json CHANGED
@@ -6,6 +6,9 @@
6
6
  ],
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "extract-translations": "./scripts/extract-translations.js"
11
+ },
9
12
  "exports": {
10
13
  ".": {
11
14
  "import": "./dist/index.js",
@@ -13,13 +16,13 @@
13
16
  }
14
17
  },
15
18
  "private": false,
16
- "version": "0.0.0-development",
19
+ "version": "1.0.0",
17
20
  "scripts": {
18
21
  "dev": "vite",
19
22
  "build": "tsc && vite build",
20
23
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
21
24
  "test": "vitest ./src/__tests__/*.test.tsx",
22
- "prepublishOnly": "npm run test && npm run build"
25
+ "prepublish": "npm run test && npm run build"
23
26
  },
24
27
  "peerDependencies": {
25
28
  "react": "^17.x || ^18.x",
@@ -39,6 +42,8 @@
39
42
  "@typescript-eslint/eslint-plugin": "^6.14.0",
40
43
  "@typescript-eslint/parser": "^6.14.0",
41
44
  "@vitejs/plugin-react": "^4.2.1",
45
+ "@xmldom/xmldom": "^0.8.10",
46
+ "commander": "^12.0.0",
42
47
  "crc-32": "^1.2.2",
43
48
  "eslint": "^8.55.0",
44
49
  "eslint-plugin-react-hooks": "^4.6.0",
@@ -55,449 +60,7 @@
55
60
  "vite-plugin-dts": "^3.7.3",
56
61
  "vitest": "^1.3.1"
57
62
  },
58
- "description": "This is a localization library that uses `i18next`, `react-i18next`, and a custom OTA SDK for translations.",
59
- "dependencies": {
60
- "JSONStream": "^1.3.5",
61
- "acorn": "^8.11.3",
62
- "acorn-jsx": "^5.3.2",
63
- "acorn-walk": "^8.3.2",
64
- "agent-base": "^7.1.0",
65
- "aggregate-error": "^5.0.0",
66
- "ajv": "^6.12.6",
67
- "ansi-escapes": "^6.2.1",
68
- "ansi-regex": "^5.0.1",
69
- "ansi-styles": "^3.2.1",
70
- "any-promise": "^1.3.0",
71
- "argparse": "^2.0.1",
72
- "argv-formatter": "^1.0.0",
73
- "aria-query": "^5.1.3",
74
- "array-buffer-byte-length": "^1.0.1",
75
- "array-ify": "^1.0.0",
76
- "array-union": "^2.1.0",
77
- "assertion-error": "^1.1.0",
78
- "asynckit": "^0.4.0",
79
- "available-typed-arrays": "^1.0.7",
80
- "balanced-match": "^1.0.2",
81
- "before-after-hook": "^3.0.2",
82
- "bottleneck": "^2.19.5",
83
- "brace-expansion": "^2.0.1",
84
- "braces": "^3.0.2",
85
- "browserslist": "^4.22.2",
86
- "cac": "^6.7.14",
87
- "call-bind": "^1.0.7",
88
- "callsites": "^3.1.0",
89
- "caniuse-lite": "^1.0.30001578",
90
- "chai": "^4.4.1",
91
- "chalk": "^2.4.2",
92
- "char-regex": "^1.0.2",
93
- "check-error": "^1.0.3",
94
- "clean-stack": "^5.2.0",
95
- "cli-highlight": "^2.1.11",
96
- "cli-table3": "^0.6.4",
97
- "cliui": "^8.0.1",
98
- "color-convert": "^1.9.3",
99
- "color-name": "^1.1.3",
100
- "colors": "^1.2.5",
101
- "combined-stream": "^1.0.8",
102
- "commander": "^9.5.0",
103
- "compare-func": "^2.0.0",
104
- "computeds": "^0.0.1",
105
- "concat-map": "^0.0.1",
106
- "config-chain": "^1.1.13",
107
- "conventional-changelog-angular": "^7.0.0",
108
- "conventional-changelog-writer": "^7.0.1",
109
- "conventional-commits-filter": "^4.0.0",
110
- "conventional-commits-parser": "^5.0.0",
111
- "convert-source-map": "^2.0.0",
112
- "core-util-is": "^1.0.3",
113
- "cosmiconfig": "^9.0.0",
114
- "cross-spawn": "^7.0.3",
115
- "crypto-random-string": "^4.0.0",
116
- "css.escape": "^1.5.1",
117
- "cssstyle": "^4.0.1",
118
- "csstype": "^3.1.3",
119
- "data-urls": "^5.0.0",
120
- "de-indent": "^1.0.2",
121
- "debug": "^4.3.4",
122
- "decimal.js": "^10.4.3",
123
- "deep-eql": "^4.1.3",
124
- "deep-equal": "^2.2.3",
125
- "deep-extend": "^0.6.0",
126
- "deep-is": "^0.1.4",
127
- "define-data-property": "^1.1.4",
128
- "define-properties": "^1.2.1",
129
- "delayed-stream": "^1.0.0",
130
- "diff-sequences": "^29.6.3",
131
- "dir-glob": "^3.0.1",
132
- "doctrine": "^3.0.0",
133
- "dom-accessibility-api": "^0.5.16",
134
- "dot-prop": "^5.3.0",
135
- "duplexer2": "^0.1.4",
136
- "eastasianwidth": "^0.2.0",
137
- "electron-to-chromium": "^1.4.633",
138
- "emoji-regex": "^9.2.2",
139
- "emojilib": "^2.4.0",
140
- "entities": "^4.5.0",
141
- "env-ci": "^11.0.0",
142
- "env-paths": "^2.2.1",
143
- "error-ex": "^1.3.2",
144
- "es-define-property": "^1.0.0",
145
- "es-errors": "^1.3.0",
146
- "es-get-iterator": "^1.1.3",
147
- "esbuild": "^0.19.11",
148
- "escalade": "^3.1.1",
149
- "escape-string-regexp": "^1.0.5",
150
- "eslint-scope": "^7.2.2",
151
- "eslint-visitor-keys": "^3.4.3",
152
- "espree": "^9.6.1",
153
- "esquery": "^1.5.0",
154
- "esrecurse": "^4.3.0",
155
- "estraverse": "^5.3.0",
156
- "estree-walker": "^3.0.3",
157
- "esutils": "^2.0.3",
158
- "execa": "^8.0.1",
159
- "fast-deep-equal": "^3.1.3",
160
- "fast-glob": "^3.3.2",
161
- "fast-json-stable-stringify": "^2.1.0",
162
- "fast-levenshtein": "^2.0.6",
163
- "fastq": "^1.16.0",
164
- "figures": "^6.1.0",
165
- "file-entry-cache": "^6.0.1",
166
- "fill-range": "^7.0.1",
167
- "find-up": "^5.0.0",
168
- "find-up-simple": "^1.0.0",
169
- "find-versions": "^5.1.0",
170
- "flat-cache": "^3.2.0",
171
- "flatted": "^3.2.9",
172
- "for-each": "^0.3.3",
173
- "foreground-child": "^3.1.1",
174
- "form-data": "^4.0.0",
175
- "from2": "^2.3.0",
176
- "fs-extra": "^7.0.1",
177
- "fs.realpath": "^1.0.0",
178
- "fsevents": "^2.3.3",
179
- "function-bind": "^1.1.2",
180
- "functions-have-names": "^1.2.3",
181
- "gensync": "^1.0.0-beta.2",
182
- "get-caller-file": "^2.0.5",
183
- "get-func-name": "^2.0.2",
184
- "get-intrinsic": "^1.2.4",
185
- "get-stream": "^8.0.1",
186
- "git-log-parser": "^1.2.0",
187
- "glob-parent": "^6.0.2",
188
- "globals": "^11.12.0",
189
- "globby": "^11.1.0",
190
- "gopd": "^1.0.1",
191
- "graceful-fs": "^4.2.11",
192
- "graphemer": "^1.4.0",
193
- "handlebars": "^4.7.8",
194
- "has-bigints": "^1.0.2",
195
- "has-flag": "^3.0.0",
196
- "has-property-descriptors": "^1.0.2",
197
- "has-proto": "^1.0.3",
198
- "has-symbols": "^1.0.3",
199
- "has-tostringtag": "^1.0.2",
200
- "hasown": "^2.0.1",
201
- "he": "^1.2.0",
202
- "highlight.js": "^10.7.3",
203
- "hook-std": "^3.0.0",
204
- "hosted-git-info": "^7.0.1",
205
- "html-encoding-sniffer": "^4.0.0",
206
- "html-parse-stringify": "^3.0.1",
207
- "http-proxy-agent": "^7.0.2",
208
- "https-proxy-agent": "^7.0.4",
209
- "human-signals": "^5.0.0",
210
- "iconv-lite": "^0.6.3",
211
- "ignore": "^5.3.0",
212
- "import-fresh": "^3.3.0",
213
- "import-from-esm": "^1.3.3",
214
- "import-lazy": "^4.0.0",
215
- "import-meta-resolve": "^4.0.0",
216
- "imurmurhash": "^0.1.4",
217
- "indent-string": "^4.0.0",
218
- "index-to-position": "^0.1.2",
219
- "inflight": "^1.0.6",
220
- "inherits": "^2.0.4",
221
- "ini": "^1.3.8",
222
- "internal-slot": "^1.0.7",
223
- "into-stream": "^7.0.0",
224
- "is-arguments": "^1.1.1",
225
- "is-array-buffer": "^3.0.4",
226
- "is-arrayish": "^0.2.1",
227
- "is-bigint": "^1.0.4",
228
- "is-boolean-object": "^1.1.2",
229
- "is-callable": "^1.2.7",
230
- "is-core-module": "^2.13.1",
231
- "is-date-object": "^1.0.5",
232
- "is-extglob": "^2.1.1",
233
- "is-fullwidth-code-point": "^3.0.0",
234
- "is-glob": "^4.0.3",
235
- "is-map": "^2.0.2",
236
- "is-number": "^7.0.0",
237
- "is-number-object": "^1.0.7",
238
- "is-obj": "^2.0.0",
239
- "is-path-inside": "^3.0.3",
240
- "is-potential-custom-element-name": "^1.0.1",
241
- "is-regex": "^1.1.4",
242
- "is-set": "^2.0.2",
243
- "is-shared-array-buffer": "^1.0.2",
244
- "is-stream": "^3.0.0",
245
- "is-string": "^1.0.7",
246
- "is-symbol": "^1.0.4",
247
- "is-text-path": "^2.0.0",
248
- "is-unicode-supported": "^2.0.0",
249
- "is-weakmap": "^2.0.1",
250
- "is-weakset": "^2.0.2",
251
- "isarray": "^2.0.5",
252
- "isexe": "^2.0.0",
253
- "issue-parser": "^7.0.0",
254
- "jackspeak": "^2.3.6",
255
- "java-properties": "^1.0.2",
256
- "jju": "^1.4.0",
257
- "js-tokens": "^4.0.0",
258
- "js-yaml": "^4.1.0",
259
- "jsesc": "^2.5.2",
260
- "json-buffer": "^3.0.1",
261
- "json-parse-better-errors": "^1.0.2",
262
- "json-parse-even-better-errors": "^2.3.1",
263
- "json-schema-traverse": "^0.4.1",
264
- "json-stable-stringify-without-jsonify": "^1.0.1",
265
- "json-stringify-safe": "^5.0.1",
266
- "json5": "^2.2.3",
267
- "jsonc-parser": "^3.2.1",
268
- "jsonfile": "^4.0.0",
269
- "jsonparse": "^1.3.1",
270
- "keyv": "^4.5.4",
271
- "kolorist": "^1.8.0",
272
- "levn": "^0.4.1",
273
- "lines-and-columns": "^1.2.4",
274
- "load-json-file": "^4.0.0",
275
- "local-pkg": "^0.5.0",
276
- "locate-path": "^6.0.0",
277
- "lodash": "^4.17.21",
278
- "lodash-es": "^4.17.21",
279
- "lodash.capitalize": "^4.2.1",
280
- "lodash.escaperegexp": "^4.1.2",
281
- "lodash.get": "^4.4.2",
282
- "lodash.isequal": "^4.5.0",
283
- "lodash.isplainobject": "^4.0.6",
284
- "lodash.isstring": "^4.0.1",
285
- "lodash.merge": "^4.6.2",
286
- "lodash.uniqby": "^4.7.0",
287
- "loose-envify": "^1.4.0",
288
- "loupe": "^2.3.7",
289
- "lru-cache": "^5.1.1",
290
- "lz-string": "^1.5.0",
291
- "magic-string": "^0.30.7",
292
- "marked": "^12.0.1",
293
- "marked-terminal": "^7.0.0",
294
- "meow": "^12.1.1",
295
- "merge-stream": "^2.0.0",
296
- "merge2": "^1.4.1",
297
- "micromatch": "^4.0.5",
298
- "mime": "^4.0.1",
299
- "mime-db": "^1.52.0",
300
- "mime-types": "^2.1.35",
301
- "mimic-fn": "^4.0.0",
302
- "min-indent": "^1.0.1",
303
- "minimatch": "^9.0.3",
304
- "minimist": "^1.2.8",
305
- "minipass": "^7.0.4",
306
- "mlly": "^1.5.0",
307
- "ms": "^2.1.2",
308
- "muggle-string": "^0.3.1",
309
- "mz": "^2.7.0",
310
- "nanoid": "^3.3.7",
311
- "natural-compare": "^1.4.0",
312
- "neo-async": "^2.6.2",
313
- "nerf-dart": "^1.0.0",
314
- "node-emoji": "^2.1.3",
315
- "node-releases": "^2.0.14",
316
- "normalize-package-data": "^6.0.0",
317
- "normalize-url": "^8.0.1",
318
- "npm": "^10.5.0",
319
- "npm-run-path": "^5.2.0",
320
- "nwsapi": "^2.2.7",
321
- "object-assign": "^4.1.1",
322
- "object-inspect": "^1.13.1",
323
- "object-is": "^1.1.5",
324
- "object-keys": "^1.1.1",
325
- "object.assign": "^4.1.5",
326
- "once": "^1.4.0",
327
- "onetime": "^6.0.0",
328
- "optionator": "^0.9.3",
329
- "p-each-series": "^3.0.0",
330
- "p-filter": "^4.1.0",
331
- "p-is-promise": "^3.0.0",
332
- "p-limit": "^3.1.0",
333
- "p-locate": "^5.0.0",
334
- "p-map": "^7.0.2",
335
- "p-reduce": "^3.0.0",
336
- "p-try": "^1.0.0",
337
- "parent-module": "^1.0.1",
338
- "parse-json": "^5.2.0",
339
- "parse5": "^7.1.2",
340
- "parse5-htmlparser2-tree-adapter": "^6.0.1",
341
- "path-browserify": "^1.0.1",
342
- "path-exists": "^4.0.0",
343
- "path-is-absolute": "^1.0.1",
344
- "path-key": "^3.1.1",
345
- "path-parse": "^1.0.7",
346
- "path-scurry": "^1.10.1",
347
- "path-type": "^4.0.0",
348
- "pathe": "^1.1.2",
349
- "pathval": "^1.1.1",
350
- "picocolors": "^1.0.0",
351
- "picomatch": "^2.3.1",
352
- "pify": "^3.0.0",
353
- "pkg-conf": "^2.1.0",
354
- "pkg-types": "^1.0.3",
355
- "possible-typed-array-names": "^1.0.0",
356
- "postcss": "^8.4.33",
357
- "prelude-ls": "^1.2.1",
358
- "pretty-format": "^29.7.0",
359
- "process-nextick-args": "^2.0.1",
360
- "proto-list": "^1.2.4",
361
- "psl": "^1.9.0",
362
- "punycode": "^2.3.1",
363
- "querystringify": "^2.2.0",
364
- "queue-microtask": "^1.2.3",
365
- "rc": "^1.2.8",
366
- "react-is": "^18.2.0",
367
- "react-refresh": "^0.14.0",
368
- "read-pkg": "^9.0.1",
369
- "read-pkg-up": "^11.0.0",
370
- "readable-stream": "^2.3.8",
371
- "redent": "^3.0.0",
372
- "regenerator-runtime": "^0.14.1",
373
- "regexp.prototype.flags": "^1.5.2",
374
- "registry-auth-token": "^5.0.2",
375
- "require-directory": "^2.1.1",
376
- "requires-port": "^1.0.0",
377
- "resolve": "^1.22.8",
378
- "resolve-from": "^4.0.0",
379
- "reusify": "^1.0.4",
380
- "rimraf": "^3.0.2",
381
- "rollup": "^4.9.5",
382
- "rrweb-cssom": "^0.6.0",
383
- "run-parallel": "^1.2.0",
384
- "safe-buffer": "^5.1.2",
385
- "safer-buffer": "^2.1.2",
386
- "saxes": "^6.0.0",
387
- "scheduler": "^0.23.0",
388
- "semver": "^7.5.4",
389
- "semver-diff": "^4.0.0",
390
- "semver-regex": "^4.0.5",
391
- "set-function-length": "^1.2.1",
392
- "set-function-name": "^2.0.2",
393
- "shebang-command": "^2.0.0",
394
- "shebang-regex": "^3.0.0",
395
- "side-channel": "^1.0.5",
396
- "siginfo": "^2.0.0",
397
- "signal-exit": "^4.1.0",
398
- "signale": "^1.4.0",
399
- "skin-tone": "^2.0.0",
400
- "slash": "^3.0.0",
401
- "source-map": "^0.6.1",
402
- "source-map-js": "^1.0.2",
403
- "spawn-error-forwarder": "^1.0.0",
404
- "spdx-correct": "^3.2.0",
405
- "spdx-exceptions": "^2.5.0",
406
- "spdx-expression-parse": "^3.0.1",
407
- "spdx-license-ids": "^3.0.17",
408
- "split2": "^4.2.0",
409
- "sprintf-js": "^1.0.3",
410
- "stackback": "^0.0.2",
411
- "std-env": "^3.7.0",
412
- "stop-iteration-iterator": "^1.0.0",
413
- "stream-combiner2": "^1.1.1",
414
- "string-argv": "^0.3.2",
415
- "string-width": "^5.1.2",
416
- "string-width-cjs": "^4.2.3",
417
- "string_decoder": "^1.1.1",
418
- "strip-ansi": "^6.0.1",
419
- "strip-ansi-cjs": "^6.0.1",
420
- "strip-bom": "^3.0.0",
421
- "strip-final-newline": "^3.0.0",
422
- "strip-indent": "^3.0.0",
423
- "strip-json-comments": "^3.1.1",
424
- "strip-literal": "^2.0.0",
425
- "supports-color": "^5.5.0",
426
- "supports-hyperlinks": "^3.0.0",
427
- "supports-preserve-symlinks-flag": "^1.0.0",
428
- "symbol-tree": "^3.2.4",
429
- "temp-dir": "^3.0.0",
430
- "tempy": "^3.1.0",
431
- "text-extensions": "^2.4.0",
432
- "text-table": "^0.2.0",
433
- "thenify": "^3.3.1",
434
- "thenify-all": "^1.6.0",
435
- "through": "^2.3.8",
436
- "through2": "^2.0.5",
437
- "tinybench": "^2.6.0",
438
- "tinypool": "^0.8.2",
439
- "tinyspy": "^2.2.1",
440
- "to-fast-properties": "^2.0.0",
441
- "to-regex-range": "^5.0.1",
442
- "tough-cookie": "^4.1.3",
443
- "tr46": "^5.0.0",
444
- "traverse": "^0.6.8",
445
- "ts-api-utils": "^1.0.3",
446
- "type-check": "^0.4.0",
447
- "type-detect": "^4.0.8",
448
- "type-fest": "^0.20.2",
449
- "ufo": "^1.4.0",
450
- "uglify-js": "^3.17.4",
451
- "undici-types": "^5.26.5",
452
- "unicode-emoji-modifier-base": "^1.0.0",
453
- "unicorn-magic": "^0.1.0",
454
- "unique-string": "^3.0.0",
455
- "universal-user-agent": "^7.0.2",
456
- "universalify": "^0.2.0",
457
- "update-browserslist-db": "^1.0.13",
458
- "uri-js": "^4.4.1",
459
- "url-join": "^5.0.0",
460
- "url-parse": "^1.5.10",
461
- "util-deprecate": "^1.0.2",
462
- "validate-npm-package-license": "^3.0.4",
463
- "validator": "^13.11.0",
464
- "vite-node": "^1.3.1",
465
- "void-elements": "^3.1.0",
466
- "vue-template-compiler": "^2.7.16",
467
- "vue-tsc": "^1.8.27",
468
- "w3c-xmlserializer": "^5.0.0",
469
- "webidl-conversions": "^7.0.0",
470
- "whatwg-encoding": "^3.1.1",
471
- "whatwg-mimetype": "^4.0.0",
472
- "whatwg-url": "^14.0.0",
473
- "which": "^2.0.2",
474
- "which-boxed-primitive": "^1.0.2",
475
- "which-collection": "^1.0.1",
476
- "which-typed-array": "^1.1.14",
477
- "why-is-node-running": "^2.2.2",
478
- "wordwrap": "^1.0.0",
479
- "wrap-ansi": "^8.1.0",
480
- "wrap-ansi-cjs": "^7.0.0",
481
- "wrappy": "^1.0.2",
482
- "ws": "^8.16.0",
483
- "xml-name-validator": "^5.0.0",
484
- "xmlchars": "^2.2.0",
485
- "xtend": "^4.0.2",
486
- "y18n": "^5.0.8",
487
- "yallist": "^3.1.1",
488
- "yargs": "^17.7.2",
489
- "yargs-parser": "^21.1.1",
490
- "yocto-queue": "^0.1.0",
491
- "z-schema": "^5.0.5"
492
- },
493
- "repository": {
494
- "type": "git",
495
- "url": "git+https://github.com/deriv-com/translations.git"
496
- },
497
- "author": "",
498
- "license": "ISC",
499
- "bugs": {
500
- "url": "https://github.com/deriv-com/translations/issues"
501
- },
502
- "homepage": "https://github.com/deriv-com/translations#readme"
63
+ "optionalDependencies": {
64
+ "@rollup/rollup-linux-x64-gnu": "^4.17.1"
65
+ }
503
66
  }
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint-disable */
4
+ const path = require("path");
5
+ const program = require("commander");
6
+ const crc32 = require("crc-32").str;
7
+ const fs = require("fs");
8
+ const glob = require("glob");
9
+ const DOMParser = require("@xmldom/xmldom").DOMParser;
10
+
11
+ const getRegexPattern = () =>
12
+ /(i18n_default_text={?|localize\()\s*(['"])\s*(.*?)(?<!\\)\2\s*/gs;
13
+
14
+ const getStringsFromInput = (input, i18n_marker = getRegexPattern()) => {
15
+ const messages = [];
16
+ let result = i18n_marker.exec(input);
17
+
18
+ while (result !== null) {
19
+ const extracted = result[3];
20
+ // Replace escape characters.
21
+ messages.push(extracted.replace(/\\/g, ""));
22
+ result = i18n_marker.exec(input);
23
+ }
24
+
25
+ return messages;
26
+ };
27
+
28
+ const getStringsFromXmlFile = (input) => {
29
+ const messages = [];
30
+ const parsed_xml = new DOMParser().parseFromString(input, "application/xml");
31
+ const el_categories = parsed_xml.getElementsByTagName("category");
32
+
33
+ Array.from(el_categories).forEach((el_category) => {
34
+ const name = el_category.getAttribute("name");
35
+ const description = el_category.getAttribute("description");
36
+
37
+ if (name) messages.push(name);
38
+ if (description) messages.push(description);
39
+ });
40
+
41
+ return messages;
42
+ };
43
+
44
+ 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
+ const globs = ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/xml/*.xml"];
58
+ const file_paths = [];
59
+
60
+ for (let i = 0; i < packages_with_translations.length; i++) {
61
+ for (let j = 0; j < globs.length; j++) {
62
+ let files_found = glob.sync(
63
+ `/${packages_with_translations[i]}/src/${globs[j]}`,
64
+ {
65
+ root: path.resolve(__dirname, "../.."), // deriv-app/packages/
66
+ }
67
+ );
68
+ files_found = files_found.filter(
69
+ (file_path) => file_path.indexOf("__tests__") === -1
70
+ );
71
+ file_paths.push(...files_found);
72
+ }
73
+ }
74
+
75
+ return file_paths;
76
+ };
77
+
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
+ /** *********************************************
85
+ * Common
86
+ */
87
+ const getKeyHash = (string) => crc32(string);
88
+
89
+ /** **********************************************
90
+ * Compile
91
+ */
92
+ (async () => {
93
+ try {
94
+ const file_paths = getTranslatableFiles();
95
+ const messages = [];
96
+ const messages_json = {};
97
+
98
+ // Iterate over files and extract all strings from the i18n marker
99
+ for (let i = 0; i < file_paths.length; i++) {
100
+ const file_path = file_paths[i];
101
+
102
+ try {
103
+ if (program.verbose) {
104
+ console.log(file_path);
105
+ }
106
+
107
+ const file = fs.readFileSync(file_path, "utf8");
108
+ messages.push(
109
+ ...(file_path.endsWith("xml")
110
+ ? getStringsFromXmlFile(file)
111
+ : getStringsFromInput(file))
112
+ );
113
+ } catch (e) {
114
+ console.log(e);
115
+ }
116
+ }
117
+
118
+ // Hash the messages and set the key-value pair for json
119
+ for (let i = 0; i < messages.length; i++) {
120
+ messages_json[getKeyHash(messages[i])] = messages[i];
121
+ }
122
+
123
+ // Add to messages.json
124
+ fs.writeFileSync(
125
+ path.resolve(__dirname, "../crowdin/messages.json"),
126
+ JSON.stringify(messages_json),
127
+ "utf8",
128
+ (err) => console.log(err)
129
+ );
130
+ } catch (e) {
131
+ console.error(e);
132
+ }
133
+ })();