@ni/xliff-to-json-converter 1.1.14 → 1.1.15
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/dist/{commonjs → esm}/convert.js +7 -12
- package/dist/{commonjs/cli.js → esm/index.js} +5 -10
- package/dist/esm/json-file.js +9 -0
- package/dist/esm/util.js +1 -0
- package/dist/esm/xliff-file.js +9 -0
- package/package.json +29 -12
- package/dist/commonjs/json-file.js +0 -13
- package/dist/commonjs/util.js +0 -2
- package/dist/commonjs/xliff-file.js +0 -13
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.makeParsedTranslation = makeParsedTranslation;
|
|
6
|
-
const json_file_1 = require("./json-file");
|
|
7
|
-
const xliff_file_1 = require("./xliff-file");
|
|
8
|
-
async function convertXliff2Json(src, dst) {
|
|
9
|
-
const xliff = await (0, xliff_file_1.loadXliff)(src);
|
|
1
|
+
import { saveJson } from './json-file.js';
|
|
2
|
+
import { loadXliff } from './xliff-file.js';
|
|
3
|
+
export async function convertXliff2Json(src, dst) {
|
|
4
|
+
const xliff = await loadXliff(src);
|
|
10
5
|
const json = xliff2Json(xliff);
|
|
11
|
-
|
|
6
|
+
saveJson(json, dst);
|
|
12
7
|
}
|
|
13
|
-
function xliff2Json(xliff) {
|
|
8
|
+
export function xliff2Json(xliff) {
|
|
14
9
|
const translations = {};
|
|
15
10
|
const template = xliff.resources['ng2.template'];
|
|
16
11
|
Object.keys(template).forEach(key => {
|
|
@@ -66,7 +61,7 @@ function xliffTranslation2jsonString(xliff) {
|
|
|
66
61
|
*
|
|
67
62
|
* Adapted from the function in @angular/localize of the same name
|
|
68
63
|
*/
|
|
69
|
-
function makeParsedTranslation(messageParts, placeholderNames) {
|
|
64
|
+
export function makeParsedTranslation(messageParts, placeholderNames) {
|
|
70
65
|
if (messageParts.length !== placeholderNames.length + 1) {
|
|
71
66
|
throw new Error('translation part length mismatch');
|
|
72
67
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
-
const helpers_1 = require("yargs/helpers");
|
|
9
|
-
const convert_1 = require("./convert");
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import { hideBin } from 'yargs/helpers';
|
|
4
|
+
import { convertXliff2Json } from './convert.js';
|
|
10
5
|
// This is how yargs expects to be run at the entry point of a cli application
|
|
11
6
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-floating-promises
|
|
12
|
-
(
|
|
7
|
+
yargs(hideBin(process.argv))
|
|
13
8
|
.strict()
|
|
14
9
|
.scriptName('xliff-to-json-converter')
|
|
15
10
|
.usage('$0 --source <src.xlf> --destination <dst.json>')
|
|
@@ -28,7 +23,7 @@ const convert_1 = require("./convert");
|
|
|
28
23
|
}), async (argv) => {
|
|
29
24
|
const { source, destination } = argv;
|
|
30
25
|
console.log(`Converting ${source} -> ${destination}`);
|
|
31
|
-
await
|
|
26
|
+
await convertXliff2Json(source, destination);
|
|
32
27
|
})
|
|
33
28
|
.help()
|
|
34
29
|
.argv;
|
package/dist/esm/util.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { xliff12ToJs } from 'xliff';
|
|
3
|
+
export async function loadXliff(path) {
|
|
4
|
+
const xliff = readFileSync(path);
|
|
5
|
+
return await parseXliff(xliff.toString());
|
|
6
|
+
}
|
|
7
|
+
export async function parseXliff(contents) {
|
|
8
|
+
return await xliff12ToJs(contents, { captureSpacesBetweenElements: true });
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ni/xliff-to-json-converter",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "Utility to convert translation files from XLIFF to JSON for Angular localization",
|
|
5
|
-
"main": "dist/commonjs/cli.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"xliff-to-json-converter": "./dist/commonjs/cli.js"
|
|
8
|
-
},
|
|
9
5
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"compile": "tsc -p tsconfig.json",
|
|
12
|
-
"compile-watch": "tsc -p tsconfig.json -w",
|
|
6
|
+
"build": "tsc -p tsconfig.json",
|
|
13
7
|
"lint": "eslint .",
|
|
14
8
|
"format": "eslint . --fix",
|
|
15
9
|
"pack": "npm pack",
|
|
@@ -17,6 +11,29 @@
|
|
|
17
11
|
"tdd": "npm run build && npm run test",
|
|
18
12
|
"test": "jasmine"
|
|
19
13
|
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/esm/index.d.ts",
|
|
19
|
+
"import": "./dist/esm/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./dist/esm/*.d.ts",
|
|
23
|
+
"import": "./dist/esm/*/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"typesVersions": {
|
|
27
|
+
"*": {
|
|
28
|
+
"*": [
|
|
29
|
+
"dist/esm/*",
|
|
30
|
+
"dist/esm/*/index.d.ts"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"xliff-to-json-converter": "./dist/esm/index.js"
|
|
36
|
+
},
|
|
20
37
|
"repository": {
|
|
21
38
|
"type": "git",
|
|
22
39
|
"url": "git+https://github.com/ni/nimble.git"
|
|
@@ -26,6 +43,10 @@
|
|
|
26
43
|
},
|
|
27
44
|
"author": "National Instruments",
|
|
28
45
|
"license": "MIT",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"xliff": "^6.1.0",
|
|
48
|
+
"yargs": "^17.5.1"
|
|
49
|
+
},
|
|
29
50
|
"devDependencies": {
|
|
30
51
|
"@ni-private/eslint-config-nimble": "*",
|
|
31
52
|
"@types/jasmine": "^5.1.4",
|
|
@@ -33,9 +54,5 @@
|
|
|
33
54
|
"jasmine": "^5.1.0",
|
|
34
55
|
"jasmine-core": "^5.1.2",
|
|
35
56
|
"typescript": "~5.8.3"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"xliff": "^6.1.0",
|
|
39
|
-
"yargs": "^17.5.1"
|
|
40
57
|
}
|
|
41
58
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringify = stringify;
|
|
4
|
-
exports.saveJson = saveJson;
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
function stringify(json) {
|
|
7
|
-
const content = JSON.stringify(json, undefined, 4);
|
|
8
|
-
return content;
|
|
9
|
-
}
|
|
10
|
-
function saveJson(json, dst) {
|
|
11
|
-
const content = stringify(json);
|
|
12
|
-
(0, fs_1.writeFileSync)(dst, content);
|
|
13
|
-
}
|
package/dist/commonjs/util.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadXliff = loadXliff;
|
|
4
|
-
exports.parseXliff = parseXliff;
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const xliff_1 = require("xliff");
|
|
7
|
-
async function loadXliff(path) {
|
|
8
|
-
const xliff = (0, fs_1.readFileSync)(path);
|
|
9
|
-
return await parseXliff(xliff.toString());
|
|
10
|
-
}
|
|
11
|
-
async function parseXliff(contents) {
|
|
12
|
-
return await (0, xliff_1.xliff12ToJs)(contents, { captureSpacesBetweenElements: true });
|
|
13
|
-
}
|