ilib-lint 2.21.0 → 2.21.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilib-lint",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"module": "./src/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/iLib-js/ilib-mono
|
|
46
|
+
"url": "https://github.com/iLib-js/ilib-mono"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=12 <23"
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"jsdoc-to-markdown": "^8.0.3",
|
|
65
65
|
"typescript": "^5.9.2",
|
|
66
66
|
"npm-run-all": "^4.1.5",
|
|
67
|
-
"ilib-lint-webos": "^1.0
|
|
67
|
+
"ilib-lint-webos": "^1.3.0",
|
|
68
68
|
"ilib-internal": "^0.0.0"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
@@ -77,14 +77,14 @@
|
|
|
77
77
|
"micromatch": "^4.0.7",
|
|
78
78
|
"options-parser": "^0.4.0",
|
|
79
79
|
"xml-js": "^1.6.11",
|
|
80
|
-
"ilib-xliff-webos": "^1.0.
|
|
80
|
+
"ilib-xliff-webos": "^1.0.5",
|
|
81
81
|
"ilib-casemapper": "^1.0.2",
|
|
82
82
|
"ilib-common": "^1.1.6",
|
|
83
83
|
"ilib-ctype": "^1.3.0",
|
|
84
84
|
"ilib-locale": "^1.2.4",
|
|
85
85
|
"ilib-lint-common": "^3.7.0",
|
|
86
86
|
"ilib-scriptinfo": "^1.0.0",
|
|
87
|
-
"ilib-tools-common": "^1.20.
|
|
87
|
+
"ilib-tools-common": "^1.20.1",
|
|
88
88
|
"ilib-xliff": "^1.4.1"
|
|
89
89
|
},
|
|
90
90
|
"scripts": {
|
|
@@ -63,7 +63,8 @@ class XliffSerializer extends Serializer {
|
|
|
63
63
|
const xliffObj = XliffFactory(getXliffInfo(ir.sourceFile.getContent()));
|
|
64
64
|
const xliff = new ResourceXliff({
|
|
65
65
|
path: ir.sourceFile.getPath(),
|
|
66
|
-
xliff: xliffObj
|
|
66
|
+
xliff: xliffObj,
|
|
67
|
+
sourceLocale: xliffObj.sourceLocale
|
|
67
68
|
});
|
|
68
69
|
resources.forEach(resource => {
|
|
69
70
|
xliff.addResource(resource);
|
|
@@ -76,4 +77,4 @@ class XliffSerializer extends Serializer {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
export default XliffSerializer;
|
|
80
|
+
export default XliffSerializer;
|
package/src/plugins/utils.js
CHANGED
|
@@ -23,25 +23,43 @@ import { xml2js } from 'xml-js';
|
|
|
23
23
|
* Extracts the XLIFF version from the provided data.
|
|
24
24
|
*
|
|
25
25
|
* @param {String} data The XML data as a string.
|
|
26
|
-
* @returns {Object} the xliff version and
|
|
26
|
+
* @returns {Object} the xliff version, style and sourceLocale.
|
|
27
27
|
*/
|
|
28
28
|
export function getXliffInfo(data) {
|
|
29
29
|
const defaultInfo = {
|
|
30
30
|
version: "1.2",
|
|
31
|
-
style: "standard"
|
|
31
|
+
style: "standard",
|
|
32
|
+
sourceLocale: "en-US"
|
|
32
33
|
};
|
|
33
34
|
if (!data) return defaultInfo;
|
|
34
35
|
|
|
35
36
|
try {
|
|
36
37
|
const parsedData = xml2js(data);
|
|
37
|
-
const
|
|
38
|
-
|
|
38
|
+
const root = parsedData?.elements?.find(el => el.name === "xliff");
|
|
39
|
+
if (!root) return defaultInfo;
|
|
40
|
+
|
|
41
|
+
const xmlVersion = root.attributes?.version || defaultInfo.version;
|
|
42
|
+
|
|
43
|
+
// XLIFF 1.2: <file source-language="">
|
|
44
|
+
const fileElem = root.elements?.find(el => el.name === "file");
|
|
45
|
+
const sourceLanguage12 = fileElem?.attributes?.["source-language"];
|
|
46
|
+
|
|
47
|
+
// XLIFF 2.0: <xliff srcLang="">
|
|
48
|
+
const sourceLanguage20 = root.attributes?.srcLang;
|
|
49
|
+
|
|
50
|
+
const sourceLocale = xmlVersion === "1.2" ? sourceLanguage12 : sourceLanguage20;
|
|
51
|
+
|
|
52
|
+
// style
|
|
53
|
+
const projectAttr = fileElem?.attributes?.["l:project"] || root.attributes?.["l:project"];
|
|
54
|
+
const style = xmlVersion === "2.0" && !projectAttr ? "webOS" : "standard";
|
|
39
55
|
|
|
40
56
|
return {
|
|
41
|
-
version: xmlVersion
|
|
42
|
-
style
|
|
57
|
+
version: xmlVersion,
|
|
58
|
+
style,
|
|
59
|
+
sourceLocale: sourceLocale || defaultInfo.sourceLocale
|
|
43
60
|
};
|
|
61
|
+
|
|
44
62
|
} catch (e) {
|
|
45
63
|
return defaultInfo;
|
|
46
64
|
}
|
|
47
|
-
}
|
|
65
|
+
}
|