xlf-translate 2.0.7-develop.1 → 2.0.7-develop.3

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.
Files changed (2) hide show
  1. package/package.json +8 -9
  2. package/src/translate.js +22 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlf-translate",
3
- "version": "2.0.7-develop.1",
3
+ "version": "2.0.7-develop.3",
4
4
  "description": "Populate XLIFF (.XLF) files with existing translations",
5
5
  "main": "src/translate.js",
6
6
  "files": [
@@ -18,19 +18,18 @@
18
18
  "license": "BSD-3-Clause",
19
19
  "dependencies": {
20
20
  "argparse": "^2.0.1",
21
- "cheerio": "^1.0.0",
22
- "js-yaml": "^4.1.0",
23
- "jsonpath": "^1.0.0"
21
+ "cheerio": "^1.2.0",
22
+ "js-yaml": "^4.1.1"
24
23
  },
25
24
  "repository": {
26
25
  "type": "git",
27
26
  "url": "git+https://github.com/tsvetomir/xlf-translate.git"
28
27
  },
29
28
  "devDependencies": {
30
- "@eslint/js": "^9.17.0",
31
- "@vitest/eslint-plugin": "^1.1.22",
32
- "eslint": "^9.17.0",
33
- "globals": "^15.14.0",
34
- "vitest": "^2.1.8"
29
+ "@eslint/js": "^10.0.1",
30
+ "@vitest/eslint-plugin": "^1.6.9",
31
+ "eslint": "^10.0.0",
32
+ "globals": "^17.3.0",
33
+ "vitest": "^4.0.18"
35
34
  }
36
35
  }
package/src/translate.js CHANGED
@@ -1,12 +1,29 @@
1
1
  'use strict';
2
2
 
3
- const jp = require('jsonpath');
4
-
5
3
  const indent = node => {
6
4
  const indent = node.parent().html().match(/^\s+/);
7
5
  return indent !== null ? indent[0] : '';
8
6
  };
9
7
 
8
+ function query(obj, id) {
9
+ if (typeof id !== 'string') {
10
+ return null;
11
+ }
12
+
13
+ const parts = id.split('.');
14
+ if (!Object.hasOwnProperty.call(obj, parts[0])) {
15
+ return null;
16
+ }
17
+
18
+ const value = obj[parts[0]];
19
+ if (parts.length === 1) {
20
+ return value;
21
+ } else {
22
+ const subid = parts.slice(1).join('.');
23
+ return query(value, subid);
24
+ }
25
+ };
26
+
10
27
  /**
11
28
  * Fills in translations in XLIFF files based on 'meaning' metadata as a key.
12
29
  *
@@ -29,13 +46,11 @@ const translate = (doc, lang, force) => {
29
46
  })
30
47
  .filter(({ id }) => id && isKey(id))
31
48
  .map(({ id, unit }) => {
32
- const parts = id.split('.').map(part => `['${part}']`);
33
- const query = '$' + parts.join('');
34
- const match = jp.query(lang, query);
49
+ const match = query(lang, id);
35
50
 
36
51
  return {
37
- found: match.length === 1,
38
- text: match[0],
52
+ found: match !== null,
53
+ text: match,
39
54
  unit: unit
40
55
  };
41
56
  })