asab_webui_shell 27.2.5 → 27.2.6
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/modules/i18n/service.js +47 -0
- package/package.json +1 -1
|
@@ -100,5 +100,52 @@ class I18nService extends _asab_webui_components.Service {
|
|
|
100
100
|
addSource(promise) {
|
|
101
101
|
this.Sources.push(promise);
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
Adds a library source for localization.
|
|
106
|
+
@param {string} path - The path in the library.
|
|
107
|
+
Usage:
|
|
108
|
+
in the main.js file of the microfrontend application add the following line:
|
|
109
|
+
app.Services?.I18nService.addLibrarySource('path/to/localization');
|
|
110
|
+
|
|
111
|
+
All available translations are merged and the priority/precedence (when there are duplicate keys) is the following:
|
|
112
|
+
1. Library
|
|
113
|
+
2. Microfrontend (src/locales)
|
|
114
|
+
3. Container (public/locales)
|
|
115
|
+
*/
|
|
116
|
+
addLibrarySource() {
|
|
117
|
+
var _this2 = this;
|
|
118
|
+
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
119
|
+
var tenantService = this.App.Services.TenantService;
|
|
120
|
+
var basePath = path ? "/library/item/Localization/".concat(path) : "/library/item/Localization";
|
|
121
|
+
if (!tenantService) {
|
|
122
|
+
console.warn('TenantService not available, skipping Library localization source.');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.Sources.push(/*#__PURE__*/function () {
|
|
126
|
+
var _ref3 = (0, _asyncToGenerator2.default)(function* (language, namespace) {
|
|
127
|
+
var currentTenant = tenantService.getCurrentTenant();
|
|
128
|
+
if (!currentTenant) {
|
|
129
|
+
console.debug('Current tenant not available, skipping Library localization source.');
|
|
130
|
+
return {};
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
var ASABLibraryAPI = _this2.App.axiosCreate('asab-library');
|
|
134
|
+
var response = yield ASABLibraryAPI.get("".concat(basePath, "/").concat(language, "/").concat(namespace, ".json"), {
|
|
135
|
+
params: {
|
|
136
|
+
tenant: currentTenant
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return response.data;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error("Failed to load localization from Library for ".concat(language, "/").concat(namespace, ":"), error.message);
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return function (_x5, _x6) {
|
|
146
|
+
return _ref3.apply(this, arguments);
|
|
147
|
+
};
|
|
148
|
+
}());
|
|
149
|
+
}
|
|
103
150
|
}
|
|
104
151
|
exports.default = I18nService;
|