sapui5-i18n-resolver 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.
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SapUi5I18nResolver = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const I18N_PATTERN_START = "{i18n>";
|
|
12
|
+
const I18N_PATTERN_END = "}";
|
|
13
|
+
|
|
14
|
+
function resolveI18nPlaceholders$1(data, i18nLookup) {
|
|
15
|
+
if (!data || typeof data !== "object") {
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const stack = [data];
|
|
20
|
+
|
|
21
|
+
while (stack.length) {
|
|
22
|
+
const current = stack.pop();
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(current)) {
|
|
25
|
+
for (let i = 0; i < current.length; i++) {
|
|
26
|
+
const value = current[i];
|
|
27
|
+
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
current[i] = resolveString(value, i18nLookup);
|
|
30
|
+
} else if (value && typeof value === "object") {
|
|
31
|
+
stack.push(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
for (const key in current) {
|
|
36
|
+
const value = current[key];
|
|
37
|
+
|
|
38
|
+
if (typeof value === "string") {
|
|
39
|
+
current[key] = resolveString(value, i18nLookup);
|
|
40
|
+
} else if (value && typeof value === "object") {
|
|
41
|
+
stack.push(value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function resolveString(value, i18nLookup) {
|
|
51
|
+
if (
|
|
52
|
+
value.startsWith(I18N_PATTERN_START) &&
|
|
53
|
+
value.endsWith(I18N_PATTERN_END)
|
|
54
|
+
) {
|
|
55
|
+
const key = value.slice(6, -1);
|
|
56
|
+
return i18nLookup(key) ?? value;
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var resolver = {
|
|
62
|
+
resolveI18nPlaceholders: resolveI18nPlaceholders$1
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const { resolveI18nPlaceholders } = resolver;
|
|
66
|
+
|
|
67
|
+
function resolveUsingUI5Models(appDataModel, i18nModel) {
|
|
68
|
+
if (!appDataModel || !i18nModel) {
|
|
69
|
+
throw new Error("Both appDataModel and i18nModel are required");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const resourceBundle = i18nModel.getResourceBundle();
|
|
73
|
+
const data = appDataModel.getData();
|
|
74
|
+
|
|
75
|
+
resolveI18nPlaceholders(data, function (key) {
|
|
76
|
+
return resourceBundle.getText(key, null, true);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
appDataModel.refresh(true);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var ui5Adapter = {
|
|
83
|
+
resolveUsingUI5Models
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const core = resolver;
|
|
87
|
+
const ui5 = ui5Adapter;
|
|
88
|
+
|
|
89
|
+
var src = {
|
|
90
|
+
...core,
|
|
91
|
+
...ui5
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(src);
|
|
95
|
+
|
|
96
|
+
return index;
|
|
97
|
+
|
|
98
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SapUi5I18nResolver=t()}(this,function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(e,t){if(e.startsWith("{i18n>")&&e.endsWith("}")){return t(e.slice(6,-1))??e}return e}var o={resolveI18nPlaceholders:function(e,o){if(!e||"object"!=typeof e)return e;const n=[e];for(;n.length;){const e=n.pop();if(Array.isArray(e))for(let r=0;r<e.length;r++){const s=e[r];"string"==typeof s?e[r]=t(s,o):s&&"object"==typeof s&&n.push(s)}else for(const r in e){const s=e[r];"string"==typeof s?e[r]=t(s,o):s&&"object"==typeof s&&n.push(s)}}return e}};const{resolveI18nPlaceholders:n}=o;var r={resolveUsingUI5Models:function(e,t){if(!e||!t)throw new Error("Both appDataModel and i18nModel are required");const o=t.getResourceBundle(),r=e.getData();n(r,function(e){return o.getText(e,null,!0)}),e.refresh(!0)}};return e({...o,...r})});
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sapui5-i18n-resolver",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "High-performance i18n placeholder resolver for SAPUI5/OpenUI5",
|
|
5
|
+
"main": "dist/sapui5-i18n-resolver.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"preinstall": "rollup -c",
|
|
11
|
+
"postinstall": "node scripts/postinstall.js",
|
|
12
|
+
"build": "rollup -c"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"sapui5",
|
|
16
|
+
"openui5",
|
|
17
|
+
"i18n",
|
|
18
|
+
"json",
|
|
19
|
+
"resolver"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
24
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
25
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
26
|
+
"rollup": "^4.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"fs-extra": "^11.3.3"
|
|
30
|
+
}
|
|
31
|
+
}
|