@itwin/core-i18n 5.14.0-dev.8 → 5.15.0-dev.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/CHANGELOG.md +31 -1
- package/lib/cjs/ITwinLocalization.d.ts.map +1 -1
- package/lib/cjs/ITwinLocalization.js +3 -17
- package/lib/cjs/ITwinLocalization.js.map +1 -1
- package/lib/cjs/test/ITwinLocalization.test.js +60 -0
- package/lib/cjs/test/ITwinLocalization.test.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js +310 -402
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.js +66 -21
- package/lib/cjs/test/webpack/bundled-tests.js.map +1 -1
- package/lib/cjs/test/webpack/vendors-common_temp_node_modules_pnpm_cross-fetch_4_1_0_node_modules_cross-fetch_dist_browser-44272f.bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/vendors-common_temp_node_modules_pnpm_cross-fetch_4_1_0_node_modules_cross-fetch_dist_browser-44272f.bundled-tests.js.map +1 -1
- package/lib/esm/ITwinLocalization.d.ts.map +1 -1
- package/lib/esm/ITwinLocalization.js +3 -17
- package/lib/esm/ITwinLocalization.js.map +1 -1
- package/lib/esm/test/ITwinLocalization.test.js +60 -0
- package/lib/esm/test/ITwinLocalization.test.js.map +1 -1
- package/package.json +6 -6
|
@@ -22480,23 +22480,9 @@ class ITwinLocalization {
|
|
|
22480
22480
|
this.i18next.loadNamespaces(name, (err) => {
|
|
22481
22481
|
if (!err)
|
|
22482
22482
|
return resolve();
|
|
22483
|
-
//
|
|
22484
|
-
|
|
22485
|
-
|
|
22486
|
-
// Using Backend from i18next-http-backend, err will be an array of strings of each namespace it tried to read and its locale.
|
|
22487
|
-
// There might be errs for some other namespaces as well as this one. We resolve the promise unless there's an error for each possible locale.
|
|
22488
|
-
let locales = this.getLanguageList().map((thisLocale) => `/${thisLocale}/`);
|
|
22489
|
-
try {
|
|
22490
|
-
for (const thisError of err) {
|
|
22491
|
-
if (typeof thisError === "string")
|
|
22492
|
-
locales = locales.filter((thisLocale) => !thisError.includes(thisLocale));
|
|
22493
|
-
}
|
|
22494
|
-
}
|
|
22495
|
-
catch {
|
|
22496
|
-
locales = [];
|
|
22497
|
-
}
|
|
22498
|
-
// if we removed every locale from the array, it wasn't loaded.
|
|
22499
|
-
if (locales.length === 0)
|
|
22483
|
+
// i18next can return errors from other concurrent namespace loads in this callback.
|
|
22484
|
+
const wasLoaded = this.getLanguageList().some((language) => this.i18next.hasResourceBundle(language, name));
|
|
22485
|
+
if (!wasLoaded)
|
|
22500
22486
|
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
22501
22487
|
resolve();
|
|
22502
22488
|
});
|
|
@@ -23433,10 +23419,9 @@ function interpolateUrl(str, data) {
|
|
|
23433
23419
|
/******/ // This file contains only the entry chunk.
|
|
23434
23420
|
/******/ // The chunk loading function for additional chunks
|
|
23435
23421
|
/******/ __webpack_require__.e = (chunkId) => {
|
|
23436
|
-
/******/
|
|
23437
|
-
/******/
|
|
23438
|
-
/******/
|
|
23439
|
-
/******/ }, []));
|
|
23422
|
+
/******/ const promises = [];
|
|
23423
|
+
/******/ __webpack_require__.f.j(chunkId, promises);
|
|
23424
|
+
/******/ return Promise.all(promises);
|
|
23440
23425
|
/******/ };
|
|
23441
23426
|
/******/
|
|
23442
23427
|
/******/ /* webpack/runtime/get javascript chunk filename */
|
|
@@ -23636,6 +23621,7 @@ let exports = __webpack_exports__;
|
|
|
23636
23621
|
*--------------------------------------------------------------------------------------------*/
|
|
23637
23622
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
23638
23623
|
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.5.0/node_modules/chai/index.js");
|
|
23624
|
+
const core_bentley_1 = __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js");
|
|
23639
23625
|
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
23640
23626
|
describe("ITwinLocalization", () => {
|
|
23641
23627
|
let localization;
|
|
@@ -24502,6 +24488,65 @@ describe("ITwinLocalization", () => {
|
|
|
24502
24488
|
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24503
24489
|
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24504
24490
|
});
|
|
24491
|
+
it("attributes errors from concurrent namespace loads to the namespace that failed", async () => {
|
|
24492
|
+
const pendingLoads = new Map();
|
|
24493
|
+
const backend = {
|
|
24494
|
+
type: "backend",
|
|
24495
|
+
init: () => { },
|
|
24496
|
+
read: (_language, namespace, callback) => pendingLoads.set(namespace, callback),
|
|
24497
|
+
};
|
|
24498
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({
|
|
24499
|
+
backendPlugin: backend,
|
|
24500
|
+
initOptions: { lng: "en", fallbackLng: false },
|
|
24501
|
+
});
|
|
24502
|
+
await itwinLocalization.initialize([]);
|
|
24503
|
+
const loggedErrors = [];
|
|
24504
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- Preserve the exact method reference so the test can restore it.
|
|
24505
|
+
const originalLogError = core_bentley_1.Logger.logError;
|
|
24506
|
+
core_bentley_1.Logger.logError = (_category, message) => loggedErrors.push(String(message));
|
|
24507
|
+
try {
|
|
24508
|
+
const loadedPromise = itwinLocalization.registerNamespace("Loaded");
|
|
24509
|
+
const missingPromise = itwinLocalization.registerNamespace("Missing");
|
|
24510
|
+
chai_1.assert.sameMembers([...pendingLoads.keys()], ["Loaded", "Missing"]);
|
|
24511
|
+
pendingLoads.get("Missing")?.(new Error("Missing namespace"), false);
|
|
24512
|
+
pendingLoads.get("Loaded")?.(null, { key: "value" });
|
|
24513
|
+
await Promise.all([missingPromise, loadedPromise]);
|
|
24514
|
+
chai_1.assert.deepEqual(loggedErrors, ["No resources for namespace Missing could be loaded"]);
|
|
24515
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasResourceBundle("en", "Loaded"));
|
|
24516
|
+
}
|
|
24517
|
+
finally {
|
|
24518
|
+
core_bentley_1.Logger.logError = originalLogError;
|
|
24519
|
+
}
|
|
24520
|
+
});
|
|
24521
|
+
it("does not log an error when a namespace loads from a fallback language", async () => {
|
|
24522
|
+
const pendingLoads = new Map();
|
|
24523
|
+
const backend = {
|
|
24524
|
+
type: "backend",
|
|
24525
|
+
init: () => { },
|
|
24526
|
+
read: (language, namespace, callback) => pendingLoads.set(`${language}/${namespace}`, callback),
|
|
24527
|
+
};
|
|
24528
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({
|
|
24529
|
+
backendPlugin: backend,
|
|
24530
|
+
initOptions: { lng: "fr", fallbackLng: "en" },
|
|
24531
|
+
});
|
|
24532
|
+
await itwinLocalization.initialize([]);
|
|
24533
|
+
const loggedErrors = [];
|
|
24534
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- Preserve the exact method reference so the test can restore it.
|
|
24535
|
+
const originalLogError = core_bentley_1.Logger.logError;
|
|
24536
|
+
core_bentley_1.Logger.logError = (_category, message) => loggedErrors.push(String(message));
|
|
24537
|
+
try {
|
|
24538
|
+
const loadPromise = itwinLocalization.registerNamespace("Fallback");
|
|
24539
|
+
chai_1.assert.sameMembers([...pendingLoads.keys()], ["fr/Fallback", "en/Fallback"]);
|
|
24540
|
+
pendingLoads.get("fr/Fallback")?.(new Error("Missing French namespace"), false);
|
|
24541
|
+
pendingLoads.get("en/Fallback")?.(null, { key: "value" });
|
|
24542
|
+
await loadPromise;
|
|
24543
|
+
chai_1.assert.isEmpty(loggedErrors);
|
|
24544
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasResourceBundle("en", "Fallback"));
|
|
24545
|
+
}
|
|
24546
|
+
finally {
|
|
24547
|
+
core_bentley_1.Logger.logError = originalLogError;
|
|
24548
|
+
}
|
|
24549
|
+
});
|
|
24505
24550
|
});
|
|
24506
24551
|
// unregisterNamespace() isn't used and basically does nothing
|
|
24507
24552
|
// describe("#unregisterNamespace", () => {
|