@itwin/core-i18n 3.7.0-dev.1 → 3.7.0-dev.2
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 +5 -0
- package/lib/cjs/ITwinLocalization.d.ts +99 -99
- package/lib/cjs/ITwinLocalization.js +231 -231
- package/lib/cjs/ITwinLocalization.js.map +1 -1
- package/lib/cjs/core-i18n.d.ts +7 -7
- package/lib/cjs/core-i18n.js +23 -23
- package/lib/cjs/core-i18n.js.map +1 -1
- package/lib/cjs/test/ITwinLocalization.test.d.ts +1 -1
- package/lib/cjs/test/ITwinLocalization.test.js +868 -868
- package/lib/cjs/test/ITwinLocalization.test.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js +1175 -1163
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.js +1203 -1191
- package/lib/cjs/test/webpack/bundled-tests.js.map +1 -1
- package/lib/esm/ITwinLocalization.d.ts +99 -99
- package/lib/esm/ITwinLocalization.js +224 -224
- package/lib/esm/ITwinLocalization.js.map +1 -1
- package/lib/esm/core-i18n.d.ts +7 -7
- package/lib/esm/core-i18n.js +11 -11
- package/lib/esm/core-i18n.js.map +1 -1
- package/lib/esm/test/ITwinLocalization.test.d.ts +1 -1
- package/lib/esm/test/ITwinLocalization.test.js +866 -866
- package/lib/esm/test/ITwinLocalization.test.js.map +1 -1
- package/package.json +7 -7
|
@@ -10823,8 +10823,8 @@ module.exports = getFuncName;
|
|
|
10823
10823
|
"use strict";
|
|
10824
10824
|
|
|
10825
10825
|
|
|
10826
|
-
var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
10827
|
-
var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
10826
|
+
var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/classCallCheck.js");
|
|
10827
|
+
var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/createClass.js");
|
|
10828
10828
|
|
|
10829
10829
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10830
10830
|
|
|
@@ -11256,15 +11256,15 @@ module.exports = Browser;
|
|
|
11256
11256
|
"use strict";
|
|
11257
11257
|
|
|
11258
11258
|
|
|
11259
|
-
var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11260
|
-
var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11261
|
-
var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11262
|
-
var _assertThisInitialized = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11263
|
-
var _inherits = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11264
|
-
var _possibleConstructorReturn = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11265
|
-
var _getPrototypeOf = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11266
|
-
var _defineProperty = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11267
|
-
var _toArray = __webpack_require__(/*! @babel/runtime/helpers/toArray */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
11259
|
+
var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js");
|
|
11260
|
+
var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/classCallCheck.js");
|
|
11261
|
+
var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/createClass.js");
|
|
11262
|
+
var _assertThisInitialized = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
|
|
11263
|
+
var _inherits = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/inherits.js");
|
|
11264
|
+
var _possibleConstructorReturn = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js");
|
|
11265
|
+
var _getPrototypeOf = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js");
|
|
11266
|
+
var _defineProperty = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/defineProperty.js");
|
|
11267
|
+
var _toArray = __webpack_require__(/*! @babel/runtime/helpers/toArray */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toArray.js");
|
|
11268
11268
|
|
|
11269
11269
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11270
11270
|
|
|
@@ -20466,6 +20466,12 @@ class ReadonlySortedArray {
|
|
|
20466
20466
|
for (let i = 0; i < this.length; i++)
|
|
20467
20467
|
func(this._array[i]);
|
|
20468
20468
|
}
|
|
20469
|
+
/** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
|
|
20470
|
+
slice(start, end) {
|
|
20471
|
+
const slice = new ReadonlySortedArray(this._compare, this._duplicatePolicy, this._clone);
|
|
20472
|
+
slice._array = this._array.slice(start, end);
|
|
20473
|
+
return slice;
|
|
20474
|
+
}
|
|
20469
20475
|
/**
|
|
20470
20476
|
* Computes the position at which the specified value should be inserted to maintain sorted order.
|
|
20471
20477
|
* @param value The value whose position is to be computed.
|
|
@@ -20596,6 +20602,12 @@ class SortedArray extends ReadonlySortedArray {
|
|
|
20596
20602
|
* @returns the index of the deleted value, or -1 if no such element exists.
|
|
20597
20603
|
*/
|
|
20598
20604
|
remove(value) { return this._remove(value); }
|
|
20605
|
+
/** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
|
|
20606
|
+
slice(start, end) {
|
|
20607
|
+
const slice = new SortedArray(this._compare, this._duplicatePolicy, this._clone);
|
|
20608
|
+
slice._array = this._array.slice(start, end);
|
|
20609
|
+
return slice;
|
|
20610
|
+
}
|
|
20599
20611
|
}
|
|
20600
20612
|
|
|
20601
20613
|
|
|
@@ -22324,237 +22336,237 @@ function partitionArray(array, criterion) {
|
|
|
22324
22336
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
22325
22337
|
|
|
22326
22338
|
"use strict";
|
|
22327
|
-
|
|
22328
|
-
/*---------------------------------------------------------------------------------------------
|
|
22329
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
22330
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
22331
|
-
*--------------------------------------------------------------------------------------------*/
|
|
22332
|
-
/** @packageDocumentation
|
|
22333
|
-
* @module Localization
|
|
22334
|
-
*/
|
|
22335
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22336
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22337
|
-
};
|
|
22338
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
22339
|
-
exports.ITwinLocalization = void 0;
|
|
22340
|
-
const i18next_1 = __importDefault(__webpack_require__(/*! i18next */ "../../common/temp/node_modules/.pnpm/i18next@21.10.0/node_modules/i18next/dist/cjs/i18next.js"));
|
|
22341
|
-
const i18next_browser_languagedetector_1 = __importDefault(__webpack_require__(/*! i18next-browser-languagedetector */ "../../common/temp/node_modules/.pnpm/i18next-browser-languagedetector@6.1.8/node_modules/i18next-browser-languagedetector/dist/cjs/i18nextBrowserLanguageDetector.js"));
|
|
22342
|
-
const i18next_http_backend_1 = __importDefault(__webpack_require__(/*! i18next-http-backend */ "../../common/temp/node_modules/.pnpm/i18next-http-backend@1.4.5/node_modules/i18next-http-backend/cjs/index.js"));
|
|
22343
|
-
const core_bentley_1 = __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js");
|
|
22344
|
-
const DEFAULT_MAX_RETRIES = 1; // a low number prevents wasted time and potential timeouts when requesting localization files throws an error
|
|
22345
|
-
/** Supplies localizations for iTwin.js
|
|
22346
|
-
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
22347
|
-
* @public
|
|
22348
|
-
*/
|
|
22349
|
-
class ITwinLocalization {
|
|
22350
|
-
constructor(options) {
|
|
22351
|
-
var _a, _b, _c;
|
|
22352
|
-
this._namespaces = new Map();
|
|
22353
|
-
this.i18next = i18next_1.default.createInstance();
|
|
22354
|
-
this._backendOptions = {
|
|
22355
|
-
loadPath: (_a = options === null || options === void 0 ? void 0 : options.urlTemplate) !== null && _a !== void 0 ? _a : "locales/{{lng}}/{{ns}}.json",
|
|
22356
|
-
crossDomain: true,
|
|
22357
|
-
...options === null || options === void 0 ? void 0 : options.backendHttpOptions,
|
|
22358
|
-
};
|
|
22359
|
-
this._detectionOptions = {
|
|
22360
|
-
order: ["querystring", "navigator", "htmlTag"],
|
|
22361
|
-
lookupQuerystring: "lng",
|
|
22362
|
-
caches: [],
|
|
22363
|
-
...options === null || options === void 0 ? void 0 : options.detectorOptions,
|
|
22364
|
-
};
|
|
22365
|
-
this._initOptions = {
|
|
22366
|
-
interpolation: { escapeValue: true },
|
|
22367
|
-
fallbackLng: "en",
|
|
22368
|
-
maxRetries: DEFAULT_MAX_RETRIES,
|
|
22369
|
-
backend: this._backendOptions,
|
|
22370
|
-
detection: this._detectionOptions,
|
|
22371
|
-
...options === null || options === void 0 ? void 0 : options.initOptions,
|
|
22372
|
-
};
|
|
22373
|
-
this.i18next
|
|
22374
|
-
.use((_b = options === null || options === void 0 ? void 0 : options.detectorPlugin) !== null && _b !== void 0 ? _b : i18next_browser_languagedetector_1.default)
|
|
22375
|
-
.use((_c = options === null || options === void 0 ? void 0 : options.backendPlugin) !== null && _c !== void 0 ? _c : i18next_http_backend_1.default)
|
|
22376
|
-
.use(TranslationLogger);
|
|
22377
|
-
}
|
|
22378
|
-
async initialize(namespaces) {
|
|
22379
|
-
var _a;
|
|
22380
|
-
// Also consider namespaces passed into constructor
|
|
22381
|
-
const initNamespaces = [this._initOptions.ns || []].flat();
|
|
22382
|
-
const combinedNamespaces = new Set([...namespaces, ...initNamespaces]); // without duplicates
|
|
22383
|
-
const defaultNamespace = (_a = this._initOptions.defaultNS) !== null && _a !== void 0 ? _a : namespaces[0];
|
|
22384
|
-
if (defaultNamespace)
|
|
22385
|
-
combinedNamespaces.add(defaultNamespace); // Make sure default namespace is in namespaces list
|
|
22386
|
-
const initOptions = {
|
|
22387
|
-
...this._initOptions,
|
|
22388
|
-
defaultNS: defaultNamespace,
|
|
22389
|
-
ns: [...combinedNamespaces],
|
|
22390
|
-
};
|
|
22391
|
-
// if in a development environment, set debugging
|
|
22392
|
-
if (false)
|
|
22393
|
-
{}
|
|
22394
|
-
const initPromise = this.i18next.init(initOptions);
|
|
22395
|
-
for (const ns of namespaces)
|
|
22396
|
-
this._namespaces.set(ns, initPromise);
|
|
22397
|
-
return initPromise;
|
|
22398
|
-
}
|
|
22399
|
-
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
22400
|
-
* For example:
|
|
22401
|
-
* ``` ts
|
|
22402
|
-
* "MyKeys": {
|
|
22403
|
-
* "Key1": "First value",
|
|
22404
|
-
* "Key2": "Second value"
|
|
22405
|
-
* }
|
|
22406
|
-
* ```
|
|
22407
|
-
*
|
|
22408
|
-
* ``` ts
|
|
22409
|
-
* i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!"
|
|
22410
|
-
* ```
|
|
22411
|
-
* @param line The input line, potentially containing %{keys}.
|
|
22412
|
-
* @returns The line with all %{keys} translated
|
|
22413
|
-
* @public
|
|
22414
|
-
*/
|
|
22415
|
-
getLocalizedKeys(line) {
|
|
22416
|
-
return line.replace(/\%\{(.+?)\}/g, (_match, tag) => this.getLocalizedString(tag));
|
|
22417
|
-
}
|
|
22418
|
-
/** Return the translated value of a key.
|
|
22419
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
22420
|
-
* @note The key includes the namespace, which identifies the particular localization file that contains the property,
|
|
22421
|
-
* followed by a colon, followed by the property in the JSON file.
|
|
22422
|
-
* For example:
|
|
22423
|
-
* ``` ts
|
|
22424
|
-
* const dataString: string = IModelApp.localization.getLocalizedString("iModelJs:BackgroundMap.BingDataAttribution");
|
|
22425
|
-
* ```
|
|
22426
|
-
* assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.
|
|
22427
|
-
* @returns The string corresponding to the first key that resolves.
|
|
22428
|
-
* @throws Error if no keys resolve to a string.
|
|
22429
|
-
* @public
|
|
22430
|
-
*/
|
|
22431
|
-
getLocalizedString(key, options) {
|
|
22432
|
-
if ((options === null || options === void 0 ? void 0 : options.returnDetails) || (options === null || options === void 0 ? void 0 : options.returnObjects)) {
|
|
22433
|
-
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
22434
|
-
}
|
|
22435
|
-
const value = this.i18next.t(key, options);
|
|
22436
|
-
if (typeof value !== "string") {
|
|
22437
|
-
throw new Error("Translation key(s) string not found");
|
|
22438
|
-
}
|
|
22439
|
-
return value;
|
|
22440
|
-
}
|
|
22441
|
-
/** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need
|
|
22442
|
-
* to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.
|
|
22443
|
-
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
22444
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
22445
|
-
* @returns The string corresponding to the first key that resolves.
|
|
22446
|
-
* @throws Error if no keys resolve to a string.
|
|
22447
|
-
* @internal
|
|
22448
|
-
*/
|
|
22449
|
-
getLocalizedStringWithNamespace(namespace, key, options) {
|
|
22450
|
-
let fullKey = "";
|
|
22451
|
-
if (typeof key === "string") {
|
|
22452
|
-
fullKey = `${namespace}:${key}`;
|
|
22453
|
-
}
|
|
22454
|
-
else {
|
|
22455
|
-
fullKey = key.map((subKey) => {
|
|
22456
|
-
return `${namespace}:${subKey}`;
|
|
22457
|
-
});
|
|
22458
|
-
}
|
|
22459
|
-
return this.getLocalizedString(fullKey, options);
|
|
22460
|
-
}
|
|
22461
|
-
/** Gets the English translation.
|
|
22462
|
-
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
22463
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
22464
|
-
* @returns The string corresponding to the first key that resolves.
|
|
22465
|
-
* @throws Error if no keys resolve to a string.
|
|
22466
|
-
* @internal
|
|
22467
|
-
*/
|
|
22468
|
-
getEnglishString(namespace, key, options) {
|
|
22469
|
-
if ((options === null || options === void 0 ? void 0 : options.returnDetails) || (options === null || options === void 0 ? void 0 : options.returnObjects)) {
|
|
22470
|
-
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
22471
|
-
}
|
|
22472
|
-
options = {
|
|
22473
|
-
...options,
|
|
22474
|
-
ns: namespace, // ensure namespace argument is used
|
|
22475
|
-
};
|
|
22476
|
-
const en = this.i18next.getFixedT("en", namespace);
|
|
22477
|
-
const str = en(key, options);
|
|
22478
|
-
if (typeof str !== "string")
|
|
22479
|
-
throw new Error("Translation key(s) not found");
|
|
22480
|
-
return str;
|
|
22481
|
-
}
|
|
22482
|
-
/** Get the promise for an already registered Namespace.
|
|
22483
|
-
* @param name - the name of the namespace
|
|
22484
|
-
* @public
|
|
22485
|
-
*/
|
|
22486
|
-
getNamespacePromise(name) {
|
|
22487
|
-
return this._namespaces.get(name);
|
|
22488
|
-
}
|
|
22489
|
-
/** @internal */
|
|
22490
|
-
getLanguageList() {
|
|
22491
|
-
return this.i18next.languages;
|
|
22492
|
-
}
|
|
22493
|
-
/** override the language detected in the browser */
|
|
22494
|
-
async changeLanguage(language) {
|
|
22495
|
-
return this.i18next.changeLanguage(language);
|
|
22496
|
-
}
|
|
22497
|
-
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
22498
|
-
* @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.
|
|
22499
|
-
* @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,
|
|
22500
|
-
* based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await
|
|
22501
|
-
* fulfillment of the readPromise Promise property of the returned LocalizationNamespace.
|
|
22502
|
-
* @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)
|
|
22503
|
-
* @public
|
|
22504
|
-
*/
|
|
22505
|
-
async registerNamespace(name) {
|
|
22506
|
-
const existing = this._namespaces.get(name);
|
|
22507
|
-
if (existing !== undefined)
|
|
22508
|
-
return existing;
|
|
22509
|
-
const theReadPromise = new Promise((resolve) => {
|
|
22510
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
22511
|
-
this.i18next.loadNamespaces(name, (err) => {
|
|
22512
|
-
if (!err)
|
|
22513
|
-
return resolve();
|
|
22514
|
-
// Here we got a non-null err object.
|
|
22515
|
-
// This method is called when the system has attempted to load the resources for the namespaces for each possible locale.
|
|
22516
|
-
// For example 'fr-ca' might be the most specific locale, in which case 'fr' and 'en' are fallback locales.
|
|
22517
|
-
// Using Backend from i18next-http-backend, err will be an array of strings of each namespace it tried to read and its locale.
|
|
22518
|
-
// 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.
|
|
22519
|
-
let locales = this.getLanguageList().map((thisLocale) => `/${thisLocale}/`);
|
|
22520
|
-
try {
|
|
22521
|
-
for (const thisError of err) {
|
|
22522
|
-
if (typeof thisError === "string")
|
|
22523
|
-
locales = locales.filter((thisLocale) => !thisError.includes(thisLocale));
|
|
22524
|
-
}
|
|
22525
|
-
}
|
|
22526
|
-
catch (e) {
|
|
22527
|
-
locales = [];
|
|
22528
|
-
}
|
|
22529
|
-
// if we removed every locale from the array, it wasn't loaded.
|
|
22530
|
-
if (locales.length === 0)
|
|
22531
|
-
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
22532
|
-
resolve();
|
|
22533
|
-
});
|
|
22534
|
-
});
|
|
22535
|
-
this._namespaces.set(name, theReadPromise);
|
|
22536
|
-
return theReadPromise;
|
|
22537
|
-
}
|
|
22538
|
-
/** @internal */
|
|
22539
|
-
unregisterNamespace(name) {
|
|
22540
|
-
this._namespaces.delete(name);
|
|
22541
|
-
}
|
|
22542
|
-
}
|
|
22543
|
-
exports.ITwinLocalization = ITwinLocalization;
|
|
22544
|
-
class TranslationLogger {
|
|
22545
|
-
log(args) { core_bentley_1.Logger.logInfo("i18n", this.createLogMessage(args)); }
|
|
22546
|
-
warn(args) { core_bentley_1.Logger.logWarning("i18n", this.createLogMessage(args)); }
|
|
22547
|
-
error(args) { core_bentley_1.Logger.logError("i18n", this.createLogMessage(args)); }
|
|
22548
|
-
createLogMessage(args) {
|
|
22549
|
-
let message = args[0];
|
|
22550
|
-
for (let i = 1; i < args.length; ++i) {
|
|
22551
|
-
if (typeof args[i] === "string")
|
|
22552
|
-
message += `\n ${args[i]}`;
|
|
22553
|
-
}
|
|
22554
|
-
return message;
|
|
22555
|
-
}
|
|
22556
|
-
}
|
|
22557
|
-
TranslationLogger.type = "logger";
|
|
22339
|
+
|
|
22340
|
+
/*---------------------------------------------------------------------------------------------
|
|
22341
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
22342
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
22343
|
+
*--------------------------------------------------------------------------------------------*/
|
|
22344
|
+
/** @packageDocumentation
|
|
22345
|
+
* @module Localization
|
|
22346
|
+
*/
|
|
22347
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22348
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22349
|
+
};
|
|
22350
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
22351
|
+
exports.ITwinLocalization = void 0;
|
|
22352
|
+
const i18next_1 = __importDefault(__webpack_require__(/*! i18next */ "../../common/temp/node_modules/.pnpm/i18next@21.10.0/node_modules/i18next/dist/cjs/i18next.js"));
|
|
22353
|
+
const i18next_browser_languagedetector_1 = __importDefault(__webpack_require__(/*! i18next-browser-languagedetector */ "../../common/temp/node_modules/.pnpm/i18next-browser-languagedetector@6.1.8/node_modules/i18next-browser-languagedetector/dist/cjs/i18nextBrowserLanguageDetector.js"));
|
|
22354
|
+
const i18next_http_backend_1 = __importDefault(__webpack_require__(/*! i18next-http-backend */ "../../common/temp/node_modules/.pnpm/i18next-http-backend@1.4.5/node_modules/i18next-http-backend/cjs/index.js"));
|
|
22355
|
+
const core_bentley_1 = __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js");
|
|
22356
|
+
const DEFAULT_MAX_RETRIES = 1; // a low number prevents wasted time and potential timeouts when requesting localization files throws an error
|
|
22357
|
+
/** Supplies localizations for iTwin.js
|
|
22358
|
+
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
22359
|
+
* @public
|
|
22360
|
+
*/
|
|
22361
|
+
class ITwinLocalization {
|
|
22362
|
+
constructor(options) {
|
|
22363
|
+
var _a, _b, _c;
|
|
22364
|
+
this._namespaces = new Map();
|
|
22365
|
+
this.i18next = i18next_1.default.createInstance();
|
|
22366
|
+
this._backendOptions = {
|
|
22367
|
+
loadPath: (_a = options === null || options === void 0 ? void 0 : options.urlTemplate) !== null && _a !== void 0 ? _a : "locales/{{lng}}/{{ns}}.json",
|
|
22368
|
+
crossDomain: true,
|
|
22369
|
+
...options === null || options === void 0 ? void 0 : options.backendHttpOptions,
|
|
22370
|
+
};
|
|
22371
|
+
this._detectionOptions = {
|
|
22372
|
+
order: ["querystring", "navigator", "htmlTag"],
|
|
22373
|
+
lookupQuerystring: "lng",
|
|
22374
|
+
caches: [],
|
|
22375
|
+
...options === null || options === void 0 ? void 0 : options.detectorOptions,
|
|
22376
|
+
};
|
|
22377
|
+
this._initOptions = {
|
|
22378
|
+
interpolation: { escapeValue: true },
|
|
22379
|
+
fallbackLng: "en",
|
|
22380
|
+
maxRetries: DEFAULT_MAX_RETRIES,
|
|
22381
|
+
backend: this._backendOptions,
|
|
22382
|
+
detection: this._detectionOptions,
|
|
22383
|
+
...options === null || options === void 0 ? void 0 : options.initOptions,
|
|
22384
|
+
};
|
|
22385
|
+
this.i18next
|
|
22386
|
+
.use((_b = options === null || options === void 0 ? void 0 : options.detectorPlugin) !== null && _b !== void 0 ? _b : i18next_browser_languagedetector_1.default)
|
|
22387
|
+
.use((_c = options === null || options === void 0 ? void 0 : options.backendPlugin) !== null && _c !== void 0 ? _c : i18next_http_backend_1.default)
|
|
22388
|
+
.use(TranslationLogger);
|
|
22389
|
+
}
|
|
22390
|
+
async initialize(namespaces) {
|
|
22391
|
+
var _a;
|
|
22392
|
+
// Also consider namespaces passed into constructor
|
|
22393
|
+
const initNamespaces = [this._initOptions.ns || []].flat();
|
|
22394
|
+
const combinedNamespaces = new Set([...namespaces, ...initNamespaces]); // without duplicates
|
|
22395
|
+
const defaultNamespace = (_a = this._initOptions.defaultNS) !== null && _a !== void 0 ? _a : namespaces[0];
|
|
22396
|
+
if (defaultNamespace)
|
|
22397
|
+
combinedNamespaces.add(defaultNamespace); // Make sure default namespace is in namespaces list
|
|
22398
|
+
const initOptions = {
|
|
22399
|
+
...this._initOptions,
|
|
22400
|
+
defaultNS: defaultNamespace,
|
|
22401
|
+
ns: [...combinedNamespaces],
|
|
22402
|
+
};
|
|
22403
|
+
// if in a development environment, set debugging
|
|
22404
|
+
if (false)
|
|
22405
|
+
{}
|
|
22406
|
+
const initPromise = this.i18next.init(initOptions);
|
|
22407
|
+
for (const ns of namespaces)
|
|
22408
|
+
this._namespaces.set(ns, initPromise);
|
|
22409
|
+
return initPromise;
|
|
22410
|
+
}
|
|
22411
|
+
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
22412
|
+
* For example:
|
|
22413
|
+
* ``` ts
|
|
22414
|
+
* "MyKeys": {
|
|
22415
|
+
* "Key1": "First value",
|
|
22416
|
+
* "Key2": "Second value"
|
|
22417
|
+
* }
|
|
22418
|
+
* ```
|
|
22419
|
+
*
|
|
22420
|
+
* ``` ts
|
|
22421
|
+
* i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!"
|
|
22422
|
+
* ```
|
|
22423
|
+
* @param line The input line, potentially containing %{keys}.
|
|
22424
|
+
* @returns The line with all %{keys} translated
|
|
22425
|
+
* @public
|
|
22426
|
+
*/
|
|
22427
|
+
getLocalizedKeys(line) {
|
|
22428
|
+
return line.replace(/\%\{(.+?)\}/g, (_match, tag) => this.getLocalizedString(tag));
|
|
22429
|
+
}
|
|
22430
|
+
/** Return the translated value of a key.
|
|
22431
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
22432
|
+
* @note The key includes the namespace, which identifies the particular localization file that contains the property,
|
|
22433
|
+
* followed by a colon, followed by the property in the JSON file.
|
|
22434
|
+
* For example:
|
|
22435
|
+
* ``` ts
|
|
22436
|
+
* const dataString: string = IModelApp.localization.getLocalizedString("iModelJs:BackgroundMap.BingDataAttribution");
|
|
22437
|
+
* ```
|
|
22438
|
+
* assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.
|
|
22439
|
+
* @returns The string corresponding to the first key that resolves.
|
|
22440
|
+
* @throws Error if no keys resolve to a string.
|
|
22441
|
+
* @public
|
|
22442
|
+
*/
|
|
22443
|
+
getLocalizedString(key, options) {
|
|
22444
|
+
if ((options === null || options === void 0 ? void 0 : options.returnDetails) || (options === null || options === void 0 ? void 0 : options.returnObjects)) {
|
|
22445
|
+
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
22446
|
+
}
|
|
22447
|
+
const value = this.i18next.t(key, options);
|
|
22448
|
+
if (typeof value !== "string") {
|
|
22449
|
+
throw new Error("Translation key(s) string not found");
|
|
22450
|
+
}
|
|
22451
|
+
return value;
|
|
22452
|
+
}
|
|
22453
|
+
/** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need
|
|
22454
|
+
* to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.
|
|
22455
|
+
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
22456
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
22457
|
+
* @returns The string corresponding to the first key that resolves.
|
|
22458
|
+
* @throws Error if no keys resolve to a string.
|
|
22459
|
+
* @internal
|
|
22460
|
+
*/
|
|
22461
|
+
getLocalizedStringWithNamespace(namespace, key, options) {
|
|
22462
|
+
let fullKey = "";
|
|
22463
|
+
if (typeof key === "string") {
|
|
22464
|
+
fullKey = `${namespace}:${key}`;
|
|
22465
|
+
}
|
|
22466
|
+
else {
|
|
22467
|
+
fullKey = key.map((subKey) => {
|
|
22468
|
+
return `${namespace}:${subKey}`;
|
|
22469
|
+
});
|
|
22470
|
+
}
|
|
22471
|
+
return this.getLocalizedString(fullKey, options);
|
|
22472
|
+
}
|
|
22473
|
+
/** Gets the English translation.
|
|
22474
|
+
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
22475
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
22476
|
+
* @returns The string corresponding to the first key that resolves.
|
|
22477
|
+
* @throws Error if no keys resolve to a string.
|
|
22478
|
+
* @internal
|
|
22479
|
+
*/
|
|
22480
|
+
getEnglishString(namespace, key, options) {
|
|
22481
|
+
if ((options === null || options === void 0 ? void 0 : options.returnDetails) || (options === null || options === void 0 ? void 0 : options.returnObjects)) {
|
|
22482
|
+
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
22483
|
+
}
|
|
22484
|
+
options = {
|
|
22485
|
+
...options,
|
|
22486
|
+
ns: namespace, // ensure namespace argument is used
|
|
22487
|
+
};
|
|
22488
|
+
const en = this.i18next.getFixedT("en", namespace);
|
|
22489
|
+
const str = en(key, options);
|
|
22490
|
+
if (typeof str !== "string")
|
|
22491
|
+
throw new Error("Translation key(s) not found");
|
|
22492
|
+
return str;
|
|
22493
|
+
}
|
|
22494
|
+
/** Get the promise for an already registered Namespace.
|
|
22495
|
+
* @param name - the name of the namespace
|
|
22496
|
+
* @public
|
|
22497
|
+
*/
|
|
22498
|
+
getNamespacePromise(name) {
|
|
22499
|
+
return this._namespaces.get(name);
|
|
22500
|
+
}
|
|
22501
|
+
/** @internal */
|
|
22502
|
+
getLanguageList() {
|
|
22503
|
+
return this.i18next.languages;
|
|
22504
|
+
}
|
|
22505
|
+
/** override the language detected in the browser */
|
|
22506
|
+
async changeLanguage(language) {
|
|
22507
|
+
return this.i18next.changeLanguage(language);
|
|
22508
|
+
}
|
|
22509
|
+
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
22510
|
+
* @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.
|
|
22511
|
+
* @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,
|
|
22512
|
+
* based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await
|
|
22513
|
+
* fulfillment of the readPromise Promise property of the returned LocalizationNamespace.
|
|
22514
|
+
* @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)
|
|
22515
|
+
* @public
|
|
22516
|
+
*/
|
|
22517
|
+
async registerNamespace(name) {
|
|
22518
|
+
const existing = this._namespaces.get(name);
|
|
22519
|
+
if (existing !== undefined)
|
|
22520
|
+
return existing;
|
|
22521
|
+
const theReadPromise = new Promise((resolve) => {
|
|
22522
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
22523
|
+
this.i18next.loadNamespaces(name, (err) => {
|
|
22524
|
+
if (!err)
|
|
22525
|
+
return resolve();
|
|
22526
|
+
// Here we got a non-null err object.
|
|
22527
|
+
// This method is called when the system has attempted to load the resources for the namespaces for each possible locale.
|
|
22528
|
+
// For example 'fr-ca' might be the most specific locale, in which case 'fr' and 'en' are fallback locales.
|
|
22529
|
+
// Using Backend from i18next-http-backend, err will be an array of strings of each namespace it tried to read and its locale.
|
|
22530
|
+
// 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.
|
|
22531
|
+
let locales = this.getLanguageList().map((thisLocale) => `/${thisLocale}/`);
|
|
22532
|
+
try {
|
|
22533
|
+
for (const thisError of err) {
|
|
22534
|
+
if (typeof thisError === "string")
|
|
22535
|
+
locales = locales.filter((thisLocale) => !thisError.includes(thisLocale));
|
|
22536
|
+
}
|
|
22537
|
+
}
|
|
22538
|
+
catch (e) {
|
|
22539
|
+
locales = [];
|
|
22540
|
+
}
|
|
22541
|
+
// if we removed every locale from the array, it wasn't loaded.
|
|
22542
|
+
if (locales.length === 0)
|
|
22543
|
+
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
22544
|
+
resolve();
|
|
22545
|
+
});
|
|
22546
|
+
});
|
|
22547
|
+
this._namespaces.set(name, theReadPromise);
|
|
22548
|
+
return theReadPromise;
|
|
22549
|
+
}
|
|
22550
|
+
/** @internal */
|
|
22551
|
+
unregisterNamespace(name) {
|
|
22552
|
+
this._namespaces.delete(name);
|
|
22553
|
+
}
|
|
22554
|
+
}
|
|
22555
|
+
exports.ITwinLocalization = ITwinLocalization;
|
|
22556
|
+
class TranslationLogger {
|
|
22557
|
+
log(args) { core_bentley_1.Logger.logInfo("i18n", this.createLogMessage(args)); }
|
|
22558
|
+
warn(args) { core_bentley_1.Logger.logWarning("i18n", this.createLogMessage(args)); }
|
|
22559
|
+
error(args) { core_bentley_1.Logger.logError("i18n", this.createLogMessage(args)); }
|
|
22560
|
+
createLogMessage(args) {
|
|
22561
|
+
let message = args[0];
|
|
22562
|
+
for (let i = 1; i < args.length; ++i) {
|
|
22563
|
+
if (typeof args[i] === "string")
|
|
22564
|
+
message += `\n ${args[i]}`;
|
|
22565
|
+
}
|
|
22566
|
+
return message;
|
|
22567
|
+
}
|
|
22568
|
+
}
|
|
22569
|
+
TranslationLogger.type = "logger";
|
|
22558
22570
|
|
|
22559
22571
|
|
|
22560
22572
|
/***/ }),
|
|
@@ -22569,10 +22581,10 @@ TranslationLogger.type = "logger";
|
|
|
22569
22581
|
|
|
22570
22582
|
/***/ }),
|
|
22571
22583
|
|
|
22572
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22573
|
-
|
|
22574
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22575
|
-
|
|
22584
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js":
|
|
22585
|
+
/*!**************************************************************************************************************************!*\
|
|
22586
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***!
|
|
22587
|
+
\**************************************************************************************************************************/
|
|
22576
22588
|
/***/ ((module) => {
|
|
22577
22589
|
|
|
22578
22590
|
function _arrayLikeToArray(arr, len) {
|
|
@@ -22584,10 +22596,10 @@ module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exp
|
|
|
22584
22596
|
|
|
22585
22597
|
/***/ }),
|
|
22586
22598
|
|
|
22587
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22588
|
-
|
|
22589
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22590
|
-
|
|
22599
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js":
|
|
22600
|
+
/*!************************************************************************************************************************!*\
|
|
22601
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js ***!
|
|
22602
|
+
\************************************************************************************************************************/
|
|
22591
22603
|
/***/ ((module) => {
|
|
22592
22604
|
|
|
22593
22605
|
function _arrayWithHoles(arr) {
|
|
@@ -22597,10 +22609,10 @@ module.exports = _arrayWithHoles, module.exports.__esModule = true, module.expor
|
|
|
22597
22609
|
|
|
22598
22610
|
/***/ }),
|
|
22599
22611
|
|
|
22600
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22601
|
-
|
|
22602
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22603
|
-
|
|
22612
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js":
|
|
22613
|
+
/*!*******************************************************************************************************************************!*\
|
|
22614
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js ***!
|
|
22615
|
+
\*******************************************************************************************************************************/
|
|
22604
22616
|
/***/ ((module) => {
|
|
22605
22617
|
|
|
22606
22618
|
function _assertThisInitialized(self) {
|
|
@@ -22613,10 +22625,10 @@ module.exports = _assertThisInitialized, module.exports.__esModule = true, modul
|
|
|
22613
22625
|
|
|
22614
22626
|
/***/ }),
|
|
22615
22627
|
|
|
22616
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22617
|
-
|
|
22618
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22619
|
-
|
|
22628
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/classCallCheck.js":
|
|
22629
|
+
/*!************************************************************************************************************************!*\
|
|
22630
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/classCallCheck.js ***!
|
|
22631
|
+
\************************************************************************************************************************/
|
|
22620
22632
|
/***/ ((module) => {
|
|
22621
22633
|
|
|
22622
22634
|
function _classCallCheck(instance, Constructor) {
|
|
@@ -22628,13 +22640,13 @@ module.exports = _classCallCheck, module.exports.__esModule = true, module.expor
|
|
|
22628
22640
|
|
|
22629
22641
|
/***/ }),
|
|
22630
22642
|
|
|
22631
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22632
|
-
|
|
22633
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22634
|
-
|
|
22643
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/createClass.js":
|
|
22644
|
+
/*!*********************************************************************************************************************!*\
|
|
22645
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/createClass.js ***!
|
|
22646
|
+
\*********************************************************************************************************************/
|
|
22635
22647
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22636
22648
|
|
|
22637
|
-
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22649
|
+
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js");
|
|
22638
22650
|
function _defineProperties(target, props) {
|
|
22639
22651
|
for (var i = 0; i < props.length; i++) {
|
|
22640
22652
|
var descriptor = props[i];
|
|
@@ -22656,13 +22668,13 @@ module.exports = _createClass, module.exports.__esModule = true, module.exports[
|
|
|
22656
22668
|
|
|
22657
22669
|
/***/ }),
|
|
22658
22670
|
|
|
22659
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22660
|
-
|
|
22661
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22662
|
-
|
|
22671
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/defineProperty.js":
|
|
22672
|
+
/*!************************************************************************************************************************!*\
|
|
22673
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/defineProperty.js ***!
|
|
22674
|
+
\************************************************************************************************************************/
|
|
22663
22675
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22664
22676
|
|
|
22665
|
-
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22677
|
+
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js");
|
|
22666
22678
|
function _defineProperty(obj, key, value) {
|
|
22667
22679
|
key = toPropertyKey(key);
|
|
22668
22680
|
if (key in obj) {
|
|
@@ -22681,10 +22693,10 @@ module.exports = _defineProperty, module.exports.__esModule = true, module.expor
|
|
|
22681
22693
|
|
|
22682
22694
|
/***/ }),
|
|
22683
22695
|
|
|
22684
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22685
|
-
|
|
22686
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22687
|
-
|
|
22696
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js":
|
|
22697
|
+
/*!************************************************************************************************************************!*\
|
|
22698
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js ***!
|
|
22699
|
+
\************************************************************************************************************************/
|
|
22688
22700
|
/***/ ((module) => {
|
|
22689
22701
|
|
|
22690
22702
|
function _getPrototypeOf(o) {
|
|
@@ -22697,13 +22709,13 @@ module.exports = _getPrototypeOf, module.exports.__esModule = true, module.expor
|
|
|
22697
22709
|
|
|
22698
22710
|
/***/ }),
|
|
22699
22711
|
|
|
22700
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22701
|
-
|
|
22702
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22703
|
-
|
|
22712
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/inherits.js":
|
|
22713
|
+
/*!******************************************************************************************************************!*\
|
|
22714
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/inherits.js ***!
|
|
22715
|
+
\******************************************************************************************************************/
|
|
22704
22716
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22705
22717
|
|
|
22706
|
-
var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22718
|
+
var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js");
|
|
22707
22719
|
function _inherits(subClass, superClass) {
|
|
22708
22720
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
22709
22721
|
throw new TypeError("Super expression must either be null or a function");
|
|
@@ -22724,10 +22736,10 @@ module.exports = _inherits, module.exports.__esModule = true, module.exports["de
|
|
|
22724
22736
|
|
|
22725
22737
|
/***/ }),
|
|
22726
22738
|
|
|
22727
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22728
|
-
|
|
22729
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22730
|
-
|
|
22739
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/iterableToArray.js":
|
|
22740
|
+
/*!*************************************************************************************************************************!*\
|
|
22741
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/iterableToArray.js ***!
|
|
22742
|
+
\*************************************************************************************************************************/
|
|
22731
22743
|
/***/ ((module) => {
|
|
22732
22744
|
|
|
22733
22745
|
function _iterableToArray(iter) {
|
|
@@ -22737,10 +22749,10 @@ module.exports = _iterableToArray, module.exports.__esModule = true, module.expo
|
|
|
22737
22749
|
|
|
22738
22750
|
/***/ }),
|
|
22739
22751
|
|
|
22740
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22741
|
-
|
|
22742
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22743
|
-
|
|
22752
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/nonIterableRest.js":
|
|
22753
|
+
/*!*************************************************************************************************************************!*\
|
|
22754
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/nonIterableRest.js ***!
|
|
22755
|
+
\*************************************************************************************************************************/
|
|
22744
22756
|
/***/ ((module) => {
|
|
22745
22757
|
|
|
22746
22758
|
function _nonIterableRest() {
|
|
@@ -22750,14 +22762,14 @@ module.exports = _nonIterableRest, module.exports.__esModule = true, module.expo
|
|
|
22750
22762
|
|
|
22751
22763
|
/***/ }),
|
|
22752
22764
|
|
|
22753
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22754
|
-
|
|
22755
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22756
|
-
|
|
22765
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js":
|
|
22766
|
+
/*!***********************************************************************************************************************************!*\
|
|
22767
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***!
|
|
22768
|
+
\***********************************************************************************************************************************/
|
|
22757
22769
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22758
22770
|
|
|
22759
|
-
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22760
|
-
var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22771
|
+
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
|
|
22772
|
+
var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
|
|
22761
22773
|
function _possibleConstructorReturn(self, call) {
|
|
22762
22774
|
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
22763
22775
|
return call;
|
|
@@ -22770,10 +22782,10 @@ module.exports = _possibleConstructorReturn, module.exports.__esModule = true, m
|
|
|
22770
22782
|
|
|
22771
22783
|
/***/ }),
|
|
22772
22784
|
|
|
22773
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22774
|
-
|
|
22775
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22776
|
-
|
|
22785
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js":
|
|
22786
|
+
/*!************************************************************************************************************************!*\
|
|
22787
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js ***!
|
|
22788
|
+
\************************************************************************************************************************/
|
|
22777
22789
|
/***/ ((module) => {
|
|
22778
22790
|
|
|
22779
22791
|
function _setPrototypeOf(o, p) {
|
|
@@ -22787,16 +22799,16 @@ module.exports = _setPrototypeOf, module.exports.__esModule = true, module.expor
|
|
|
22787
22799
|
|
|
22788
22800
|
/***/ }),
|
|
22789
22801
|
|
|
22790
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22791
|
-
|
|
22792
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22793
|
-
|
|
22802
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toArray.js":
|
|
22803
|
+
/*!*****************************************************************************************************************!*\
|
|
22804
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toArray.js ***!
|
|
22805
|
+
\*****************************************************************************************************************/
|
|
22794
22806
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22795
22807
|
|
|
22796
|
-
var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22797
|
-
var iterableToArray = __webpack_require__(/*! ./iterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22798
|
-
var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22799
|
-
var nonIterableRest = __webpack_require__(/*! ./nonIterableRest.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22808
|
+
var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js");
|
|
22809
|
+
var iterableToArray = __webpack_require__(/*! ./iterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/iterableToArray.js");
|
|
22810
|
+
var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js");
|
|
22811
|
+
var nonIterableRest = __webpack_require__(/*! ./nonIterableRest.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/nonIterableRest.js");
|
|
22800
22812
|
function _toArray(arr) {
|
|
22801
22813
|
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest();
|
|
22802
22814
|
}
|
|
@@ -22804,13 +22816,13 @@ module.exports = _toArray, module.exports.__esModule = true, module.exports["def
|
|
|
22804
22816
|
|
|
22805
22817
|
/***/ }),
|
|
22806
22818
|
|
|
22807
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22808
|
-
|
|
22809
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22810
|
-
|
|
22819
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPrimitive.js":
|
|
22820
|
+
/*!*********************************************************************************************************************!*\
|
|
22821
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPrimitive.js ***!
|
|
22822
|
+
\*********************************************************************************************************************/
|
|
22811
22823
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22812
22824
|
|
|
22813
|
-
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22825
|
+
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
|
|
22814
22826
|
function _toPrimitive(input, hint) {
|
|
22815
22827
|
if (_typeof(input) !== "object" || input === null) return input;
|
|
22816
22828
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -22825,14 +22837,14 @@ module.exports = _toPrimitive, module.exports.__esModule = true, module.exports[
|
|
|
22825
22837
|
|
|
22826
22838
|
/***/ }),
|
|
22827
22839
|
|
|
22828
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22829
|
-
|
|
22830
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22831
|
-
|
|
22840
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js":
|
|
22841
|
+
/*!***********************************************************************************************************************!*\
|
|
22842
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js ***!
|
|
22843
|
+
\***********************************************************************************************************************/
|
|
22832
22844
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22833
22845
|
|
|
22834
|
-
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22835
|
-
var toPrimitive = __webpack_require__(/*! ./toPrimitive.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22846
|
+
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
|
|
22847
|
+
var toPrimitive = __webpack_require__(/*! ./toPrimitive.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPrimitive.js");
|
|
22836
22848
|
function _toPropertyKey(arg) {
|
|
22837
22849
|
var key = toPrimitive(arg, "string");
|
|
22838
22850
|
return _typeof(key) === "symbol" ? key : String(key);
|
|
@@ -22841,10 +22853,10 @@ module.exports = _toPropertyKey, module.exports.__esModule = true, module.export
|
|
|
22841
22853
|
|
|
22842
22854
|
/***/ }),
|
|
22843
22855
|
|
|
22844
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22845
|
-
|
|
22846
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22847
|
-
|
|
22856
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js":
|
|
22857
|
+
/*!****************************************************************************************************************!*\
|
|
22858
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js ***!
|
|
22859
|
+
\****************************************************************************************************************/
|
|
22848
22860
|
/***/ ((module) => {
|
|
22849
22861
|
|
|
22850
22862
|
function _typeof(obj) {
|
|
@@ -22860,13 +22872,13 @@ module.exports = _typeof, module.exports.__esModule = true, module.exports["defa
|
|
|
22860
22872
|
|
|
22861
22873
|
/***/ }),
|
|
22862
22874
|
|
|
22863
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22864
|
-
|
|
22865
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22866
|
-
|
|
22875
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js":
|
|
22876
|
+
/*!************************************************************************************************************************************!*\
|
|
22877
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***!
|
|
22878
|
+
\************************************************************************************************************************************/
|
|
22867
22879
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
22868
22880
|
|
|
22869
|
-
var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
22881
|
+
var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js");
|
|
22870
22882
|
function _unsupportedIterableToArray(o, minLen) {
|
|
22871
22883
|
if (!o) return;
|
|
22872
22884
|
if (typeof o === "string") return arrayLikeToArray(o, minLen);
|
|
@@ -23387,874 +23399,874 @@ var exports = __webpack_exports__;
|
|
|
23387
23399
|
/*!************************************************!*\
|
|
23388
23400
|
!*** ./lib/cjs/test/ITwinLocalization.test.js ***!
|
|
23389
23401
|
\************************************************/
|
|
23390
|
-
|
|
23391
|
-
/*---------------------------------------------------------------------------------------------
|
|
23392
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
23393
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
23394
|
-
*--------------------------------------------------------------------------------------------*/
|
|
23395
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
23396
|
-
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.3.7/node_modules/chai/index.js");
|
|
23397
|
-
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
23398
|
-
describe("ITwinLocalization", () => {
|
|
23399
|
-
let localization;
|
|
23400
|
-
let germanLocalization;
|
|
23401
|
-
describe("#constructor", () => {
|
|
23402
|
-
let itwinLocalization;
|
|
23403
|
-
it("set default namespace", async () => {
|
|
23404
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
23405
|
-
await itwinLocalization.initialize([]);
|
|
23406
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23407
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23408
|
-
});
|
|
23409
|
-
it("set default language as english", async () => {
|
|
23410
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "en" } });
|
|
23411
|
-
await itwinLocalization.initialize([]);
|
|
23412
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "en");
|
|
23413
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23414
|
-
});
|
|
23415
|
-
it("set default language as NOT english", async () => {
|
|
23416
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "de" } });
|
|
23417
|
-
await itwinLocalization.initialize([]);
|
|
23418
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "de");
|
|
23419
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
23420
|
-
});
|
|
23421
|
-
it("set fallback language as NOT english", async () => {
|
|
23422
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", fallbackLng: "de" } });
|
|
23423
|
-
await itwinLocalization.initialize([]);
|
|
23424
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.fallbackLng, "de");
|
|
23425
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("OnlyGerman"), "Hallo");
|
|
23426
|
-
});
|
|
23427
|
-
});
|
|
23428
|
-
describe("#initialize", () => {
|
|
23429
|
-
let itwinLocalization;
|
|
23430
|
-
it("cannot fetch from unregistered namespaces", async () => {
|
|
23431
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23432
|
-
await localization.initialize([]);
|
|
23433
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "FirstTrivial");
|
|
23434
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "FirstTrivial");
|
|
23435
|
-
});
|
|
23436
|
-
describe("with no default namespace predefined", () => {
|
|
23437
|
-
before(() => {
|
|
23438
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
23439
|
-
});
|
|
23440
|
-
it("no default namespace set when initialized with empty array", async () => {
|
|
23441
|
-
await itwinLocalization.initialize([]);
|
|
23442
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, undefined);
|
|
23443
|
-
});
|
|
23444
|
-
it("initialize with single namespace", async () => {
|
|
23445
|
-
var _a;
|
|
23446
|
-
await itwinLocalization.initialize(["Test"]);
|
|
23447
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Test");
|
|
23448
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Test"));
|
|
23449
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
23450
|
-
});
|
|
23451
|
-
it("initialize with two namespaces recognizes both namespaces", async () => {
|
|
23452
|
-
var _a, _b;
|
|
23453
|
-
await itwinLocalization.initialize(["Default", "Test"]);
|
|
23454
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23455
|
-
chai_1.assert.isTrue((_b = itwinLocalization.i18next.options.ns) === null || _b === void 0 ? void 0 : _b.includes("Test"));
|
|
23456
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
23457
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
23458
|
-
});
|
|
23459
|
-
it("initialize with two namespaces sets first as default", async () => {
|
|
23460
|
-
await itwinLocalization.initialize(["Default", "Test"]);
|
|
23461
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23462
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23463
|
-
});
|
|
23464
|
-
it("initialize with duplicate namespace values does not break anything", async () => {
|
|
23465
|
-
var _a;
|
|
23466
|
-
await itwinLocalization.initialize(["Default", "Default"]);
|
|
23467
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23468
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23469
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23470
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
23471
|
-
});
|
|
23472
|
-
});
|
|
23473
|
-
describe("with default namespace", () => {
|
|
23474
|
-
before(() => {
|
|
23475
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
23476
|
-
});
|
|
23477
|
-
it("default namespace set when initialized with empty array", async () => {
|
|
23478
|
-
await itwinLocalization.initialize([]);
|
|
23479
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23480
|
-
});
|
|
23481
|
-
it("default namespace not overridden by one namespace", async () => {
|
|
23482
|
-
await itwinLocalization.initialize(["Test"]);
|
|
23483
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23484
|
-
});
|
|
23485
|
-
it("default namespace not overridden by two namespaces", async () => {
|
|
23486
|
-
await itwinLocalization.initialize(["NotExist", "Test"]);
|
|
23487
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23488
|
-
});
|
|
23489
|
-
it("duplicate namespace value does not break default namespace", async () => {
|
|
23490
|
-
await itwinLocalization.initialize(["Default"]);
|
|
23491
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23492
|
-
});
|
|
23493
|
-
it("default namespace is in list of all namespaces initalized with empty array", async () => {
|
|
23494
|
-
var _a;
|
|
23495
|
-
await itwinLocalization.initialize([]);
|
|
23496
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23497
|
-
});
|
|
23498
|
-
it("default namespace is in list of all namespaces", async () => {
|
|
23499
|
-
var _a;
|
|
23500
|
-
await itwinLocalization.initialize(["Test"]);
|
|
23501
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23502
|
-
});
|
|
23503
|
-
});
|
|
23504
|
-
});
|
|
23505
|
-
describe("#getLocalizedKeys", () => {
|
|
23506
|
-
before(async () => {
|
|
23507
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23508
|
-
await localization.initialize(["Default", "Test"]);
|
|
23509
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
23510
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
23511
|
-
});
|
|
23512
|
-
it("no substitution", () => {
|
|
23513
|
-
chai_1.assert.equal(localization.getLocalizedKeys("MyString"), "MyString");
|
|
23514
|
-
});
|
|
23515
|
-
describe("Default Namespace", () => {
|
|
23516
|
-
it("first level string", () => {
|
|
23517
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default)");
|
|
23518
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default german)");
|
|
23519
|
-
});
|
|
23520
|
-
it("second level string", () => {
|
|
23521
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
23522
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
23523
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default german)");
|
|
23524
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default german)");
|
|
23525
|
-
});
|
|
23526
|
-
it("first level string with keys", () => {
|
|
23527
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default)");
|
|
23528
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
23529
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default german)");
|
|
23530
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default german)");
|
|
23531
|
-
});
|
|
23532
|
-
it("second level string with keys", () => {
|
|
23533
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
23534
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
23535
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default german)");
|
|
23536
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default german)");
|
|
23537
|
-
});
|
|
23538
|
-
it("first level missing key doesn't find a value", () => {
|
|
23539
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
23540
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
23541
|
-
});
|
|
23542
|
-
it("second level missing key doesn't find a value", () => {
|
|
23543
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
23544
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
23545
|
-
});
|
|
23546
|
-
});
|
|
23547
|
-
describe("Given Namespace", () => {
|
|
23548
|
-
it("first level string", () => {
|
|
23549
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:FirstTrivial}"), "hi First level string (default)");
|
|
23550
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:FirstTrivial}"), "hi First level string (test)");
|
|
23551
|
-
});
|
|
23552
|
-
it("second level string", () => {
|
|
23553
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
23554
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
23555
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondTrivial.Test1}"), "Second level string 1 (test)");
|
|
23556
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:SecondTrivial.Test2}"), "bye Second level string 2 (test)");
|
|
23557
|
-
});
|
|
23558
|
-
it("first level string with keys", () => {
|
|
23559
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:FirstSubstitution1}"), "First level {{str}} (default)");
|
|
23560
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
23561
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:FirstSubstitution1}"), "First level {{str}} (test)");
|
|
23562
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (test)");
|
|
23563
|
-
});
|
|
23564
|
-
it("second level string with keys", () => {
|
|
23565
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
23566
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
23567
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (test)");
|
|
23568
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (test)");
|
|
23569
|
-
});
|
|
23570
|
-
it("first level missing key doesn't find a value", () => {
|
|
23571
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{Default:MissingKeyString}"), "no MissingKeyString");
|
|
23572
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{Test:MissingKeyString}"), "no MissingKeyString");
|
|
23573
|
-
});
|
|
23574
|
-
it("second level missing key doesn't find a value", () => {
|
|
23575
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
23576
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
23577
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
23578
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
23579
|
-
});
|
|
23580
|
-
});
|
|
23581
|
-
describe("Nonexisting Namespace", () => {
|
|
23582
|
-
it("first level fails", () => {
|
|
23583
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:FirstTrivial}"), "FirstTrivial");
|
|
23584
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:MissingKeyString}"), "MissingKeyString");
|
|
23585
|
-
});
|
|
23586
|
-
it("second level fails", () => {
|
|
23587
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:SecondTrivial.Test1}"), "SecondTrivial.Test1");
|
|
23588
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:Missing.String}"), "Missing.String");
|
|
23589
|
-
});
|
|
23590
|
-
});
|
|
23591
|
-
});
|
|
23592
|
-
// The goal is not to test i18next's interpolation,
|
|
23593
|
-
// but just to have some simple tests to make sure the
|
|
23594
|
-
// basics work through the ITwinLocalization class.
|
|
23595
|
-
// For interpolation options, see: https://www.i18next.com/translation-function/interpolation
|
|
23596
|
-
describe("#getLocalizedString", () => {
|
|
23597
|
-
before(async () => {
|
|
23598
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23599
|
-
await localization.initialize(["Default", "Test"]);
|
|
23600
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
23601
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
23602
|
-
});
|
|
23603
|
-
describe("Default Namespace", () => {
|
|
23604
|
-
it("first level with no substitution", () => {
|
|
23605
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23606
|
-
});
|
|
23607
|
-
it("first level with no substitution with fallback keys", () => {
|
|
23608
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
23609
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default)");
|
|
23610
|
-
});
|
|
23611
|
-
it("more than two fallback keys succeeds", () => {
|
|
23612
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist1", "NotExist2"]), "First level string (default)");
|
|
23613
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "FirstTrivial", "NotExist2"]), "First level string (default)");
|
|
23614
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "NotExist2", "FirstTrivial"]), "First level string (default)");
|
|
23615
|
-
chai_1.assert.equal(localization.getLocalizedString(["1", "2", "3", "4", "5", "FirstTrivial"]), "First level string (default)");
|
|
23616
|
-
});
|
|
23617
|
-
it("second level with no substitution", () => {
|
|
23618
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
23619
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
23620
|
-
});
|
|
23621
|
-
it("second level with no substitution with fallback keys", () => {
|
|
23622
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
23623
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default)");
|
|
23624
|
-
});
|
|
23625
|
-
it("first level with substitution", () => {
|
|
23626
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23627
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23628
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23629
|
-
});
|
|
23630
|
-
it("first level with substitution with fallback keys", () => {
|
|
23631
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23632
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23633
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23634
|
-
});
|
|
23635
|
-
it("second level with substitution", () => {
|
|
23636
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23637
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23638
|
-
});
|
|
23639
|
-
it("second level with substitution with fallback keys", () => {
|
|
23640
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23641
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23642
|
-
});
|
|
23643
|
-
it("first level missing key doesn't find a value", () => {
|
|
23644
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
23645
|
-
});
|
|
23646
|
-
it("first level missing all keys doesn't find a value", () => {
|
|
23647
|
-
chai_1.assert.equal(localization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
23648
|
-
});
|
|
23649
|
-
it("second level missing key doesn't find a value", () => {
|
|
23650
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23651
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "MissingKeyObject.MissingString"]), "MissingKeyObject.MissingString");
|
|
23652
|
-
});
|
|
23653
|
-
it("read from en-US fallback", () => {
|
|
23654
|
-
chai_1.assert.equal(localization.getLocalizedString("OnlyEnglishUS"), "HelloUS");
|
|
23655
|
-
});
|
|
23656
|
-
});
|
|
23657
|
-
describe("Default Namespace (German)", () => {
|
|
23658
|
-
it("first level with no substitution", () => {
|
|
23659
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
23660
|
-
});
|
|
23661
|
-
it("first level with no substitution with fallback keys", () => {
|
|
23662
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default german)");
|
|
23663
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default german)");
|
|
23664
|
-
});
|
|
23665
|
-
it("second level with no substitution", () => {
|
|
23666
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
23667
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
23668
|
-
});
|
|
23669
|
-
it("second level with no substitution with fallback keys", () => {
|
|
23670
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default german)");
|
|
23671
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default german)");
|
|
23672
|
-
});
|
|
23673
|
-
it("first level with substitution", () => {
|
|
23674
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23675
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23676
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23677
|
-
});
|
|
23678
|
-
it("first level with substitution with fallback keys", () => {
|
|
23679
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23680
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23681
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23682
|
-
});
|
|
23683
|
-
it("second level with substitution", () => {
|
|
23684
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23685
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23686
|
-
});
|
|
23687
|
-
it("second level with substitution with fallback keys", () => {
|
|
23688
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23689
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23690
|
-
});
|
|
23691
|
-
it("first level missing key doesn't find a value", () => {
|
|
23692
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
23693
|
-
});
|
|
23694
|
-
it("first level missing all keys doesn't find a value", () => {
|
|
23695
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
23696
|
-
});
|
|
23697
|
-
it("second level missing key doesn't find a value", () => {
|
|
23698
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23699
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
23700
|
-
});
|
|
23701
|
-
});
|
|
23702
|
-
describe("Given Namespace", () => {
|
|
23703
|
-
it("first level with no substitution", () => {
|
|
23704
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
23705
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
23706
|
-
});
|
|
23707
|
-
it("first level with no substitution with fallback keys", () => {
|
|
23708
|
-
chai_1.assert.equal(localization.getLocalizedString(["Default:FirstTrivial", "Not:NotExist"]), "First level string (default)");
|
|
23709
|
-
chai_1.assert.equal(localization.getLocalizedString(["Default:NotExist", "Test:FirstTrivial"]), "First level string (test)");
|
|
23710
|
-
});
|
|
23711
|
-
it("second level with no substitution", () => {
|
|
23712
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
23713
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
23714
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
23715
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
23716
|
-
});
|
|
23717
|
-
it("second level with no substitution with fallback keys", () => {
|
|
23718
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
23719
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
23720
|
-
});
|
|
23721
|
-
it("first level with substitution", () => {
|
|
23722
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23723
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23724
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23725
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
23726
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23727
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
23728
|
-
});
|
|
23729
|
-
it("first level with substitution with fallback keys", () => {
|
|
23730
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23731
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:FirstSubstitution1", "Default:NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23732
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23733
|
-
});
|
|
23734
|
-
it("second level with substitution", () => {
|
|
23735
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23736
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23737
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
23738
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23739
|
-
});
|
|
23740
|
-
it("second level with substitution with fallback keys", () => {
|
|
23741
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23742
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondSubstitution.Test2", "Default:NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23743
|
-
});
|
|
23744
|
-
it("first level missing key doesn't find a value", () => {
|
|
23745
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
23746
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
23747
|
-
});
|
|
23748
|
-
it("second level missing key doesn't find a value", () => {
|
|
23749
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23750
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
23751
|
-
});
|
|
23752
|
-
it("read from en-US fallback", () => {
|
|
23753
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:OnlyEnglishUS"), "HelloUS");
|
|
23754
|
-
});
|
|
23755
|
-
});
|
|
23756
|
-
describe("Given Namespace (German)", () => {
|
|
23757
|
-
it("first level with no substitution", () => {
|
|
23758
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default german)");
|
|
23759
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (german)");
|
|
23760
|
-
});
|
|
23761
|
-
it("second level with no substitution", () => {
|
|
23762
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
23763
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
23764
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (german)");
|
|
23765
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (german)");
|
|
23766
|
-
});
|
|
23767
|
-
it("first level with substitution", () => {
|
|
23768
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23769
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23770
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23771
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
23772
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
23773
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
23774
|
-
});
|
|
23775
|
-
it("second level with substitution", () => {
|
|
23776
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23777
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23778
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
23779
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
23780
|
-
});
|
|
23781
|
-
it("first level missing key doesn't find a value", () => {
|
|
23782
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
23783
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
23784
|
-
});
|
|
23785
|
-
it("second level missing key doesn't find a value", () => {
|
|
23786
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23787
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
23788
|
-
});
|
|
23789
|
-
});
|
|
23790
|
-
describe("Nonexisting Namespace", () => {
|
|
23791
|
-
it("first level fails", () => {
|
|
23792
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
|
|
23793
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
|
|
23794
|
-
});
|
|
23795
|
-
it("second level fails", () => {
|
|
23796
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
23797
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
|
|
23798
|
-
});
|
|
23799
|
-
it("fallback key fails", () => {
|
|
23800
|
-
chai_1.assert.equal(localization.getLocalizedString(["Nonexisting:FirstTrivial", "NotExist"]), "NotExist");
|
|
23801
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Nonexisting:Missing.String"]), "Missing.String");
|
|
23802
|
-
});
|
|
23803
|
-
});
|
|
23804
|
-
// Test a few options to make sure they get passed through correctly
|
|
23805
|
-
describe("With Options", () => {
|
|
23806
|
-
it("returnDetails throws error", () => {
|
|
23807
|
-
chai_1.assert.throws(() => {
|
|
23808
|
-
localization.getLocalizedString("X", { returnDetails: true });
|
|
23809
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23810
|
-
});
|
|
23811
|
-
it("returnObjects throws error", () => {
|
|
23812
|
-
chai_1.assert.throws(() => {
|
|
23813
|
-
localization.getLocalizedString("X", { returnObjects: true });
|
|
23814
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23815
|
-
});
|
|
23816
|
-
it("returnDetails and returnObjects throws error", () => {
|
|
23817
|
-
chai_1.assert.throws(() => {
|
|
23818
|
-
localization.getLocalizedString("X", { returnDetails: true, returnObjects: true });
|
|
23819
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23820
|
-
});
|
|
23821
|
-
it("default value", () => {
|
|
23822
|
-
chai_1.assert.equal(localization.getLocalizedString("Missing", { defaultValue: "default" }), "default");
|
|
23823
|
-
});
|
|
23824
|
-
it("override fallback language", () => {
|
|
23825
|
-
// Doesn't fallback to English
|
|
23826
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { fallbackLng: "de" }), "OnlyEnglish");
|
|
23827
|
-
});
|
|
23828
|
-
it("set namespace", () => {
|
|
23829
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
23830
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (test)");
|
|
23831
|
-
});
|
|
23832
|
-
});
|
|
23833
|
-
});
|
|
23834
|
-
describe("#getLocalizedString with namespace passed in as an option", () => {
|
|
23835
|
-
before(async () => {
|
|
23836
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23837
|
-
await localization.initialize(["Default", "Test"]);
|
|
23838
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
23839
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
23840
|
-
});
|
|
23841
|
-
describe("Keys Without Namespaces", () => {
|
|
23842
|
-
it("first level with no substitution", () => {
|
|
23843
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
23844
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
23845
|
-
});
|
|
23846
|
-
it("first level with no substitution with fallback keys", () => {
|
|
23847
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Default" }), "First level string (default)");
|
|
23848
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
23849
|
-
});
|
|
23850
|
-
it("second level with no substitution", () => {
|
|
23851
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default)");
|
|
23852
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default)");
|
|
23853
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
23854
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (test)");
|
|
23855
|
-
});
|
|
23856
|
-
it("second level with no substitution with fallback keys", () => {
|
|
23857
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"], { ns: "Default" }), "Second level string 1 (default)");
|
|
23858
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"], { ns: "Test" }), "Second level string 2 (test)");
|
|
23859
|
-
});
|
|
23860
|
-
it("first level with substitution", () => {
|
|
23861
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23862
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23863
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23864
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
23865
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23866
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
23867
|
-
});
|
|
23868
|
-
it("first level with substitution with fallback keys", () => {
|
|
23869
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23870
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23871
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
23872
|
-
});
|
|
23873
|
-
it("second level with substitution", () => {
|
|
23874
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23875
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23876
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
23877
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23878
|
-
});
|
|
23879
|
-
it("second level with substitution with fallback keys", () => {
|
|
23880
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23881
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23882
|
-
});
|
|
23883
|
-
it("first level missing key doesn't find a value", () => {
|
|
23884
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
23885
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
23886
|
-
});
|
|
23887
|
-
it("second level missing key doesn't find a value", () => {
|
|
23888
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
23889
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
23890
|
-
});
|
|
23891
|
-
});
|
|
23892
|
-
describe("Keys Without Namespaces (German)", () => {
|
|
23893
|
-
it("first level with no substitution", () => {
|
|
23894
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default german)");
|
|
23895
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (german)");
|
|
23896
|
-
});
|
|
23897
|
-
it("second level with no substitution", () => {
|
|
23898
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default german)");
|
|
23899
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default german)");
|
|
23900
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (german)");
|
|
23901
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (german)");
|
|
23902
|
-
});
|
|
23903
|
-
it("first level with substitution", () => {
|
|
23904
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23905
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23906
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23907
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
23908
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
23909
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
23910
|
-
});
|
|
23911
|
-
it("second level with substitution", () => {
|
|
23912
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23913
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23914
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
23915
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
23916
|
-
});
|
|
23917
|
-
it("first level missing key doesn't find a value", () => {
|
|
23918
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
23919
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
23920
|
-
});
|
|
23921
|
-
it("second level missing key doesn't find a value", () => {
|
|
23922
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
23923
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
23924
|
-
});
|
|
23925
|
-
});
|
|
23926
|
-
describe("Keys With Namespaces", () => {
|
|
23927
|
-
it("key with same namespace works", () => {
|
|
23928
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
23929
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
23930
|
-
});
|
|
23931
|
-
it("key with different namespace overrides given namespace", () => {
|
|
23932
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Default" }), "First level string (test)");
|
|
23933
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
23934
|
-
});
|
|
23935
|
-
it("key with same namespace works with fallback keys", () => {
|
|
23936
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Default" }), "First level string (default)");
|
|
23937
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
23938
|
-
});
|
|
23939
|
-
it("key with different namespace overrides given namespace with fallback keys", () => {
|
|
23940
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Default" }), "First level string (test)");
|
|
23941
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Test" }), "First level string (default)");
|
|
23942
|
-
});
|
|
23943
|
-
it("missing key does not find a value", () => {
|
|
23944
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
23945
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["Missing1", "MissingKeyObject.MissingString"], { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
23946
|
-
});
|
|
23947
|
-
});
|
|
23948
|
-
describe("Nonexisting Namespace", () => {
|
|
23949
|
-
it("first level fails", () => {
|
|
23950
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Nonexisting" }), "FirstTrivial");
|
|
23951
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Nonexisting" }), "MissingKeyString");
|
|
23952
|
-
});
|
|
23953
|
-
it("second level fails", () => {
|
|
23954
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Nonexisting" }), "SecondTrivial.Test1");
|
|
23955
|
-
chai_1.assert.equal(localization.getLocalizedString("Missing.String", { ns: "Nonexisting" }), "Missing.String");
|
|
23956
|
-
});
|
|
23957
|
-
it("empty string namespace falls back to default namespace", () => {
|
|
23958
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "" }), "First level string (default)");
|
|
23959
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "" }), "Second level string 1 (default)");
|
|
23960
|
-
});
|
|
23961
|
-
it("fallback key fails", () => {
|
|
23962
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Nonexisting" }), "NotExist");
|
|
23963
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Missing.String"], { ns: "Nonexisting" }), "Missing.String");
|
|
23964
|
-
});
|
|
23965
|
-
it("use key with valid namespace instead", () => {
|
|
23966
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Nonexisting" }), "First level string (default)");
|
|
23967
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Nonexisting" }), "First level string (test)");
|
|
23968
|
-
});
|
|
23969
|
-
it("providing key with invalid namespace fails", () => {
|
|
23970
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting2:FirstTrivial", { ns: "Nonexisting1" }), "FirstTrivial");
|
|
23971
|
-
});
|
|
23972
|
-
});
|
|
23973
|
-
// Test a few options to make sure they get passed through correctly
|
|
23974
|
-
describe("With Options", () => {
|
|
23975
|
-
it("returnDetails throws error", () => {
|
|
23976
|
-
chai_1.assert.throws(() => {
|
|
23977
|
-
localization.getLocalizedString("X", { ns: "Default", returnDetails: true });
|
|
23978
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23979
|
-
});
|
|
23980
|
-
it("returnObjects throws error", () => {
|
|
23981
|
-
chai_1.assert.throws(() => {
|
|
23982
|
-
localization.getLocalizedString("X", { ns: "Default", returnObjects: true });
|
|
23983
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23984
|
-
});
|
|
23985
|
-
it("returnDetails and returnObjects throws error", () => {
|
|
23986
|
-
chai_1.assert.throws(() => {
|
|
23987
|
-
localization.getLocalizedString("X", { ns: "Default", returnDetails: true, returnObjects: true });
|
|
23988
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23989
|
-
});
|
|
23990
|
-
it("default value", () => {
|
|
23991
|
-
chai_1.assert.equal(localization.getLocalizedString("Missing", { ns: "Default", defaultValue: "default" }), "default");
|
|
23992
|
-
});
|
|
23993
|
-
it("override fallback language", () => {
|
|
23994
|
-
// Doesn't fallback to English
|
|
23995
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { ns: "Default", fallbackLng: "de" }), "OnlyEnglish");
|
|
23996
|
-
});
|
|
23997
|
-
});
|
|
23998
|
-
});
|
|
23999
|
-
describe("#getEnglishString", () => {
|
|
24000
|
-
before(async () => {
|
|
24001
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
24002
|
-
await localization.initialize(["Default", "Test"]);
|
|
24003
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
24004
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
24005
|
-
});
|
|
24006
|
-
describe("Given Namespace", () => {
|
|
24007
|
-
it("first level with no substitution", () => {
|
|
24008
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
24009
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
24010
|
-
});
|
|
24011
|
-
it("first level with no substitution with fallback keys", () => {
|
|
24012
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
24013
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
24014
|
-
});
|
|
24015
|
-
it("second level with no substitution", () => {
|
|
24016
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
24017
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
24018
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
24019
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
24020
|
-
});
|
|
24021
|
-
it("second level with no substitution with fallback keys", () => {
|
|
24022
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
24023
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
24024
|
-
});
|
|
24025
|
-
it("first level with substitution", () => {
|
|
24026
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24027
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
24028
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
24029
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
24030
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24031
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24032
|
-
});
|
|
24033
|
-
it("first level with substitution with fallback keys", () => {
|
|
24034
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24035
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24036
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24037
|
-
});
|
|
24038
|
-
it("second level with substitution", () => {
|
|
24039
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24040
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
24041
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
24042
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24043
|
-
});
|
|
24044
|
-
it("second level with substitution with fallback keys", () => {
|
|
24045
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24046
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24047
|
-
});
|
|
24048
|
-
it("first level missing key doesn't find a value", () => {
|
|
24049
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
24050
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
24051
|
-
});
|
|
24052
|
-
it("second level missing key doesn't find a value", () => {
|
|
24053
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
24054
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
24055
|
-
});
|
|
24056
|
-
});
|
|
24057
|
-
describe("Given Namespace with German default language returns English strings", () => {
|
|
24058
|
-
it("first level with no substitution", () => {
|
|
24059
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
24060
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
24061
|
-
});
|
|
24062
|
-
it("first level with no substitution with fallback keys", () => {
|
|
24063
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
24064
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
24065
|
-
});
|
|
24066
|
-
it("second level with no substitution", () => {
|
|
24067
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
24068
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
24069
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
24070
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
24071
|
-
});
|
|
24072
|
-
it("second level with no substitution with fallback keys", () => {
|
|
24073
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
24074
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
24075
|
-
});
|
|
24076
|
-
it("first level with substitution", () => {
|
|
24077
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24078
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
24079
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
24080
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
24081
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24082
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24083
|
-
});
|
|
24084
|
-
it("first level with substitution with fallback keys", () => {
|
|
24085
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24086
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24087
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24088
|
-
});
|
|
24089
|
-
it("second level with substitution", () => {
|
|
24090
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24091
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
24092
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
24093
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24094
|
-
});
|
|
24095
|
-
it("second level with substitution with fallback keys", () => {
|
|
24096
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24097
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24098
|
-
});
|
|
24099
|
-
it("first level missing key doesn't find a value", () => {
|
|
24100
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
24101
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
24102
|
-
});
|
|
24103
|
-
it("second level missing key doesn't find a value", () => {
|
|
24104
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
24105
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
24106
|
-
});
|
|
24107
|
-
});
|
|
24108
|
-
describe("Nonexisting Namespace", () => {
|
|
24109
|
-
it("first level fails", () => {
|
|
24110
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "FirstTrivial"), "FirstTrivial");
|
|
24111
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "MissingKeyString"), "MissingKeyString");
|
|
24112
|
-
});
|
|
24113
|
-
it("second level fails", () => {
|
|
24114
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
24115
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "Missing.String"), "Missing.String");
|
|
24116
|
-
});
|
|
24117
|
-
it("empty string namespace is treated as default namespace", () => {
|
|
24118
|
-
chai_1.assert.equal(localization.getEnglishString("", "FirstTrivial"), "First level string (default)");
|
|
24119
|
-
chai_1.assert.equal(localization.getEnglishString("", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
24120
|
-
});
|
|
24121
|
-
});
|
|
24122
|
-
// Test a few options to make sure they get passed through correctly
|
|
24123
|
-
describe("With Options", () => {
|
|
24124
|
-
it("returnDetails throws error", () => {
|
|
24125
|
-
chai_1.assert.throws(() => {
|
|
24126
|
-
localization.getEnglishString("Default", "X", { returnDetails: true });
|
|
24127
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24128
|
-
});
|
|
24129
|
-
it("returnObjects throws error", () => {
|
|
24130
|
-
chai_1.assert.throws(() => {
|
|
24131
|
-
localization.getEnglishString("Default", "X", { returnObjects: true });
|
|
24132
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24133
|
-
});
|
|
24134
|
-
it("returnDetails and returnObjects throws error", () => {
|
|
24135
|
-
chai_1.assert.throws(() => {
|
|
24136
|
-
localization.getEnglishString("Default", "X", { returnDetails: true, returnObjects: true });
|
|
24137
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24138
|
-
});
|
|
24139
|
-
it("default value", () => {
|
|
24140
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "Missing", { defaultValue: "default" }), "default");
|
|
24141
|
-
});
|
|
24142
|
-
it("english takes priority over fallback language", () => {
|
|
24143
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "OnlyEnglish", { fallbackLng: "de" }), "Hello");
|
|
24144
|
-
});
|
|
24145
|
-
// White box test
|
|
24146
|
-
it("given namespace overrides namespace translation option", () => {
|
|
24147
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
24148
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
|
|
24149
|
-
});
|
|
24150
|
-
});
|
|
24151
|
-
});
|
|
24152
|
-
// Returned promises never have anything of substance, being only empty or resolving to null...
|
|
24153
|
-
// describe("#getNamespacePromise", () => {
|
|
24154
|
-
// });
|
|
24155
|
-
describe("#getLanguageList", () => {
|
|
24156
|
-
let languages;
|
|
24157
|
-
it("english language list includes en and en-US", async () => {
|
|
24158
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
24159
|
-
await localization.initialize([]);
|
|
24160
|
-
languages = localization.getLanguageList();
|
|
24161
|
-
chai_1.assert.isTrue(languages.includes("en-US"));
|
|
24162
|
-
chai_1.assert.isTrue(languages.includes("en"));
|
|
24163
|
-
});
|
|
24164
|
-
it("when non-english language is set as default, that language and english are included in langauge list", async () => {
|
|
24165
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
24166
|
-
await germanLocalization.initialize([]);
|
|
24167
|
-
languages = germanLocalization.getLanguageList();
|
|
24168
|
-
chai_1.assert.isTrue(languages.includes("en"));
|
|
24169
|
-
chai_1.assert.isTrue(languages.includes("de"));
|
|
24170
|
-
});
|
|
24171
|
-
});
|
|
24172
|
-
describe("#changeLanguage", () => {
|
|
24173
|
-
it("change from english to another language", async () => {
|
|
24174
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
24175
|
-
await localization.initialize(["Default"]);
|
|
24176
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
24177
|
-
await localization.changeLanguage("de");
|
|
24178
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
24179
|
-
});
|
|
24180
|
-
it("change from another language to english", async () => {
|
|
24181
|
-
localization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
24182
|
-
await localization.initialize(["Default"]);
|
|
24183
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
24184
|
-
await localization.changeLanguage("en");
|
|
24185
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
24186
|
-
});
|
|
24187
|
-
});
|
|
24188
|
-
describe("#registerNamespace", () => {
|
|
24189
|
-
let itwinLocalization;
|
|
24190
|
-
beforeEach(async () => {
|
|
24191
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
24192
|
-
});
|
|
24193
|
-
it("can read from namespace after it is registered", async () => {
|
|
24194
|
-
await itwinLocalization.initialize([]);
|
|
24195
|
-
await itwinLocalization.registerNamespace("Test");
|
|
24196
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24197
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24198
|
-
});
|
|
24199
|
-
it("zero initial, register one", async () => {
|
|
24200
|
-
await itwinLocalization.initialize([]);
|
|
24201
|
-
await itwinLocalization.registerNamespace("test1");
|
|
24202
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24203
|
-
});
|
|
24204
|
-
it("zero initial, register two", async () => {
|
|
24205
|
-
await itwinLocalization.initialize([]);
|
|
24206
|
-
await itwinLocalization.registerNamespace("test1");
|
|
24207
|
-
await itwinLocalization.registerNamespace("test2");
|
|
24208
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24209
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
24210
|
-
});
|
|
24211
|
-
it("one initial, register one", async () => {
|
|
24212
|
-
await itwinLocalization.initialize(["initial1"]);
|
|
24213
|
-
await itwinLocalization.registerNamespace("test1");
|
|
24214
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24215
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24216
|
-
});
|
|
24217
|
-
it("one initial, register two", async () => {
|
|
24218
|
-
await itwinLocalization.initialize(["initial1"]);
|
|
24219
|
-
await itwinLocalization.registerNamespace("test1");
|
|
24220
|
-
await itwinLocalization.registerNamespace("test2");
|
|
24221
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24222
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
24223
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24224
|
-
});
|
|
24225
|
-
it("two initial, register one", async () => {
|
|
24226
|
-
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
24227
|
-
await itwinLocalization.registerNamespace("test1");
|
|
24228
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24229
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24230
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
24231
|
-
});
|
|
24232
|
-
it("two initial, register two", async () => {
|
|
24233
|
-
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
24234
|
-
await itwinLocalization.registerNamespace("test1");
|
|
24235
|
-
await itwinLocalization.registerNamespace("test2");
|
|
24236
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24237
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24238
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
24239
|
-
});
|
|
24240
|
-
it("register duplicate namespaces", async () => {
|
|
24241
|
-
await itwinLocalization.initialize([]);
|
|
24242
|
-
await itwinLocalization.registerNamespace("Test");
|
|
24243
|
-
await itwinLocalization.registerNamespace("Test");
|
|
24244
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24245
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24246
|
-
});
|
|
24247
|
-
it("register duplicate namespace of initial namespace doesn't break anything", async () => {
|
|
24248
|
-
await itwinLocalization.initialize(["Test"]);
|
|
24249
|
-
await itwinLocalization.registerNamespace("Test");
|
|
24250
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24251
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24252
|
-
});
|
|
24253
|
-
});
|
|
24254
|
-
// unregisterNamespace() isn't used and basically does nothing
|
|
24255
|
-
// describe("#unregisterNamespace", () => {
|
|
24256
|
-
// });
|
|
24257
|
-
});
|
|
23402
|
+
|
|
23403
|
+
/*---------------------------------------------------------------------------------------------
|
|
23404
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
23405
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
23406
|
+
*--------------------------------------------------------------------------------------------*/
|
|
23407
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
23408
|
+
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.3.7/node_modules/chai/index.js");
|
|
23409
|
+
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
23410
|
+
describe("ITwinLocalization", () => {
|
|
23411
|
+
let localization;
|
|
23412
|
+
let germanLocalization;
|
|
23413
|
+
describe("#constructor", () => {
|
|
23414
|
+
let itwinLocalization;
|
|
23415
|
+
it("set default namespace", async () => {
|
|
23416
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
23417
|
+
await itwinLocalization.initialize([]);
|
|
23418
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23419
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23420
|
+
});
|
|
23421
|
+
it("set default language as english", async () => {
|
|
23422
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "en" } });
|
|
23423
|
+
await itwinLocalization.initialize([]);
|
|
23424
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "en");
|
|
23425
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23426
|
+
});
|
|
23427
|
+
it("set default language as NOT english", async () => {
|
|
23428
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "de" } });
|
|
23429
|
+
await itwinLocalization.initialize([]);
|
|
23430
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "de");
|
|
23431
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
23432
|
+
});
|
|
23433
|
+
it("set fallback language as NOT english", async () => {
|
|
23434
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", fallbackLng: "de" } });
|
|
23435
|
+
await itwinLocalization.initialize([]);
|
|
23436
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.fallbackLng, "de");
|
|
23437
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("OnlyGerman"), "Hallo");
|
|
23438
|
+
});
|
|
23439
|
+
});
|
|
23440
|
+
describe("#initialize", () => {
|
|
23441
|
+
let itwinLocalization;
|
|
23442
|
+
it("cannot fetch from unregistered namespaces", async () => {
|
|
23443
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23444
|
+
await localization.initialize([]);
|
|
23445
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "FirstTrivial");
|
|
23446
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "FirstTrivial");
|
|
23447
|
+
});
|
|
23448
|
+
describe("with no default namespace predefined", () => {
|
|
23449
|
+
before(() => {
|
|
23450
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
23451
|
+
});
|
|
23452
|
+
it("no default namespace set when initialized with empty array", async () => {
|
|
23453
|
+
await itwinLocalization.initialize([]);
|
|
23454
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, undefined);
|
|
23455
|
+
});
|
|
23456
|
+
it("initialize with single namespace", async () => {
|
|
23457
|
+
var _a;
|
|
23458
|
+
await itwinLocalization.initialize(["Test"]);
|
|
23459
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Test");
|
|
23460
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Test"));
|
|
23461
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
23462
|
+
});
|
|
23463
|
+
it("initialize with two namespaces recognizes both namespaces", async () => {
|
|
23464
|
+
var _a, _b;
|
|
23465
|
+
await itwinLocalization.initialize(["Default", "Test"]);
|
|
23466
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23467
|
+
chai_1.assert.isTrue((_b = itwinLocalization.i18next.options.ns) === null || _b === void 0 ? void 0 : _b.includes("Test"));
|
|
23468
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
23469
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
23470
|
+
});
|
|
23471
|
+
it("initialize with two namespaces sets first as default", async () => {
|
|
23472
|
+
await itwinLocalization.initialize(["Default", "Test"]);
|
|
23473
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23474
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23475
|
+
});
|
|
23476
|
+
it("initialize with duplicate namespace values does not break anything", async () => {
|
|
23477
|
+
var _a;
|
|
23478
|
+
await itwinLocalization.initialize(["Default", "Default"]);
|
|
23479
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23480
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23481
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23482
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
23483
|
+
});
|
|
23484
|
+
});
|
|
23485
|
+
describe("with default namespace", () => {
|
|
23486
|
+
before(() => {
|
|
23487
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
23488
|
+
});
|
|
23489
|
+
it("default namespace set when initialized with empty array", async () => {
|
|
23490
|
+
await itwinLocalization.initialize([]);
|
|
23491
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23492
|
+
});
|
|
23493
|
+
it("default namespace not overridden by one namespace", async () => {
|
|
23494
|
+
await itwinLocalization.initialize(["Test"]);
|
|
23495
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23496
|
+
});
|
|
23497
|
+
it("default namespace not overridden by two namespaces", async () => {
|
|
23498
|
+
await itwinLocalization.initialize(["NotExist", "Test"]);
|
|
23499
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23500
|
+
});
|
|
23501
|
+
it("duplicate namespace value does not break default namespace", async () => {
|
|
23502
|
+
await itwinLocalization.initialize(["Default"]);
|
|
23503
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
23504
|
+
});
|
|
23505
|
+
it("default namespace is in list of all namespaces initalized with empty array", async () => {
|
|
23506
|
+
var _a;
|
|
23507
|
+
await itwinLocalization.initialize([]);
|
|
23508
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23509
|
+
});
|
|
23510
|
+
it("default namespace is in list of all namespaces", async () => {
|
|
23511
|
+
var _a;
|
|
23512
|
+
await itwinLocalization.initialize(["Test"]);
|
|
23513
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
23514
|
+
});
|
|
23515
|
+
});
|
|
23516
|
+
});
|
|
23517
|
+
describe("#getLocalizedKeys", () => {
|
|
23518
|
+
before(async () => {
|
|
23519
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23520
|
+
await localization.initialize(["Default", "Test"]);
|
|
23521
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
23522
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
23523
|
+
});
|
|
23524
|
+
it("no substitution", () => {
|
|
23525
|
+
chai_1.assert.equal(localization.getLocalizedKeys("MyString"), "MyString");
|
|
23526
|
+
});
|
|
23527
|
+
describe("Default Namespace", () => {
|
|
23528
|
+
it("first level string", () => {
|
|
23529
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default)");
|
|
23530
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default german)");
|
|
23531
|
+
});
|
|
23532
|
+
it("second level string", () => {
|
|
23533
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
23534
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
23535
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default german)");
|
|
23536
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default german)");
|
|
23537
|
+
});
|
|
23538
|
+
it("first level string with keys", () => {
|
|
23539
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default)");
|
|
23540
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
23541
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default german)");
|
|
23542
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default german)");
|
|
23543
|
+
});
|
|
23544
|
+
it("second level string with keys", () => {
|
|
23545
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
23546
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
23547
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default german)");
|
|
23548
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default german)");
|
|
23549
|
+
});
|
|
23550
|
+
it("first level missing key doesn't find a value", () => {
|
|
23551
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
23552
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
23553
|
+
});
|
|
23554
|
+
it("second level missing key doesn't find a value", () => {
|
|
23555
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
23556
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
23557
|
+
});
|
|
23558
|
+
});
|
|
23559
|
+
describe("Given Namespace", () => {
|
|
23560
|
+
it("first level string", () => {
|
|
23561
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:FirstTrivial}"), "hi First level string (default)");
|
|
23562
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:FirstTrivial}"), "hi First level string (test)");
|
|
23563
|
+
});
|
|
23564
|
+
it("second level string", () => {
|
|
23565
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
23566
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
23567
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondTrivial.Test1}"), "Second level string 1 (test)");
|
|
23568
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:SecondTrivial.Test2}"), "bye Second level string 2 (test)");
|
|
23569
|
+
});
|
|
23570
|
+
it("first level string with keys", () => {
|
|
23571
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:FirstSubstitution1}"), "First level {{str}} (default)");
|
|
23572
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
23573
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:FirstSubstitution1}"), "First level {{str}} (test)");
|
|
23574
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (test)");
|
|
23575
|
+
});
|
|
23576
|
+
it("second level string with keys", () => {
|
|
23577
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
23578
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
23579
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (test)");
|
|
23580
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (test)");
|
|
23581
|
+
});
|
|
23582
|
+
it("first level missing key doesn't find a value", () => {
|
|
23583
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{Default:MissingKeyString}"), "no MissingKeyString");
|
|
23584
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{Test:MissingKeyString}"), "no MissingKeyString");
|
|
23585
|
+
});
|
|
23586
|
+
it("second level missing key doesn't find a value", () => {
|
|
23587
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
23588
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
23589
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
23590
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
23591
|
+
});
|
|
23592
|
+
});
|
|
23593
|
+
describe("Nonexisting Namespace", () => {
|
|
23594
|
+
it("first level fails", () => {
|
|
23595
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:FirstTrivial}"), "FirstTrivial");
|
|
23596
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:MissingKeyString}"), "MissingKeyString");
|
|
23597
|
+
});
|
|
23598
|
+
it("second level fails", () => {
|
|
23599
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:SecondTrivial.Test1}"), "SecondTrivial.Test1");
|
|
23600
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:Missing.String}"), "Missing.String");
|
|
23601
|
+
});
|
|
23602
|
+
});
|
|
23603
|
+
});
|
|
23604
|
+
// The goal is not to test i18next's interpolation,
|
|
23605
|
+
// but just to have some simple tests to make sure the
|
|
23606
|
+
// basics work through the ITwinLocalization class.
|
|
23607
|
+
// For interpolation options, see: https://www.i18next.com/translation-function/interpolation
|
|
23608
|
+
describe("#getLocalizedString", () => {
|
|
23609
|
+
before(async () => {
|
|
23610
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23611
|
+
await localization.initialize(["Default", "Test"]);
|
|
23612
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
23613
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
23614
|
+
});
|
|
23615
|
+
describe("Default Namespace", () => {
|
|
23616
|
+
it("first level with no substitution", () => {
|
|
23617
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
23618
|
+
});
|
|
23619
|
+
it("first level with no substitution with fallback keys", () => {
|
|
23620
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
23621
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default)");
|
|
23622
|
+
});
|
|
23623
|
+
it("more than two fallback keys succeeds", () => {
|
|
23624
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist1", "NotExist2"]), "First level string (default)");
|
|
23625
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "FirstTrivial", "NotExist2"]), "First level string (default)");
|
|
23626
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "NotExist2", "FirstTrivial"]), "First level string (default)");
|
|
23627
|
+
chai_1.assert.equal(localization.getLocalizedString(["1", "2", "3", "4", "5", "FirstTrivial"]), "First level string (default)");
|
|
23628
|
+
});
|
|
23629
|
+
it("second level with no substitution", () => {
|
|
23630
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
23631
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
23632
|
+
});
|
|
23633
|
+
it("second level with no substitution with fallback keys", () => {
|
|
23634
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
23635
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default)");
|
|
23636
|
+
});
|
|
23637
|
+
it("first level with substitution", () => {
|
|
23638
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23639
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23640
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23641
|
+
});
|
|
23642
|
+
it("first level with substitution with fallback keys", () => {
|
|
23643
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23644
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23645
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23646
|
+
});
|
|
23647
|
+
it("second level with substitution", () => {
|
|
23648
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23649
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23650
|
+
});
|
|
23651
|
+
it("second level with substitution with fallback keys", () => {
|
|
23652
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23653
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23654
|
+
});
|
|
23655
|
+
it("first level missing key doesn't find a value", () => {
|
|
23656
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
23657
|
+
});
|
|
23658
|
+
it("first level missing all keys doesn't find a value", () => {
|
|
23659
|
+
chai_1.assert.equal(localization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
23660
|
+
});
|
|
23661
|
+
it("second level missing key doesn't find a value", () => {
|
|
23662
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23663
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "MissingKeyObject.MissingString"]), "MissingKeyObject.MissingString");
|
|
23664
|
+
});
|
|
23665
|
+
it("read from en-US fallback", () => {
|
|
23666
|
+
chai_1.assert.equal(localization.getLocalizedString("OnlyEnglishUS"), "HelloUS");
|
|
23667
|
+
});
|
|
23668
|
+
});
|
|
23669
|
+
describe("Default Namespace (German)", () => {
|
|
23670
|
+
it("first level with no substitution", () => {
|
|
23671
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
23672
|
+
});
|
|
23673
|
+
it("first level with no substitution with fallback keys", () => {
|
|
23674
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default german)");
|
|
23675
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default german)");
|
|
23676
|
+
});
|
|
23677
|
+
it("second level with no substitution", () => {
|
|
23678
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
23679
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
23680
|
+
});
|
|
23681
|
+
it("second level with no substitution with fallback keys", () => {
|
|
23682
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default german)");
|
|
23683
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default german)");
|
|
23684
|
+
});
|
|
23685
|
+
it("first level with substitution", () => {
|
|
23686
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23687
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23688
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23689
|
+
});
|
|
23690
|
+
it("first level with substitution with fallback keys", () => {
|
|
23691
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23692
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23693
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23694
|
+
});
|
|
23695
|
+
it("second level with substitution", () => {
|
|
23696
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23697
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23698
|
+
});
|
|
23699
|
+
it("second level with substitution with fallback keys", () => {
|
|
23700
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23701
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23702
|
+
});
|
|
23703
|
+
it("first level missing key doesn't find a value", () => {
|
|
23704
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
23705
|
+
});
|
|
23706
|
+
it("first level missing all keys doesn't find a value", () => {
|
|
23707
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
23708
|
+
});
|
|
23709
|
+
it("second level missing key doesn't find a value", () => {
|
|
23710
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23711
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
23712
|
+
});
|
|
23713
|
+
});
|
|
23714
|
+
describe("Given Namespace", () => {
|
|
23715
|
+
it("first level with no substitution", () => {
|
|
23716
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
23717
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
23718
|
+
});
|
|
23719
|
+
it("first level with no substitution with fallback keys", () => {
|
|
23720
|
+
chai_1.assert.equal(localization.getLocalizedString(["Default:FirstTrivial", "Not:NotExist"]), "First level string (default)");
|
|
23721
|
+
chai_1.assert.equal(localization.getLocalizedString(["Default:NotExist", "Test:FirstTrivial"]), "First level string (test)");
|
|
23722
|
+
});
|
|
23723
|
+
it("second level with no substitution", () => {
|
|
23724
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
23725
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
23726
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
23727
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
23728
|
+
});
|
|
23729
|
+
it("second level with no substitution with fallback keys", () => {
|
|
23730
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
23731
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
23732
|
+
});
|
|
23733
|
+
it("first level with substitution", () => {
|
|
23734
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23735
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23736
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23737
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
23738
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23739
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
23740
|
+
});
|
|
23741
|
+
it("first level with substitution with fallback keys", () => {
|
|
23742
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23743
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:FirstSubstitution1", "Default:NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23744
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23745
|
+
});
|
|
23746
|
+
it("second level with substitution", () => {
|
|
23747
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23748
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23749
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
23750
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23751
|
+
});
|
|
23752
|
+
it("second level with substitution with fallback keys", () => {
|
|
23753
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23754
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondSubstitution.Test2", "Default:NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23755
|
+
});
|
|
23756
|
+
it("first level missing key doesn't find a value", () => {
|
|
23757
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
23758
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
23759
|
+
});
|
|
23760
|
+
it("second level missing key doesn't find a value", () => {
|
|
23761
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23762
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
23763
|
+
});
|
|
23764
|
+
it("read from en-US fallback", () => {
|
|
23765
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:OnlyEnglishUS"), "HelloUS");
|
|
23766
|
+
});
|
|
23767
|
+
});
|
|
23768
|
+
describe("Given Namespace (German)", () => {
|
|
23769
|
+
it("first level with no substitution", () => {
|
|
23770
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default german)");
|
|
23771
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (german)");
|
|
23772
|
+
});
|
|
23773
|
+
it("second level with no substitution", () => {
|
|
23774
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
23775
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
23776
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (german)");
|
|
23777
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (german)");
|
|
23778
|
+
});
|
|
23779
|
+
it("first level with substitution", () => {
|
|
23780
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23781
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23782
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23783
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
23784
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
23785
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
23786
|
+
});
|
|
23787
|
+
it("second level with substitution", () => {
|
|
23788
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23789
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23790
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
23791
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
23792
|
+
});
|
|
23793
|
+
it("first level missing key doesn't find a value", () => {
|
|
23794
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
23795
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
23796
|
+
});
|
|
23797
|
+
it("second level missing key doesn't find a value", () => {
|
|
23798
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
23799
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
23800
|
+
});
|
|
23801
|
+
});
|
|
23802
|
+
describe("Nonexisting Namespace", () => {
|
|
23803
|
+
it("first level fails", () => {
|
|
23804
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
|
|
23805
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
|
|
23806
|
+
});
|
|
23807
|
+
it("second level fails", () => {
|
|
23808
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
23809
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
|
|
23810
|
+
});
|
|
23811
|
+
it("fallback key fails", () => {
|
|
23812
|
+
chai_1.assert.equal(localization.getLocalizedString(["Nonexisting:FirstTrivial", "NotExist"]), "NotExist");
|
|
23813
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Nonexisting:Missing.String"]), "Missing.String");
|
|
23814
|
+
});
|
|
23815
|
+
});
|
|
23816
|
+
// Test a few options to make sure they get passed through correctly
|
|
23817
|
+
describe("With Options", () => {
|
|
23818
|
+
it("returnDetails throws error", () => {
|
|
23819
|
+
chai_1.assert.throws(() => {
|
|
23820
|
+
localization.getLocalizedString("X", { returnDetails: true });
|
|
23821
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23822
|
+
});
|
|
23823
|
+
it("returnObjects throws error", () => {
|
|
23824
|
+
chai_1.assert.throws(() => {
|
|
23825
|
+
localization.getLocalizedString("X", { returnObjects: true });
|
|
23826
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23827
|
+
});
|
|
23828
|
+
it("returnDetails and returnObjects throws error", () => {
|
|
23829
|
+
chai_1.assert.throws(() => {
|
|
23830
|
+
localization.getLocalizedString("X", { returnDetails: true, returnObjects: true });
|
|
23831
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23832
|
+
});
|
|
23833
|
+
it("default value", () => {
|
|
23834
|
+
chai_1.assert.equal(localization.getLocalizedString("Missing", { defaultValue: "default" }), "default");
|
|
23835
|
+
});
|
|
23836
|
+
it("override fallback language", () => {
|
|
23837
|
+
// Doesn't fallback to English
|
|
23838
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { fallbackLng: "de" }), "OnlyEnglish");
|
|
23839
|
+
});
|
|
23840
|
+
it("set namespace", () => {
|
|
23841
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
23842
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (test)");
|
|
23843
|
+
});
|
|
23844
|
+
});
|
|
23845
|
+
});
|
|
23846
|
+
describe("#getLocalizedString with namespace passed in as an option", () => {
|
|
23847
|
+
before(async () => {
|
|
23848
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
23849
|
+
await localization.initialize(["Default", "Test"]);
|
|
23850
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
23851
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
23852
|
+
});
|
|
23853
|
+
describe("Keys Without Namespaces", () => {
|
|
23854
|
+
it("first level with no substitution", () => {
|
|
23855
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
23856
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
23857
|
+
});
|
|
23858
|
+
it("first level with no substitution with fallback keys", () => {
|
|
23859
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Default" }), "First level string (default)");
|
|
23860
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
23861
|
+
});
|
|
23862
|
+
it("second level with no substitution", () => {
|
|
23863
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default)");
|
|
23864
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default)");
|
|
23865
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
23866
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (test)");
|
|
23867
|
+
});
|
|
23868
|
+
it("second level with no substitution with fallback keys", () => {
|
|
23869
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"], { ns: "Default" }), "Second level string 1 (default)");
|
|
23870
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"], { ns: "Test" }), "Second level string 2 (test)");
|
|
23871
|
+
});
|
|
23872
|
+
it("first level with substitution", () => {
|
|
23873
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23874
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
23875
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
23876
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
23877
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23878
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
23879
|
+
});
|
|
23880
|
+
it("first level with substitution with fallback keys", () => {
|
|
23881
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
23882
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
23883
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
23884
|
+
});
|
|
23885
|
+
it("second level with substitution", () => {
|
|
23886
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23887
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
23888
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
23889
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23890
|
+
});
|
|
23891
|
+
it("second level with substitution with fallback keys", () => {
|
|
23892
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
23893
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
23894
|
+
});
|
|
23895
|
+
it("first level missing key doesn't find a value", () => {
|
|
23896
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
23897
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
23898
|
+
});
|
|
23899
|
+
it("second level missing key doesn't find a value", () => {
|
|
23900
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
23901
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
23902
|
+
});
|
|
23903
|
+
});
|
|
23904
|
+
describe("Keys Without Namespaces (German)", () => {
|
|
23905
|
+
it("first level with no substitution", () => {
|
|
23906
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default german)");
|
|
23907
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (german)");
|
|
23908
|
+
});
|
|
23909
|
+
it("second level with no substitution", () => {
|
|
23910
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default german)");
|
|
23911
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default german)");
|
|
23912
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (german)");
|
|
23913
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (german)");
|
|
23914
|
+
});
|
|
23915
|
+
it("first level with substitution", () => {
|
|
23916
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
23917
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
23918
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
23919
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
23920
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
23921
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
23922
|
+
});
|
|
23923
|
+
it("second level with substitution", () => {
|
|
23924
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
23925
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
23926
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
23927
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
23928
|
+
});
|
|
23929
|
+
it("first level missing key doesn't find a value", () => {
|
|
23930
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
23931
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
23932
|
+
});
|
|
23933
|
+
it("second level missing key doesn't find a value", () => {
|
|
23934
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
23935
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
23936
|
+
});
|
|
23937
|
+
});
|
|
23938
|
+
describe("Keys With Namespaces", () => {
|
|
23939
|
+
it("key with same namespace works", () => {
|
|
23940
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
23941
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
23942
|
+
});
|
|
23943
|
+
it("key with different namespace overrides given namespace", () => {
|
|
23944
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Default" }), "First level string (test)");
|
|
23945
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
23946
|
+
});
|
|
23947
|
+
it("key with same namespace works with fallback keys", () => {
|
|
23948
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Default" }), "First level string (default)");
|
|
23949
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
23950
|
+
});
|
|
23951
|
+
it("key with different namespace overrides given namespace with fallback keys", () => {
|
|
23952
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Default" }), "First level string (test)");
|
|
23953
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Test" }), "First level string (default)");
|
|
23954
|
+
});
|
|
23955
|
+
it("missing key does not find a value", () => {
|
|
23956
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
23957
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["Missing1", "MissingKeyObject.MissingString"], { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
23958
|
+
});
|
|
23959
|
+
});
|
|
23960
|
+
describe("Nonexisting Namespace", () => {
|
|
23961
|
+
it("first level fails", () => {
|
|
23962
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Nonexisting" }), "FirstTrivial");
|
|
23963
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Nonexisting" }), "MissingKeyString");
|
|
23964
|
+
});
|
|
23965
|
+
it("second level fails", () => {
|
|
23966
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Nonexisting" }), "SecondTrivial.Test1");
|
|
23967
|
+
chai_1.assert.equal(localization.getLocalizedString("Missing.String", { ns: "Nonexisting" }), "Missing.String");
|
|
23968
|
+
});
|
|
23969
|
+
it("empty string namespace falls back to default namespace", () => {
|
|
23970
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "" }), "First level string (default)");
|
|
23971
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "" }), "Second level string 1 (default)");
|
|
23972
|
+
});
|
|
23973
|
+
it("fallback key fails", () => {
|
|
23974
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Nonexisting" }), "NotExist");
|
|
23975
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Missing.String"], { ns: "Nonexisting" }), "Missing.String");
|
|
23976
|
+
});
|
|
23977
|
+
it("use key with valid namespace instead", () => {
|
|
23978
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Nonexisting" }), "First level string (default)");
|
|
23979
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Nonexisting" }), "First level string (test)");
|
|
23980
|
+
});
|
|
23981
|
+
it("providing key with invalid namespace fails", () => {
|
|
23982
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting2:FirstTrivial", { ns: "Nonexisting1" }), "FirstTrivial");
|
|
23983
|
+
});
|
|
23984
|
+
});
|
|
23985
|
+
// Test a few options to make sure they get passed through correctly
|
|
23986
|
+
describe("With Options", () => {
|
|
23987
|
+
it("returnDetails throws error", () => {
|
|
23988
|
+
chai_1.assert.throws(() => {
|
|
23989
|
+
localization.getLocalizedString("X", { ns: "Default", returnDetails: true });
|
|
23990
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23991
|
+
});
|
|
23992
|
+
it("returnObjects throws error", () => {
|
|
23993
|
+
chai_1.assert.throws(() => {
|
|
23994
|
+
localization.getLocalizedString("X", { ns: "Default", returnObjects: true });
|
|
23995
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
23996
|
+
});
|
|
23997
|
+
it("returnDetails and returnObjects throws error", () => {
|
|
23998
|
+
chai_1.assert.throws(() => {
|
|
23999
|
+
localization.getLocalizedString("X", { ns: "Default", returnDetails: true, returnObjects: true });
|
|
24000
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24001
|
+
});
|
|
24002
|
+
it("default value", () => {
|
|
24003
|
+
chai_1.assert.equal(localization.getLocalizedString("Missing", { ns: "Default", defaultValue: "default" }), "default");
|
|
24004
|
+
});
|
|
24005
|
+
it("override fallback language", () => {
|
|
24006
|
+
// Doesn't fallback to English
|
|
24007
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { ns: "Default", fallbackLng: "de" }), "OnlyEnglish");
|
|
24008
|
+
});
|
|
24009
|
+
});
|
|
24010
|
+
});
|
|
24011
|
+
describe("#getEnglishString", () => {
|
|
24012
|
+
before(async () => {
|
|
24013
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
24014
|
+
await localization.initialize(["Default", "Test"]);
|
|
24015
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
24016
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
24017
|
+
});
|
|
24018
|
+
describe("Given Namespace", () => {
|
|
24019
|
+
it("first level with no substitution", () => {
|
|
24020
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
24021
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
24022
|
+
});
|
|
24023
|
+
it("first level with no substitution with fallback keys", () => {
|
|
24024
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
24025
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
24026
|
+
});
|
|
24027
|
+
it("second level with no substitution", () => {
|
|
24028
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
24029
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
24030
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
24031
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
24032
|
+
});
|
|
24033
|
+
it("second level with no substitution with fallback keys", () => {
|
|
24034
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
24035
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
24036
|
+
});
|
|
24037
|
+
it("first level with substitution", () => {
|
|
24038
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24039
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
24040
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
24041
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
24042
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24043
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24044
|
+
});
|
|
24045
|
+
it("first level with substitution with fallback keys", () => {
|
|
24046
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24047
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24048
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24049
|
+
});
|
|
24050
|
+
it("second level with substitution", () => {
|
|
24051
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24052
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
24053
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
24054
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24055
|
+
});
|
|
24056
|
+
it("second level with substitution with fallback keys", () => {
|
|
24057
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24058
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24059
|
+
});
|
|
24060
|
+
it("first level missing key doesn't find a value", () => {
|
|
24061
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
24062
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
24063
|
+
});
|
|
24064
|
+
it("second level missing key doesn't find a value", () => {
|
|
24065
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
24066
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
24067
|
+
});
|
|
24068
|
+
});
|
|
24069
|
+
describe("Given Namespace with German default language returns English strings", () => {
|
|
24070
|
+
it("first level with no substitution", () => {
|
|
24071
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
24072
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
24073
|
+
});
|
|
24074
|
+
it("first level with no substitution with fallback keys", () => {
|
|
24075
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
24076
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
24077
|
+
});
|
|
24078
|
+
it("second level with no substitution", () => {
|
|
24079
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
24080
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
24081
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
24082
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
24083
|
+
});
|
|
24084
|
+
it("second level with no substitution with fallback keys", () => {
|
|
24085
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
24086
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
24087
|
+
});
|
|
24088
|
+
it("first level with substitution", () => {
|
|
24089
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24090
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
24091
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
24092
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
24093
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24094
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24095
|
+
});
|
|
24096
|
+
it("first level with substitution with fallback keys", () => {
|
|
24097
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
24098
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
24099
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
24100
|
+
});
|
|
24101
|
+
it("second level with substitution", () => {
|
|
24102
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24103
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
24104
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
24105
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24106
|
+
});
|
|
24107
|
+
it("second level with substitution with fallback keys", () => {
|
|
24108
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
24109
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
24110
|
+
});
|
|
24111
|
+
it("first level missing key doesn't find a value", () => {
|
|
24112
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
24113
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
24114
|
+
});
|
|
24115
|
+
it("second level missing key doesn't find a value", () => {
|
|
24116
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
24117
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
24118
|
+
});
|
|
24119
|
+
});
|
|
24120
|
+
describe("Nonexisting Namespace", () => {
|
|
24121
|
+
it("first level fails", () => {
|
|
24122
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "FirstTrivial"), "FirstTrivial");
|
|
24123
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "MissingKeyString"), "MissingKeyString");
|
|
24124
|
+
});
|
|
24125
|
+
it("second level fails", () => {
|
|
24126
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
24127
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "Missing.String"), "Missing.String");
|
|
24128
|
+
});
|
|
24129
|
+
it("empty string namespace is treated as default namespace", () => {
|
|
24130
|
+
chai_1.assert.equal(localization.getEnglishString("", "FirstTrivial"), "First level string (default)");
|
|
24131
|
+
chai_1.assert.equal(localization.getEnglishString("", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
24132
|
+
});
|
|
24133
|
+
});
|
|
24134
|
+
// Test a few options to make sure they get passed through correctly
|
|
24135
|
+
describe("With Options", () => {
|
|
24136
|
+
it("returnDetails throws error", () => {
|
|
24137
|
+
chai_1.assert.throws(() => {
|
|
24138
|
+
localization.getEnglishString("Default", "X", { returnDetails: true });
|
|
24139
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24140
|
+
});
|
|
24141
|
+
it("returnObjects throws error", () => {
|
|
24142
|
+
chai_1.assert.throws(() => {
|
|
24143
|
+
localization.getEnglishString("Default", "X", { returnObjects: true });
|
|
24144
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24145
|
+
});
|
|
24146
|
+
it("returnDetails and returnObjects throws error", () => {
|
|
24147
|
+
chai_1.assert.throws(() => {
|
|
24148
|
+
localization.getEnglishString("Default", "X", { returnDetails: true, returnObjects: true });
|
|
24149
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
24150
|
+
});
|
|
24151
|
+
it("default value", () => {
|
|
24152
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "Missing", { defaultValue: "default" }), "default");
|
|
24153
|
+
});
|
|
24154
|
+
it("english takes priority over fallback language", () => {
|
|
24155
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "OnlyEnglish", { fallbackLng: "de" }), "Hello");
|
|
24156
|
+
});
|
|
24157
|
+
// White box test
|
|
24158
|
+
it("given namespace overrides namespace translation option", () => {
|
|
24159
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
24160
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
|
|
24161
|
+
});
|
|
24162
|
+
});
|
|
24163
|
+
});
|
|
24164
|
+
// Returned promises never have anything of substance, being only empty or resolving to null...
|
|
24165
|
+
// describe("#getNamespacePromise", () => {
|
|
24166
|
+
// });
|
|
24167
|
+
describe("#getLanguageList", () => {
|
|
24168
|
+
let languages;
|
|
24169
|
+
it("english language list includes en and en-US", async () => {
|
|
24170
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
24171
|
+
await localization.initialize([]);
|
|
24172
|
+
languages = localization.getLanguageList();
|
|
24173
|
+
chai_1.assert.isTrue(languages.includes("en-US"));
|
|
24174
|
+
chai_1.assert.isTrue(languages.includes("en"));
|
|
24175
|
+
});
|
|
24176
|
+
it("when non-english language is set as default, that language and english are included in langauge list", async () => {
|
|
24177
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
24178
|
+
await germanLocalization.initialize([]);
|
|
24179
|
+
languages = germanLocalization.getLanguageList();
|
|
24180
|
+
chai_1.assert.isTrue(languages.includes("en"));
|
|
24181
|
+
chai_1.assert.isTrue(languages.includes("de"));
|
|
24182
|
+
});
|
|
24183
|
+
});
|
|
24184
|
+
describe("#changeLanguage", () => {
|
|
24185
|
+
it("change from english to another language", async () => {
|
|
24186
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
24187
|
+
await localization.initialize(["Default"]);
|
|
24188
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
24189
|
+
await localization.changeLanguage("de");
|
|
24190
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
24191
|
+
});
|
|
24192
|
+
it("change from another language to english", async () => {
|
|
24193
|
+
localization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
24194
|
+
await localization.initialize(["Default"]);
|
|
24195
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
24196
|
+
await localization.changeLanguage("en");
|
|
24197
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
24198
|
+
});
|
|
24199
|
+
});
|
|
24200
|
+
describe("#registerNamespace", () => {
|
|
24201
|
+
let itwinLocalization;
|
|
24202
|
+
beforeEach(async () => {
|
|
24203
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
24204
|
+
});
|
|
24205
|
+
it("can read from namespace after it is registered", async () => {
|
|
24206
|
+
await itwinLocalization.initialize([]);
|
|
24207
|
+
await itwinLocalization.registerNamespace("Test");
|
|
24208
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24209
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24210
|
+
});
|
|
24211
|
+
it("zero initial, register one", async () => {
|
|
24212
|
+
await itwinLocalization.initialize([]);
|
|
24213
|
+
await itwinLocalization.registerNamespace("test1");
|
|
24214
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24215
|
+
});
|
|
24216
|
+
it("zero initial, register two", async () => {
|
|
24217
|
+
await itwinLocalization.initialize([]);
|
|
24218
|
+
await itwinLocalization.registerNamespace("test1");
|
|
24219
|
+
await itwinLocalization.registerNamespace("test2");
|
|
24220
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24221
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
24222
|
+
});
|
|
24223
|
+
it("one initial, register one", async () => {
|
|
24224
|
+
await itwinLocalization.initialize(["initial1"]);
|
|
24225
|
+
await itwinLocalization.registerNamespace("test1");
|
|
24226
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24227
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24228
|
+
});
|
|
24229
|
+
it("one initial, register two", async () => {
|
|
24230
|
+
await itwinLocalization.initialize(["initial1"]);
|
|
24231
|
+
await itwinLocalization.registerNamespace("test1");
|
|
24232
|
+
await itwinLocalization.registerNamespace("test2");
|
|
24233
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24234
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
24235
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24236
|
+
});
|
|
24237
|
+
it("two initial, register one", async () => {
|
|
24238
|
+
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
24239
|
+
await itwinLocalization.registerNamespace("test1");
|
|
24240
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24241
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24242
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
24243
|
+
});
|
|
24244
|
+
it("two initial, register two", async () => {
|
|
24245
|
+
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
24246
|
+
await itwinLocalization.registerNamespace("test1");
|
|
24247
|
+
await itwinLocalization.registerNamespace("test2");
|
|
24248
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
24249
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
24250
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
24251
|
+
});
|
|
24252
|
+
it("register duplicate namespaces", async () => {
|
|
24253
|
+
await itwinLocalization.initialize([]);
|
|
24254
|
+
await itwinLocalization.registerNamespace("Test");
|
|
24255
|
+
await itwinLocalization.registerNamespace("Test");
|
|
24256
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24257
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24258
|
+
});
|
|
24259
|
+
it("register duplicate namespace of initial namespace doesn't break anything", async () => {
|
|
24260
|
+
await itwinLocalization.initialize(["Test"]);
|
|
24261
|
+
await itwinLocalization.registerNamespace("Test");
|
|
24262
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
24263
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
24264
|
+
});
|
|
24265
|
+
});
|
|
24266
|
+
// unregisterNamespace() isn't used and basically does nothing
|
|
24267
|
+
// describe("#unregisterNamespace", () => {
|
|
24268
|
+
// });
|
|
24269
|
+
});
|
|
24258
24270
|
|
|
24259
24271
|
})();
|
|
24260
24272
|
|