@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
|
@@ -10,20 +10,20 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
/*---------------------------------------------------------------------------------------------
|
|
14
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
15
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
13
|
+
/*---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
15
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
16
16
|
*--------------------------------------------------------------------------------------------*/
|
|
17
|
-
/** @packageDocumentation
|
|
18
|
-
* @module Localization
|
|
17
|
+
/** @packageDocumentation
|
|
18
|
+
* @module Localization
|
|
19
19
|
*/
|
|
20
|
-
function
|
|
21
|
-
var path = "D:\\
|
|
22
|
-
var hash = "
|
|
20
|
+
function cov_2l9mmpbx71() {
|
|
21
|
+
var path = "D:\\vsts_a\\4\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js";
|
|
22
|
+
var hash = "cc047c5ea4bef181505d77b051311020fceb8acf";
|
|
23
23
|
var global = new Function("return this")();
|
|
24
24
|
var gcv = "__coverage__";
|
|
25
25
|
var coverageData = {
|
|
26
|
-
path: "D:\\
|
|
26
|
+
path: "D:\\vsts_a\\4\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js",
|
|
27
27
|
statementMap: {
|
|
28
28
|
"0": {
|
|
29
29
|
start: {
|
|
@@ -3086,13 +3086,13 @@ function cov_2jo8rrbgid() {
|
|
|
3086
3086
|
inputSourceMap: {
|
|
3087
3087
|
version: 3,
|
|
3088
3088
|
file: "ITwinLocalization.js",
|
|
3089
|
-
sources: ["D:\\
|
|
3089
|
+
sources: ["D:\\vsts_a\\4\\s\\core\\i18n\\src\\ITwinLocalization.ts"],
|
|
3090
3090
|
names: [],
|
|
3091
3091
|
mappings: ";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,sDAA2E;AAC3E,wGAAmG;AACnG,gFAA+D;AAC/D,sDAA6C;AAG7C,MAAM,mBAAmB,GAAW,CAAC,CAAC,CAAC,8GAA8G;AAcrJ;;;GAGG;AACH,MAAa,iBAAiB;IAO5B,YAAmB,OAA6B;;QAF/B,gBAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;QAG9D,IAAI,CAAC,OAAO,GAAG,iBAAO,CAAC,cAAc,EAAE,CAAC;QAExC,IAAI,CAAC,eAAe,GAAG;YACrB,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,6BAA6B;YAC/D,WAAW,EAAE,IAAI;YACjB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB;SAC/B,CAAC;QAEF,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,CAAC;YAC9C,iBAAiB,EAAE,KAAK;YACxB,MAAM,EAAE,EAAE;YACV,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe;SAC5B,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG;YAClB,aAAa,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;YACpC,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,mBAAmB;YAC/B,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,SAAS,EAAE,IAAI,CAAC,iBAAiB;YACjC,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW;SACxB,CAAC;QAEF,IAAI,CAAC,OAAO;aACT,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,mCAAI,0CAA8B,CAAC;aAC9D,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,8BAAO,CAAC;aACtC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,UAAoB;;QAE1C,mDAAmD;QACnD,MAAM,cAAc,GAAa,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,kBAAkB,GAAgB,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,qBAAqB;QAE1G,MAAM,gBAAgB,GAAuC,MAAA,IAAI,CAAC,YAAY,CAAC,SAAS,mCAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1G,IAAI,gBAAgB;YAClB,kBAAkB,CAAC,GAAG,CAAC,gBAA0B,CAAC,CAAC,CAAC,oDAAoD;QAE1G,MAAM,WAAW,GAAgB;YAC/B,GAAG,IAAI,CAAC,YAAY;YACpB,SAAS,EAAE,gBAAgB;YAC3B,EAAE,EAAE,CAAC,GAAG,kBAAkB,CAAC;SAC5B,CAAC;QAEF,iDAAiD;QACjD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;YACxC,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC;QAE3B,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAA6B,CAAC;QAE/E,KAAK,MAAM,EAAE,IAAI,UAAU;YACzB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAExC,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,gBAAgB,CAAC,IAAY;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,kBAAkB,CAAC,GAAsB,EAAE,OAAsB;QACtE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAA,EAAE;YACpD,MAAM,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC;SACzG;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAE3C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;OAOG;IACI,+BAA+B,CAAC,SAAiB,EAAE,GAAsB,EAAE,OAAsB;QACtG,IAAI,OAAO,GAAsB,EAAE,CAAC;QAEpC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,OAAO,GAAG,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;SACjC;aAAM;YACL,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,MAAc,EAAE,EAAE;gBACnC,OAAO,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACI,gBAAgB,CAAC,SAAiB,EAAE,GAAsB,EAAE,OAAsB;QACvF,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAA,EAAE;YACpD,MAAM,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC;SACzG;QAED,OAAO,GAAG;YACR,GAAG,OAAO;YACV,EAAE,EAAE,SAAS,EAAE,oCAAoC;SACpD,CAAC;QAEF,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC7B,IAAI,OAAO,GAAG,KAAK,QAAQ;YACzB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAElD,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,mBAAmB,CAAC,IAAY;QACrC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,gBAAgB;IACT,eAAe;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IAChC,CAAC;IAED,qDAAqD;IAC9C,KAAK,CAAC,cAAc,CAAC,QAAgB;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAA6B,CAAC;IAC3E,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,iBAAiB,CAAC,IAAY;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,QAAQ,KAAK,SAAS;YACxB,OAAO,QAAQ,CAAC;QAElB,MAAM,cAAc,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnD,mEAAmE;YACnE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;gBACxC,IAAI,CAAC,GAAG;oBACN,OAAO,OAAO,EAAE,CAAC;gBAEnB,qCAAqC;gBACrC,yHAAyH;gBACzH,2GAA2G;gBAC3G,8HAA8H;gBAC9H,8IAA8I;gBAC9I,IAAI,OAAO,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,CAAC,UAAe,EAAE,EAAE,CAAC,IAAI,UAAU,GAAG,CAAC,CAAC;gBAEjF,IAAI;oBACF,KAAK,MAAM,SAAS,IAAI,GAAG,EAAE;wBAC3B,IAAI,OAAO,SAAS,KAAK,QAAQ;4BAC/B,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;qBAC7E;iBACF;gBAAC,OAAO,CAAC,EAAE;oBACV,OAAO,GAAG,EAAE,CAAC;iBACd;gBACD,+DAA+D;gBAC/D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;oBACtB,qBAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,8BAA8B,IAAI,kBAAkB,CAAC,CAAC;gBAEhF,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QAC3C,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,gBAAgB;IACT,mBAAmB,CAAC,IAAY;QACrC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AAnOD,8CAmOC;AAED,MAAM,iBAAiB;IAEd,GAAG,CAAC,IAAc,IAAI,qBAAM,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,IAAI,CAAC,IAAc,IAAI,qBAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,KAAK,CAAC,IAAc,IAAI,qBAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,gBAAgB,CAAC,IAAc;QACrC,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACpC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAC7B,OAAO,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/B;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;;AAXsB,sBAAI,GAAG,QAAQ,CAAC",
|
|
3092
|
-
sourcesContent: ["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Localization\r\n */\r\n\r\nimport i18next, { i18n, InitOptions, Module, TOptionsBase } from \"i18next\";\r\nimport i18nextBrowserLanguageDetector, { DetectorOptions } from \"i18next-browser-languagedetector\";\r\nimport Backend, { BackendOptions } from \"i18next-http-backend\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport type { Localization } from \"@itwin/core-common\";\r\n\r\nconst DEFAULT_MAX_RETRIES: number = 1; // a low number prevents wasted time and potential timeouts when requesting localization files throws an error\r\n\r\n/** Options for ITwinLocalization\r\n * @public\r\n */\r\nexport interface LocalizationOptions {\r\n urlTemplate?: string;\r\n backendPlugin?: Module;\r\n detectorPlugin?: Module;\r\n initOptions?: InitOptions;\r\n backendHttpOptions?: BackendOptions;\r\n detectorOptions?: DetectorOptions;\r\n}\r\n\r\n/** Supplies localizations for iTwin.js\r\n * @note this class uses the [i18next](https://www.i18next.com/) package.\r\n * @public\r\n */\r\nexport class ITwinLocalization implements Localization {\r\n public i18next: i18n;\r\n private readonly _initOptions: InitOptions;\r\n private readonly _backendOptions: BackendOptions;\r\n private readonly _detectionOptions: DetectorOptions;\r\n private readonly _namespaces = new Map<string, Promise<void>>();\r\n\r\n public constructor(options?: LocalizationOptions) {\r\n this.i18next = i18next.createInstance();\r\n\r\n this._backendOptions = {\r\n loadPath: options?.urlTemplate ?? \"locales/{{lng}}/{{ns}}.json\",\r\n crossDomain: true,\r\n ...options?.backendHttpOptions,\r\n };\r\n\r\n this._detectionOptions = {\r\n order: [\"querystring\", \"navigator\", \"htmlTag\"],\r\n lookupQuerystring: \"lng\",\r\n caches: [],\r\n ...options?.detectorOptions,\r\n };\r\n\r\n this._initOptions = {\r\n interpolation: { escapeValue: true },\r\n fallbackLng: \"en\",\r\n maxRetries: DEFAULT_MAX_RETRIES,\r\n backend: this._backendOptions,\r\n detection: this._detectionOptions,\r\n ...options?.initOptions,\r\n };\r\n\r\n this.i18next\r\n .use(options?.detectorPlugin ?? i18nextBrowserLanguageDetector)\r\n .use(options?.backendPlugin ?? Backend)\r\n .use(TranslationLogger);\r\n }\r\n\r\n public async initialize(namespaces: string[]): Promise<void> {\r\n\r\n // Also consider namespaces passed into constructor\r\n const initNamespaces: string[] = [this._initOptions.ns || []].flat();\r\n const combinedNamespaces: Set<string> = new Set([...namespaces, ...initNamespaces]); // without duplicates\r\n\r\n const defaultNamespace: string | false | readonly string[] = this._initOptions.defaultNS ?? namespaces[0];\r\n if (defaultNamespace)\r\n combinedNamespaces.add(defaultNamespace as string); // Make sure default namespace is in namespaces list\r\n\r\n const initOptions: InitOptions = {\r\n ...this._initOptions,\r\n defaultNS: defaultNamespace,\r\n ns: [...combinedNamespaces],\r\n };\r\n\r\n // if in a development environment, set debugging\r\n if (process.env.NODE_ENV === \"development\")\r\n initOptions.debug = true;\r\n\r\n const initPromise = this.i18next.init(initOptions) as unknown as Promise<void>;\r\n\r\n for (const ns of namespaces)\r\n this._namespaces.set(ns, initPromise);\r\n\r\n return initPromise;\r\n }\r\n\r\n /** Replace all instances of `%{key}` within a string with the translations of those keys.\r\n * For example:\r\n * ``` ts\r\n * \"MyKeys\": {\r\n * \"Key1\": \"First value\",\r\n * \"Key2\": \"Second value\"\r\n * }\r\n * ```\r\n *\r\n * ``` ts\r\n * i18.translateKeys(\"string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!\"\") // returns \"string with First Value followed by Second Value!\"\r\n * ```\r\n * @param line The input line, potentially containing %{keys}.\r\n * @returns The line with all %{keys} translated\r\n * @public\r\n */\r\n public getLocalizedKeys(line: string): string {\r\n return line.replace(/\\%\\{(.+?)\\}/g, (_match, tag) => this.getLocalizedString(tag));\r\n }\r\n\r\n /** Return the translated value of a key.\r\n * @param key - the key that matches a property in the JSON localization file.\r\n * @note The key includes the namespace, which identifies the particular localization file that contains the property,\r\n * followed by a colon, followed by the property in the JSON file.\r\n * For example:\r\n * ``` ts\r\n * const dataString: string = IModelApp.localization.getLocalizedString(\"iModelJs:BackgroundMap.BingDataAttribution\");\r\n * ```\r\n * assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.\r\n * @returns The string corresponding to the first key that resolves.\r\n * @throws Error if no keys resolve to a string.\r\n * @public\r\n */\r\n public getLocalizedString(key: string | string[], options?: TOptionsBase): string {\r\n if (options?.returnDetails || options?.returnObjects) {\r\n throw new Error(\"Translation key must map to a string, but the given options will result in an object\");\r\n }\r\n\r\n const value = this.i18next.t(key, options);\r\n\r\n if (typeof value !== \"string\") {\r\n throw new Error(\"Translation key(s) string not found\");\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need\r\n * to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.\r\n * @param namespace - the namespace that identifies the particular localization file that contains the property.\r\n * @param key - the key that matches a property in the JSON localization file.\r\n * @returns The string corresponding to the first key that resolves.\r\n * @throws Error if no keys resolve to a string.\r\n * @internal\r\n */\r\n public getLocalizedStringWithNamespace(namespace: string, key: string | string[], options?: TOptionsBase): string {\r\n let fullKey: string | string[] = \"\";\r\n\r\n if (typeof key === \"string\") {\r\n fullKey = `${namespace}:${key}`;\r\n } else {\r\n fullKey = key.map((subKey: string) => {\r\n return `${namespace}:${subKey}`;\r\n });\r\n }\r\n\r\n return this.getLocalizedString(fullKey, options);\r\n }\r\n\r\n /** Gets the English translation.\r\n * @param namespace - the namespace that identifies the particular localization file that contains the property.\r\n * @param key - the key that matches a property in the JSON localization file.\r\n * @returns The string corresponding to the first key that resolves.\r\n * @throws Error if no keys resolve to a string.\r\n * @internal\r\n */\r\n public getEnglishString(namespace: string, key: string | string[], options?: TOptionsBase): string {\r\n if (options?.returnDetails || options?.returnObjects) {\r\n throw new Error(\"Translation key must map to a string, but the given options will result in an object\");\r\n }\r\n\r\n options = {\r\n ...options,\r\n ns: namespace, // ensure namespace argument is used\r\n };\r\n\r\n const en = this.i18next.getFixedT(\"en\", namespace);\r\n const str = en(key, options);\r\n if (typeof str !== \"string\")\r\n throw new Error(\"Translation key(s) not found\");\r\n\r\n return str;\r\n }\r\n\r\n /** Get the promise for an already registered Namespace.\r\n * @param name - the name of the namespace\r\n * @public\r\n */\r\n public getNamespacePromise(name: string): Promise<void> | undefined {\r\n return this._namespaces.get(name);\r\n }\r\n\r\n /** @internal */\r\n public getLanguageList(): readonly string[] {\r\n return this.i18next.languages;\r\n }\r\n\r\n /** override the language detected in the browser */\r\n public async changeLanguage(language: string) {\r\n return this.i18next.changeLanguage(language) as unknown as Promise<void>;\r\n }\r\n\r\n /** Register a new Namespace and return it. If the namespace is already registered, it will be returned.\r\n * @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.\r\n * @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,\r\n * based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await\r\n * fulfillment of the readPromise Promise property of the returned LocalizationNamespace.\r\n * @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)\r\n * @public\r\n */\r\n public async registerNamespace(name: string): Promise<void> {\r\n const existing = this._namespaces.get(name);\r\n if (existing !== undefined)\r\n return existing;\r\n\r\n const theReadPromise = new Promise<void>((resolve) => {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this.i18next.loadNamespaces(name, (err) => {\r\n if (!err)\r\n return resolve();\r\n\r\n // Here we got a non-null err object.\r\n // This method is called when the system has attempted to load the resources for the namespaces for each possible locale.\r\n // For example 'fr-ca' might be the most specific locale, in which case 'fr' and 'en' are fallback locales.\r\n // Using Backend from i18next-http-backend, err will be an array of strings of each namespace it tried to read and its locale.\r\n // 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.\r\n let locales = this.getLanguageList().map((thisLocale: any) => `/${thisLocale}/`);\r\n\r\n try {\r\n for (const thisError of err) {\r\n if (typeof thisError === \"string\")\r\n locales = locales.filter((thisLocale) => !thisError.includes(thisLocale));\r\n }\r\n } catch (e) {\r\n locales = [];\r\n }\r\n // if we removed every locale from the array, it wasn't loaded.\r\n if (locales.length === 0)\r\n Logger.logError(\"i18n\", `No resources for namespace ${name} could be loaded`);\r\n\r\n resolve();\r\n });\r\n });\r\n this._namespaces.set(name, theReadPromise);\r\n return theReadPromise;\r\n }\r\n\r\n /** @internal */\r\n public unregisterNamespace(name: string): void {\r\n this._namespaces.delete(name);\r\n }\r\n}\r\n\r\nclass TranslationLogger {\r\n public static readonly type = \"logger\";\r\n public log(args: string[]) { Logger.logInfo(\"i18n\", this.createLogMessage(args)); }\r\n public warn(args: string[]) { Logger.logWarning(\"i18n\", this.createLogMessage(args)); }\r\n public error(args: string[]) { Logger.logError(\"i18n\", this.createLogMessage(args)); }\r\n private createLogMessage(args: string[]) {\r\n let message = args[0];\r\n for (let i = 1; i < args.length; ++i) {\r\n if (typeof args[i] === \"string\")\r\n message += `\\n ${args[i]}`;\r\n }\r\n return message;\r\n }\r\n}\r\n"]
|
|
3092
|
+
sourcesContent: ["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Localization\n */\n\nimport i18next, { i18n, InitOptions, Module, TOptionsBase } from \"i18next\";\nimport i18nextBrowserLanguageDetector, { DetectorOptions } from \"i18next-browser-languagedetector\";\nimport Backend, { BackendOptions } from \"i18next-http-backend\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type { Localization } from \"@itwin/core-common\";\n\nconst DEFAULT_MAX_RETRIES: number = 1; // a low number prevents wasted time and potential timeouts when requesting localization files throws an error\n\n/** Options for ITwinLocalization\n * @public\n */\nexport interface LocalizationOptions {\n urlTemplate?: string;\n backendPlugin?: Module;\n detectorPlugin?: Module;\n initOptions?: InitOptions;\n backendHttpOptions?: BackendOptions;\n detectorOptions?: DetectorOptions;\n}\n\n/** Supplies localizations for iTwin.js\n * @note this class uses the [i18next](https://www.i18next.com/) package.\n * @public\n */\nexport class ITwinLocalization implements Localization {\n public i18next: i18n;\n private readonly _initOptions: InitOptions;\n private readonly _backendOptions: BackendOptions;\n private readonly _detectionOptions: DetectorOptions;\n private readonly _namespaces = new Map<string, Promise<void>>();\n\n public constructor(options?: LocalizationOptions) {\n this.i18next = i18next.createInstance();\n\n this._backendOptions = {\n loadPath: options?.urlTemplate ?? \"locales/{{lng}}/{{ns}}.json\",\n crossDomain: true,\n ...options?.backendHttpOptions,\n };\n\n this._detectionOptions = {\n order: [\"querystring\", \"navigator\", \"htmlTag\"],\n lookupQuerystring: \"lng\",\n caches: [],\n ...options?.detectorOptions,\n };\n\n this._initOptions = {\n interpolation: { escapeValue: true },\n fallbackLng: \"en\",\n maxRetries: DEFAULT_MAX_RETRIES,\n backend: this._backendOptions,\n detection: this._detectionOptions,\n ...options?.initOptions,\n };\n\n this.i18next\n .use(options?.detectorPlugin ?? i18nextBrowserLanguageDetector)\n .use(options?.backendPlugin ?? Backend)\n .use(TranslationLogger);\n }\n\n public async initialize(namespaces: string[]): Promise<void> {\n\n // Also consider namespaces passed into constructor\n const initNamespaces: string[] = [this._initOptions.ns || []].flat();\n const combinedNamespaces: Set<string> = new Set([...namespaces, ...initNamespaces]); // without duplicates\n\n const defaultNamespace: string | false | readonly string[] = this._initOptions.defaultNS ?? namespaces[0];\n if (defaultNamespace)\n combinedNamespaces.add(defaultNamespace as string); // Make sure default namespace is in namespaces list\n\n const initOptions: InitOptions = {\n ...this._initOptions,\n defaultNS: defaultNamespace,\n ns: [...combinedNamespaces],\n };\n\n // if in a development environment, set debugging\n if (process.env.NODE_ENV === \"development\")\n initOptions.debug = true;\n\n const initPromise = this.i18next.init(initOptions) as unknown as Promise<void>;\n\n for (const ns of namespaces)\n this._namespaces.set(ns, initPromise);\n\n return initPromise;\n }\n\n /** Replace all instances of `%{key}` within a string with the translations of those keys.\n * For example:\n * ``` ts\n * \"MyKeys\": {\n * \"Key1\": \"First value\",\n * \"Key2\": \"Second value\"\n * }\n * ```\n *\n * ``` ts\n * i18.translateKeys(\"string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!\"\") // returns \"string with First Value followed by Second Value!\"\n * ```\n * @param line The input line, potentially containing %{keys}.\n * @returns The line with all %{keys} translated\n * @public\n */\n public getLocalizedKeys(line: string): string {\n return line.replace(/\\%\\{(.+?)\\}/g, (_match, tag) => this.getLocalizedString(tag));\n }\n\n /** Return the translated value of a key.\n * @param key - the key that matches a property in the JSON localization file.\n * @note The key includes the namespace, which identifies the particular localization file that contains the property,\n * followed by a colon, followed by the property in the JSON file.\n * For example:\n * ``` ts\n * const dataString: string = IModelApp.localization.getLocalizedString(\"iModelJs:BackgroundMap.BingDataAttribution\");\n * ```\n * assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.\n * @returns The string corresponding to the first key that resolves.\n * @throws Error if no keys resolve to a string.\n * @public\n */\n public getLocalizedString(key: string | string[], options?: TOptionsBase): string {\n if (options?.returnDetails || options?.returnObjects) {\n throw new Error(\"Translation key must map to a string, but the given options will result in an object\");\n }\n\n const value = this.i18next.t(key, options);\n\n if (typeof value !== \"string\") {\n throw new Error(\"Translation key(s) string not found\");\n }\n\n return value;\n }\n\n /** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need\n * to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.\n * @param namespace - the namespace that identifies the particular localization file that contains the property.\n * @param key - the key that matches a property in the JSON localization file.\n * @returns The string corresponding to the first key that resolves.\n * @throws Error if no keys resolve to a string.\n * @internal\n */\n public getLocalizedStringWithNamespace(namespace: string, key: string | string[], options?: TOptionsBase): string {\n let fullKey: string | string[] = \"\";\n\n if (typeof key === \"string\") {\n fullKey = `${namespace}:${key}`;\n } else {\n fullKey = key.map((subKey: string) => {\n return `${namespace}:${subKey}`;\n });\n }\n\n return this.getLocalizedString(fullKey, options);\n }\n\n /** Gets the English translation.\n * @param namespace - the namespace that identifies the particular localization file that contains the property.\n * @param key - the key that matches a property in the JSON localization file.\n * @returns The string corresponding to the first key that resolves.\n * @throws Error if no keys resolve to a string.\n * @internal\n */\n public getEnglishString(namespace: string, key: string | string[], options?: TOptionsBase): string {\n if (options?.returnDetails || options?.returnObjects) {\n throw new Error(\"Translation key must map to a string, but the given options will result in an object\");\n }\n\n options = {\n ...options,\n ns: namespace, // ensure namespace argument is used\n };\n\n const en = this.i18next.getFixedT(\"en\", namespace);\n const str = en(key, options);\n if (typeof str !== \"string\")\n throw new Error(\"Translation key(s) not found\");\n\n return str;\n }\n\n /** Get the promise for an already registered Namespace.\n * @param name - the name of the namespace\n * @public\n */\n public getNamespacePromise(name: string): Promise<void> | undefined {\n return this._namespaces.get(name);\n }\n\n /** @internal */\n public getLanguageList(): readonly string[] {\n return this.i18next.languages;\n }\n\n /** override the language detected in the browser */\n public async changeLanguage(language: string) {\n return this.i18next.changeLanguage(language) as unknown as Promise<void>;\n }\n\n /** Register a new Namespace and return it. If the namespace is already registered, it will be returned.\n * @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.\n * @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,\n * based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await\n * fulfillment of the readPromise Promise property of the returned LocalizationNamespace.\n * @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)\n * @public\n */\n public async registerNamespace(name: string): Promise<void> {\n const existing = this._namespaces.get(name);\n if (existing !== undefined)\n return existing;\n\n const theReadPromise = new Promise<void>((resolve) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.i18next.loadNamespaces(name, (err) => {\n if (!err)\n return resolve();\n\n // Here we got a non-null err object.\n // This method is called when the system has attempted to load the resources for the namespaces for each possible locale.\n // For example 'fr-ca' might be the most specific locale, in which case 'fr' and 'en' are fallback locales.\n // Using Backend from i18next-http-backend, err will be an array of strings of each namespace it tried to read and its locale.\n // 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.\n let locales = this.getLanguageList().map((thisLocale: any) => `/${thisLocale}/`);\n\n try {\n for (const thisError of err) {\n if (typeof thisError === \"string\")\n locales = locales.filter((thisLocale) => !thisError.includes(thisLocale));\n }\n } catch (e) {\n locales = [];\n }\n // if we removed every locale from the array, it wasn't loaded.\n if (locales.length === 0)\n Logger.logError(\"i18n\", `No resources for namespace ${name} could be loaded`);\n\n resolve();\n });\n });\n this._namespaces.set(name, theReadPromise);\n return theReadPromise;\n }\n\n /** @internal */\n public unregisterNamespace(name: string): void {\n this._namespaces.delete(name);\n }\n}\n\nclass TranslationLogger {\n public static readonly type = \"logger\";\n public log(args: string[]) { Logger.logInfo(\"i18n\", this.createLogMessage(args)); }\n public warn(args: string[]) { Logger.logWarning(\"i18n\", this.createLogMessage(args)); }\n public error(args: string[]) { Logger.logError(\"i18n\", this.createLogMessage(args)); }\n private createLogMessage(args: string[]) {\n let message = args[0];\n for (let i = 1; i < args.length; ++i) {\n if (typeof args[i] === \"string\")\n message += `\\n ${args[i]}`;\n }\n return message;\n }\n}\n"]
|
|
3093
3093
|
},
|
|
3094
3094
|
_coverageSchema: "1a1c01bbd47fc00a2c39e90264f33305004495a9",
|
|
3095
|
-
hash: "
|
|
3095
|
+
hash: "cc047c5ea4bef181505d77b051311020fceb8acf"
|
|
3096
3096
|
};
|
|
3097
3097
|
var coverage = global[gcv] || (global[gcv] = {});
|
|
3098
3098
|
if (!coverage[path] || coverage[path].hash !== hash) {
|
|
@@ -3101,57 +3101,57 @@ function cov_2jo8rrbgid() {
|
|
|
3101
3101
|
var actualCoverage = coverage[path];
|
|
3102
3102
|
{
|
|
3103
3103
|
// @ts-ignore
|
|
3104
|
-
|
|
3104
|
+
cov_2l9mmpbx71 = function () {
|
|
3105
3105
|
return actualCoverage;
|
|
3106
3106
|
};
|
|
3107
3107
|
}
|
|
3108
3108
|
return actualCoverage;
|
|
3109
3109
|
}
|
|
3110
|
-
|
|
3111
|
-
var __importDefault = (
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
return (
|
|
3110
|
+
cov_2l9mmpbx71();
|
|
3111
|
+
var __importDefault = (cov_2l9mmpbx71().s[0]++, (cov_2l9mmpbx71().b[0][0]++, this) && (cov_2l9mmpbx71().b[0][1]++, this.__importDefault) || (cov_2l9mmpbx71().b[0][2]++, function (mod) {
|
|
3112
|
+
cov_2l9mmpbx71().f[0]++;
|
|
3113
|
+
cov_2l9mmpbx71().s[1]++;
|
|
3114
|
+
return (cov_2l9mmpbx71().b[2][0]++, mod) && (cov_2l9mmpbx71().b[2][1]++, mod.__esModule) ? (cov_2l9mmpbx71().b[1][0]++, mod) : (cov_2l9mmpbx71().b[1][1]++, {
|
|
3115
3115
|
"default": mod
|
|
3116
3116
|
});
|
|
3117
3117
|
}));
|
|
3118
|
-
|
|
3118
|
+
cov_2l9mmpbx71().s[2]++;
|
|
3119
3119
|
Object.defineProperty(exports, "__esModule", ({
|
|
3120
3120
|
value: true
|
|
3121
3121
|
}));
|
|
3122
|
-
|
|
3122
|
+
cov_2l9mmpbx71().s[3]++;
|
|
3123
3123
|
exports.ITwinLocalization = void 0;
|
|
3124
|
-
const i18next_1 = (
|
|
3125
|
-
const i18next_browser_languagedetector_1 = (
|
|
3126
|
-
const i18next_http_backend_1 = (
|
|
3127
|
-
const core_bentley_1 = (
|
|
3128
|
-
const DEFAULT_MAX_RETRIES = (
|
|
3129
|
-
/** Supplies localizations for iTwin.js
|
|
3130
|
-
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
3131
|
-
* @public
|
|
3124
|
+
const i18next_1 = (cov_2l9mmpbx71().s[4]++, __importDefault(__webpack_require__(/*! i18next */ "../../common/temp/node_modules/.pnpm/i18next@21.10.0/node_modules/i18next/dist/cjs/i18next.js")));
|
|
3125
|
+
const i18next_browser_languagedetector_1 = (cov_2l9mmpbx71().s[5]++, __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")));
|
|
3126
|
+
const i18next_http_backend_1 = (cov_2l9mmpbx71().s[6]++, __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")));
|
|
3127
|
+
const core_bentley_1 = (cov_2l9mmpbx71().s[7]++, __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js"));
|
|
3128
|
+
const DEFAULT_MAX_RETRIES = (cov_2l9mmpbx71().s[8]++, 1); // a low number prevents wasted time and potential timeouts when requesting localization files throws an error
|
|
3129
|
+
/** Supplies localizations for iTwin.js
|
|
3130
|
+
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
3131
|
+
* @public
|
|
3132
3132
|
*/
|
|
3133
3133
|
class ITwinLocalization {
|
|
3134
3134
|
constructor(options) {
|
|
3135
|
-
|
|
3135
|
+
cov_2l9mmpbx71().f[1]++;
|
|
3136
3136
|
var _a, _b, _c;
|
|
3137
|
-
|
|
3137
|
+
cov_2l9mmpbx71().s[9]++;
|
|
3138
3138
|
this._namespaces = new Map();
|
|
3139
|
-
|
|
3139
|
+
cov_2l9mmpbx71().s[10]++;
|
|
3140
3140
|
this.i18next = i18next_1.default.createInstance();
|
|
3141
|
-
|
|
3141
|
+
cov_2l9mmpbx71().s[11]++;
|
|
3142
3142
|
this._backendOptions = {
|
|
3143
|
-
loadPath: (
|
|
3143
|
+
loadPath: (cov_2l9mmpbx71().b[4][0]++, (_a = (cov_2l9mmpbx71().b[6][0]++, options === null) || (cov_2l9mmpbx71().b[6][1]++, options === void 0) ? (cov_2l9mmpbx71().b[5][0]++, void 0) : (cov_2l9mmpbx71().b[5][1]++, options.urlTemplate)) !== null) && (cov_2l9mmpbx71().b[4][1]++, _a !== void 0) ? (cov_2l9mmpbx71().b[3][0]++, _a) : (cov_2l9mmpbx71().b[3][1]++, "locales/{{lng}}/{{ns}}.json"),
|
|
3144
3144
|
crossDomain: true,
|
|
3145
|
-
...((
|
|
3145
|
+
...((cov_2l9mmpbx71().b[8][0]++, options === null) || (cov_2l9mmpbx71().b[8][1]++, options === void 0) ? (cov_2l9mmpbx71().b[7][0]++, void 0) : (cov_2l9mmpbx71().b[7][1]++, options.backendHttpOptions))
|
|
3146
3146
|
};
|
|
3147
|
-
|
|
3147
|
+
cov_2l9mmpbx71().s[12]++;
|
|
3148
3148
|
this._detectionOptions = {
|
|
3149
3149
|
order: ["querystring", "navigator", "htmlTag"],
|
|
3150
3150
|
lookupQuerystring: "lng",
|
|
3151
3151
|
caches: [],
|
|
3152
|
-
...((
|
|
3152
|
+
...((cov_2l9mmpbx71().b[10][0]++, options === null) || (cov_2l9mmpbx71().b[10][1]++, options === void 0) ? (cov_2l9mmpbx71().b[9][0]++, void 0) : (cov_2l9mmpbx71().b[9][1]++, options.detectorOptions))
|
|
3153
3153
|
};
|
|
3154
|
-
|
|
3154
|
+
cov_2l9mmpbx71().s[13]++;
|
|
3155
3155
|
this._initOptions = {
|
|
3156
3156
|
interpolation: {
|
|
3157
3157
|
escapeValue: true
|
|
@@ -3160,316 +3160,316 @@ class ITwinLocalization {
|
|
|
3160
3160
|
maxRetries: DEFAULT_MAX_RETRIES,
|
|
3161
3161
|
backend: this._backendOptions,
|
|
3162
3162
|
detection: this._detectionOptions,
|
|
3163
|
-
...((
|
|
3163
|
+
...((cov_2l9mmpbx71().b[12][0]++, options === null) || (cov_2l9mmpbx71().b[12][1]++, options === void 0) ? (cov_2l9mmpbx71().b[11][0]++, void 0) : (cov_2l9mmpbx71().b[11][1]++, options.initOptions))
|
|
3164
3164
|
};
|
|
3165
|
-
|
|
3166
|
-
this.i18next.use((
|
|
3165
|
+
cov_2l9mmpbx71().s[14]++;
|
|
3166
|
+
this.i18next.use((cov_2l9mmpbx71().b[14][0]++, (_b = (cov_2l9mmpbx71().b[16][0]++, options === null) || (cov_2l9mmpbx71().b[16][1]++, options === void 0) ? (cov_2l9mmpbx71().b[15][0]++, void 0) : (cov_2l9mmpbx71().b[15][1]++, options.detectorPlugin)) !== null) && (cov_2l9mmpbx71().b[14][1]++, _b !== void 0) ? (cov_2l9mmpbx71().b[13][0]++, _b) : (cov_2l9mmpbx71().b[13][1]++, i18next_browser_languagedetector_1.default)).use((cov_2l9mmpbx71().b[18][0]++, (_c = (cov_2l9mmpbx71().b[20][0]++, options === null) || (cov_2l9mmpbx71().b[20][1]++, options === void 0) ? (cov_2l9mmpbx71().b[19][0]++, void 0) : (cov_2l9mmpbx71().b[19][1]++, options.backendPlugin)) !== null) && (cov_2l9mmpbx71().b[18][1]++, _c !== void 0) ? (cov_2l9mmpbx71().b[17][0]++, _c) : (cov_2l9mmpbx71().b[17][1]++, i18next_http_backend_1.default)).use(TranslationLogger);
|
|
3167
3167
|
}
|
|
3168
3168
|
async initialize(namespaces) {
|
|
3169
|
-
|
|
3169
|
+
cov_2l9mmpbx71().f[2]++;
|
|
3170
3170
|
var _a;
|
|
3171
3171
|
// Also consider namespaces passed into constructor
|
|
3172
|
-
const initNamespaces = (
|
|
3173
|
-
const combinedNamespaces = (
|
|
3174
|
-
const defaultNamespace = (
|
|
3175
|
-
|
|
3172
|
+
const initNamespaces = (cov_2l9mmpbx71().s[15]++, [(cov_2l9mmpbx71().b[21][0]++, this._initOptions.ns) || (cov_2l9mmpbx71().b[21][1]++, [])].flat());
|
|
3173
|
+
const combinedNamespaces = (cov_2l9mmpbx71().s[16]++, new Set([...namespaces, ...initNamespaces])); // without duplicates
|
|
3174
|
+
const defaultNamespace = (cov_2l9mmpbx71().s[17]++, (cov_2l9mmpbx71().b[23][0]++, (_a = this._initOptions.defaultNS) !== null) && (cov_2l9mmpbx71().b[23][1]++, _a !== void 0) ? (cov_2l9mmpbx71().b[22][0]++, _a) : (cov_2l9mmpbx71().b[22][1]++, namespaces[0]));
|
|
3175
|
+
cov_2l9mmpbx71().s[18]++;
|
|
3176
3176
|
if (defaultNamespace) {
|
|
3177
|
-
|
|
3178
|
-
|
|
3177
|
+
cov_2l9mmpbx71().b[24][0]++;
|
|
3178
|
+
cov_2l9mmpbx71().s[19]++;
|
|
3179
3179
|
combinedNamespaces.add(defaultNamespace);
|
|
3180
3180
|
} else {
|
|
3181
|
-
|
|
3181
|
+
cov_2l9mmpbx71().b[24][1]++;
|
|
3182
3182
|
} // Make sure default namespace is in namespaces list
|
|
3183
|
-
const initOptions = (
|
|
3183
|
+
const initOptions = (cov_2l9mmpbx71().s[20]++, {
|
|
3184
3184
|
...this._initOptions,
|
|
3185
3185
|
defaultNS: defaultNamespace,
|
|
3186
3186
|
ns: [...combinedNamespaces]
|
|
3187
3187
|
});
|
|
3188
3188
|
// if in a development environment, set debugging
|
|
3189
|
-
|
|
3189
|
+
cov_2l9mmpbx71().s[21]++;
|
|
3190
3190
|
if (false) {} else {
|
|
3191
|
-
|
|
3191
|
+
cov_2l9mmpbx71().b[25][1]++;
|
|
3192
3192
|
}
|
|
3193
|
-
const initPromise = (
|
|
3194
|
-
|
|
3193
|
+
const initPromise = (cov_2l9mmpbx71().s[23]++, this.i18next.init(initOptions));
|
|
3194
|
+
cov_2l9mmpbx71().s[24]++;
|
|
3195
3195
|
for (const ns of namespaces) {
|
|
3196
|
-
|
|
3196
|
+
cov_2l9mmpbx71().s[25]++;
|
|
3197
3197
|
this._namespaces.set(ns, initPromise);
|
|
3198
3198
|
}
|
|
3199
|
-
|
|
3199
|
+
cov_2l9mmpbx71().s[26]++;
|
|
3200
3200
|
return initPromise;
|
|
3201
3201
|
}
|
|
3202
|
-
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
3203
|
-
* For example:
|
|
3204
|
-
* ``` ts
|
|
3205
|
-
* "MyKeys": {
|
|
3206
|
-
* "Key1": "First value",
|
|
3207
|
-
* "Key2": "Second value"
|
|
3208
|
-
* }
|
|
3209
|
-
* ```
|
|
3210
|
-
*
|
|
3211
|
-
* ``` ts
|
|
3212
|
-
* i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!"
|
|
3213
|
-
* ```
|
|
3214
|
-
* @param line The input line, potentially containing %{keys}.
|
|
3215
|
-
* @returns The line with all %{keys} translated
|
|
3216
|
-
* @public
|
|
3202
|
+
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
3203
|
+
* For example:
|
|
3204
|
+
* ``` ts
|
|
3205
|
+
* "MyKeys": {
|
|
3206
|
+
* "Key1": "First value",
|
|
3207
|
+
* "Key2": "Second value"
|
|
3208
|
+
* }
|
|
3209
|
+
* ```
|
|
3210
|
+
*
|
|
3211
|
+
* ``` ts
|
|
3212
|
+
* i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!"
|
|
3213
|
+
* ```
|
|
3214
|
+
* @param line The input line, potentially containing %{keys}.
|
|
3215
|
+
* @returns The line with all %{keys} translated
|
|
3216
|
+
* @public
|
|
3217
3217
|
*/
|
|
3218
3218
|
getLocalizedKeys(line) {
|
|
3219
|
-
|
|
3220
|
-
|
|
3219
|
+
cov_2l9mmpbx71().f[3]++;
|
|
3220
|
+
cov_2l9mmpbx71().s[27]++;
|
|
3221
3221
|
return line.replace(/\%\{(.+?)\}/g, (_match, tag) => {
|
|
3222
|
-
|
|
3223
|
-
|
|
3222
|
+
cov_2l9mmpbx71().f[4]++;
|
|
3223
|
+
cov_2l9mmpbx71().s[28]++;
|
|
3224
3224
|
return this.getLocalizedString(tag);
|
|
3225
3225
|
});
|
|
3226
3226
|
}
|
|
3227
|
-
/** Return the translated value of a key.
|
|
3228
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
3229
|
-
* @note The key includes the namespace, which identifies the particular localization file that contains the property,
|
|
3230
|
-
* followed by a colon, followed by the property in the JSON file.
|
|
3231
|
-
* For example:
|
|
3232
|
-
* ``` ts
|
|
3233
|
-
* const dataString: string = IModelApp.localization.getLocalizedString("iModelJs:BackgroundMap.BingDataAttribution");
|
|
3234
|
-
* ```
|
|
3235
|
-
* assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.
|
|
3236
|
-
* @returns The string corresponding to the first key that resolves.
|
|
3237
|
-
* @throws Error if no keys resolve to a string.
|
|
3238
|
-
* @public
|
|
3227
|
+
/** Return the translated value of a key.
|
|
3228
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
3229
|
+
* @note The key includes the namespace, which identifies the particular localization file that contains the property,
|
|
3230
|
+
* followed by a colon, followed by the property in the JSON file.
|
|
3231
|
+
* For example:
|
|
3232
|
+
* ``` ts
|
|
3233
|
+
* const dataString: string = IModelApp.localization.getLocalizedString("iModelJs:BackgroundMap.BingDataAttribution");
|
|
3234
|
+
* ```
|
|
3235
|
+
* assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.
|
|
3236
|
+
* @returns The string corresponding to the first key that resolves.
|
|
3237
|
+
* @throws Error if no keys resolve to a string.
|
|
3238
|
+
* @public
|
|
3239
3239
|
*/
|
|
3240
3240
|
getLocalizedString(key, options) {
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
if ((
|
|
3244
|
-
|
|
3245
|
-
|
|
3241
|
+
cov_2l9mmpbx71().f[5]++;
|
|
3242
|
+
cov_2l9mmpbx71().s[29]++;
|
|
3243
|
+
if ((cov_2l9mmpbx71().b[27][0]++, (cov_2l9mmpbx71().b[29][0]++, options === null) || (cov_2l9mmpbx71().b[29][1]++, options === void 0) ? (cov_2l9mmpbx71().b[28][0]++, void 0) : (cov_2l9mmpbx71().b[28][1]++, options.returnDetails)) || (cov_2l9mmpbx71().b[27][1]++, (cov_2l9mmpbx71().b[31][0]++, options === null) || (cov_2l9mmpbx71().b[31][1]++, options === void 0) ? (cov_2l9mmpbx71().b[30][0]++, void 0) : (cov_2l9mmpbx71().b[30][1]++, options.returnObjects))) {
|
|
3244
|
+
cov_2l9mmpbx71().b[26][0]++;
|
|
3245
|
+
cov_2l9mmpbx71().s[30]++;
|
|
3246
3246
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
3247
3247
|
} else {
|
|
3248
|
-
|
|
3248
|
+
cov_2l9mmpbx71().b[26][1]++;
|
|
3249
3249
|
}
|
|
3250
|
-
const value = (
|
|
3251
|
-
|
|
3250
|
+
const value = (cov_2l9mmpbx71().s[31]++, this.i18next.t(key, options));
|
|
3251
|
+
cov_2l9mmpbx71().s[32]++;
|
|
3252
3252
|
if (typeof value !== "string") {
|
|
3253
|
-
|
|
3254
|
-
|
|
3253
|
+
cov_2l9mmpbx71().b[32][0]++;
|
|
3254
|
+
cov_2l9mmpbx71().s[33]++;
|
|
3255
3255
|
throw new Error("Translation key(s) string not found");
|
|
3256
3256
|
} else {
|
|
3257
|
-
|
|
3257
|
+
cov_2l9mmpbx71().b[32][1]++;
|
|
3258
3258
|
}
|
|
3259
|
-
|
|
3259
|
+
cov_2l9mmpbx71().s[34]++;
|
|
3260
3260
|
return value;
|
|
3261
3261
|
}
|
|
3262
|
-
/** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need
|
|
3263
|
-
* to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.
|
|
3264
|
-
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3265
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
3266
|
-
* @returns The string corresponding to the first key that resolves.
|
|
3267
|
-
* @throws Error if no keys resolve to a string.
|
|
3268
|
-
* @internal
|
|
3262
|
+
/** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need
|
|
3263
|
+
* to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.
|
|
3264
|
+
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3265
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
3266
|
+
* @returns The string corresponding to the first key that resolves.
|
|
3267
|
+
* @throws Error if no keys resolve to a string.
|
|
3268
|
+
* @internal
|
|
3269
3269
|
*/
|
|
3270
3270
|
getLocalizedStringWithNamespace(namespace, key, options) {
|
|
3271
|
-
|
|
3272
|
-
let fullKey = (
|
|
3273
|
-
|
|
3271
|
+
cov_2l9mmpbx71().f[6]++;
|
|
3272
|
+
let fullKey = (cov_2l9mmpbx71().s[35]++, "");
|
|
3273
|
+
cov_2l9mmpbx71().s[36]++;
|
|
3274
3274
|
if (typeof key === "string") {
|
|
3275
|
-
|
|
3276
|
-
|
|
3275
|
+
cov_2l9mmpbx71().b[33][0]++;
|
|
3276
|
+
cov_2l9mmpbx71().s[37]++;
|
|
3277
3277
|
fullKey = `${namespace}:${key}`;
|
|
3278
3278
|
} else {
|
|
3279
|
-
|
|
3280
|
-
|
|
3279
|
+
cov_2l9mmpbx71().b[33][1]++;
|
|
3280
|
+
cov_2l9mmpbx71().s[38]++;
|
|
3281
3281
|
fullKey = key.map(subKey => {
|
|
3282
|
-
|
|
3283
|
-
|
|
3282
|
+
cov_2l9mmpbx71().f[7]++;
|
|
3283
|
+
cov_2l9mmpbx71().s[39]++;
|
|
3284
3284
|
return `${namespace}:${subKey}`;
|
|
3285
3285
|
});
|
|
3286
3286
|
}
|
|
3287
|
-
|
|
3287
|
+
cov_2l9mmpbx71().s[40]++;
|
|
3288
3288
|
return this.getLocalizedString(fullKey, options);
|
|
3289
3289
|
}
|
|
3290
|
-
/** Gets the English translation.
|
|
3291
|
-
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3292
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
3293
|
-
* @returns The string corresponding to the first key that resolves.
|
|
3294
|
-
* @throws Error if no keys resolve to a string.
|
|
3295
|
-
* @internal
|
|
3290
|
+
/** Gets the English translation.
|
|
3291
|
+
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3292
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
3293
|
+
* @returns The string corresponding to the first key that resolves.
|
|
3294
|
+
* @throws Error if no keys resolve to a string.
|
|
3295
|
+
* @internal
|
|
3296
3296
|
*/
|
|
3297
3297
|
getEnglishString(namespace, key, options) {
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
if ((
|
|
3301
|
-
|
|
3302
|
-
|
|
3298
|
+
cov_2l9mmpbx71().f[8]++;
|
|
3299
|
+
cov_2l9mmpbx71().s[41]++;
|
|
3300
|
+
if ((cov_2l9mmpbx71().b[35][0]++, (cov_2l9mmpbx71().b[37][0]++, options === null) || (cov_2l9mmpbx71().b[37][1]++, options === void 0) ? (cov_2l9mmpbx71().b[36][0]++, void 0) : (cov_2l9mmpbx71().b[36][1]++, options.returnDetails)) || (cov_2l9mmpbx71().b[35][1]++, (cov_2l9mmpbx71().b[39][0]++, options === null) || (cov_2l9mmpbx71().b[39][1]++, options === void 0) ? (cov_2l9mmpbx71().b[38][0]++, void 0) : (cov_2l9mmpbx71().b[38][1]++, options.returnObjects))) {
|
|
3301
|
+
cov_2l9mmpbx71().b[34][0]++;
|
|
3302
|
+
cov_2l9mmpbx71().s[42]++;
|
|
3303
3303
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
3304
3304
|
} else {
|
|
3305
|
-
|
|
3305
|
+
cov_2l9mmpbx71().b[34][1]++;
|
|
3306
3306
|
}
|
|
3307
|
-
|
|
3307
|
+
cov_2l9mmpbx71().s[43]++;
|
|
3308
3308
|
options = {
|
|
3309
3309
|
...options,
|
|
3310
3310
|
ns: namespace // ensure namespace argument is used
|
|
3311
3311
|
};
|
|
3312
3312
|
|
|
3313
|
-
const en = (
|
|
3314
|
-
const str = (
|
|
3315
|
-
|
|
3313
|
+
const en = (cov_2l9mmpbx71().s[44]++, this.i18next.getFixedT("en", namespace));
|
|
3314
|
+
const str = (cov_2l9mmpbx71().s[45]++, en(key, options));
|
|
3315
|
+
cov_2l9mmpbx71().s[46]++;
|
|
3316
3316
|
if (typeof str !== "string") {
|
|
3317
|
-
|
|
3318
|
-
|
|
3317
|
+
cov_2l9mmpbx71().b[40][0]++;
|
|
3318
|
+
cov_2l9mmpbx71().s[47]++;
|
|
3319
3319
|
throw new Error("Translation key(s) not found");
|
|
3320
3320
|
} else {
|
|
3321
|
-
|
|
3321
|
+
cov_2l9mmpbx71().b[40][1]++;
|
|
3322
3322
|
}
|
|
3323
|
-
|
|
3323
|
+
cov_2l9mmpbx71().s[48]++;
|
|
3324
3324
|
return str;
|
|
3325
3325
|
}
|
|
3326
|
-
/** Get the promise for an already registered Namespace.
|
|
3327
|
-
* @param name - the name of the namespace
|
|
3328
|
-
* @public
|
|
3326
|
+
/** Get the promise for an already registered Namespace.
|
|
3327
|
+
* @param name - the name of the namespace
|
|
3328
|
+
* @public
|
|
3329
3329
|
*/
|
|
3330
3330
|
getNamespacePromise(name) {
|
|
3331
|
-
|
|
3332
|
-
|
|
3331
|
+
cov_2l9mmpbx71().f[9]++;
|
|
3332
|
+
cov_2l9mmpbx71().s[49]++;
|
|
3333
3333
|
return this._namespaces.get(name);
|
|
3334
3334
|
}
|
|
3335
3335
|
/** @internal */
|
|
3336
3336
|
getLanguageList() {
|
|
3337
|
-
|
|
3338
|
-
|
|
3337
|
+
cov_2l9mmpbx71().f[10]++;
|
|
3338
|
+
cov_2l9mmpbx71().s[50]++;
|
|
3339
3339
|
return this.i18next.languages;
|
|
3340
3340
|
}
|
|
3341
3341
|
/** override the language detected in the browser */
|
|
3342
3342
|
async changeLanguage(language) {
|
|
3343
|
-
|
|
3344
|
-
|
|
3343
|
+
cov_2l9mmpbx71().f[11]++;
|
|
3344
|
+
cov_2l9mmpbx71().s[51]++;
|
|
3345
3345
|
return this.i18next.changeLanguage(language);
|
|
3346
3346
|
}
|
|
3347
|
-
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
3348
|
-
* @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.
|
|
3349
|
-
* @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,
|
|
3350
|
-
* based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await
|
|
3351
|
-
* fulfillment of the readPromise Promise property of the returned LocalizationNamespace.
|
|
3352
|
-
* @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)
|
|
3353
|
-
* @public
|
|
3347
|
+
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
3348
|
+
* @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.
|
|
3349
|
+
* @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,
|
|
3350
|
+
* based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await
|
|
3351
|
+
* fulfillment of the readPromise Promise property of the returned LocalizationNamespace.
|
|
3352
|
+
* @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)
|
|
3353
|
+
* @public
|
|
3354
3354
|
*/
|
|
3355
3355
|
async registerNamespace(name) {
|
|
3356
|
-
|
|
3357
|
-
const existing = (
|
|
3358
|
-
|
|
3356
|
+
cov_2l9mmpbx71().f[12]++;
|
|
3357
|
+
const existing = (cov_2l9mmpbx71().s[52]++, this._namespaces.get(name));
|
|
3358
|
+
cov_2l9mmpbx71().s[53]++;
|
|
3359
3359
|
if (existing !== undefined) {
|
|
3360
|
-
|
|
3361
|
-
|
|
3360
|
+
cov_2l9mmpbx71().b[41][0]++;
|
|
3361
|
+
cov_2l9mmpbx71().s[54]++;
|
|
3362
3362
|
return existing;
|
|
3363
3363
|
} else {
|
|
3364
|
-
|
|
3364
|
+
cov_2l9mmpbx71().b[41][1]++;
|
|
3365
3365
|
}
|
|
3366
|
-
const theReadPromise = (
|
|
3367
|
-
|
|
3368
|
-
|
|
3366
|
+
const theReadPromise = (cov_2l9mmpbx71().s[55]++, new Promise(resolve => {
|
|
3367
|
+
cov_2l9mmpbx71().f[13]++;
|
|
3368
|
+
cov_2l9mmpbx71().s[56]++;
|
|
3369
3369
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
3370
3370
|
this.i18next.loadNamespaces(name, err => {
|
|
3371
|
-
|
|
3372
|
-
|
|
3371
|
+
cov_2l9mmpbx71().f[14]++;
|
|
3372
|
+
cov_2l9mmpbx71().s[57]++;
|
|
3373
3373
|
if (!err) {
|
|
3374
|
-
|
|
3375
|
-
|
|
3374
|
+
cov_2l9mmpbx71().b[42][0]++;
|
|
3375
|
+
cov_2l9mmpbx71().s[58]++;
|
|
3376
3376
|
return resolve();
|
|
3377
3377
|
} else {
|
|
3378
|
-
|
|
3378
|
+
cov_2l9mmpbx71().b[42][1]++;
|
|
3379
3379
|
}
|
|
3380
3380
|
// Here we got a non-null err object.
|
|
3381
3381
|
// This method is called when the system has attempted to load the resources for the namespaces for each possible locale.
|
|
3382
3382
|
// For example 'fr-ca' might be the most specific locale, in which case 'fr' and 'en' are fallback locales.
|
|
3383
3383
|
// Using Backend from i18next-http-backend, err will be an array of strings of each namespace it tried to read and its locale.
|
|
3384
3384
|
// 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.
|
|
3385
|
-
let locales = (
|
|
3386
|
-
|
|
3387
|
-
|
|
3385
|
+
let locales = (cov_2l9mmpbx71().s[59]++, this.getLanguageList().map(thisLocale => {
|
|
3386
|
+
cov_2l9mmpbx71().f[15]++;
|
|
3387
|
+
cov_2l9mmpbx71().s[60]++;
|
|
3388
3388
|
return `/${thisLocale}/`;
|
|
3389
3389
|
}));
|
|
3390
|
-
|
|
3390
|
+
cov_2l9mmpbx71().s[61]++;
|
|
3391
3391
|
try {
|
|
3392
|
-
|
|
3392
|
+
cov_2l9mmpbx71().s[62]++;
|
|
3393
3393
|
for (const thisError of err) {
|
|
3394
|
-
|
|
3394
|
+
cov_2l9mmpbx71().s[63]++;
|
|
3395
3395
|
if (typeof thisError === "string") {
|
|
3396
|
-
|
|
3397
|
-
|
|
3396
|
+
cov_2l9mmpbx71().b[43][0]++;
|
|
3397
|
+
cov_2l9mmpbx71().s[64]++;
|
|
3398
3398
|
locales = locales.filter(thisLocale => {
|
|
3399
|
-
|
|
3400
|
-
|
|
3399
|
+
cov_2l9mmpbx71().f[16]++;
|
|
3400
|
+
cov_2l9mmpbx71().s[65]++;
|
|
3401
3401
|
return !thisError.includes(thisLocale);
|
|
3402
3402
|
});
|
|
3403
3403
|
} else {
|
|
3404
|
-
|
|
3404
|
+
cov_2l9mmpbx71().b[43][1]++;
|
|
3405
3405
|
}
|
|
3406
3406
|
}
|
|
3407
3407
|
} catch (e) {
|
|
3408
|
-
|
|
3408
|
+
cov_2l9mmpbx71().s[66]++;
|
|
3409
3409
|
locales = [];
|
|
3410
3410
|
}
|
|
3411
3411
|
// if we removed every locale from the array, it wasn't loaded.
|
|
3412
|
-
|
|
3412
|
+
cov_2l9mmpbx71().s[67]++;
|
|
3413
3413
|
if (locales.length === 0) {
|
|
3414
|
-
|
|
3415
|
-
|
|
3414
|
+
cov_2l9mmpbx71().b[44][0]++;
|
|
3415
|
+
cov_2l9mmpbx71().s[68]++;
|
|
3416
3416
|
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
3417
3417
|
} else {
|
|
3418
|
-
|
|
3418
|
+
cov_2l9mmpbx71().b[44][1]++;
|
|
3419
3419
|
}
|
|
3420
|
-
|
|
3420
|
+
cov_2l9mmpbx71().s[69]++;
|
|
3421
3421
|
resolve();
|
|
3422
3422
|
});
|
|
3423
3423
|
}));
|
|
3424
|
-
|
|
3424
|
+
cov_2l9mmpbx71().s[70]++;
|
|
3425
3425
|
this._namespaces.set(name, theReadPromise);
|
|
3426
|
-
|
|
3426
|
+
cov_2l9mmpbx71().s[71]++;
|
|
3427
3427
|
return theReadPromise;
|
|
3428
3428
|
}
|
|
3429
3429
|
/** @internal */
|
|
3430
3430
|
unregisterNamespace(name) {
|
|
3431
|
-
|
|
3432
|
-
|
|
3431
|
+
cov_2l9mmpbx71().f[17]++;
|
|
3432
|
+
cov_2l9mmpbx71().s[72]++;
|
|
3433
3433
|
this._namespaces.delete(name);
|
|
3434
3434
|
}
|
|
3435
3435
|
}
|
|
3436
|
-
|
|
3436
|
+
cov_2l9mmpbx71().s[73]++;
|
|
3437
3437
|
exports.ITwinLocalization = ITwinLocalization;
|
|
3438
3438
|
class TranslationLogger {
|
|
3439
3439
|
log(args) {
|
|
3440
|
-
|
|
3441
|
-
|
|
3440
|
+
cov_2l9mmpbx71().f[18]++;
|
|
3441
|
+
cov_2l9mmpbx71().s[74]++;
|
|
3442
3442
|
core_bentley_1.Logger.logInfo("i18n", this.createLogMessage(args));
|
|
3443
3443
|
}
|
|
3444
3444
|
warn(args) {
|
|
3445
|
-
|
|
3446
|
-
|
|
3445
|
+
cov_2l9mmpbx71().f[19]++;
|
|
3446
|
+
cov_2l9mmpbx71().s[75]++;
|
|
3447
3447
|
core_bentley_1.Logger.logWarning("i18n", this.createLogMessage(args));
|
|
3448
3448
|
}
|
|
3449
3449
|
error(args) {
|
|
3450
|
-
|
|
3451
|
-
|
|
3450
|
+
cov_2l9mmpbx71().f[20]++;
|
|
3451
|
+
cov_2l9mmpbx71().s[76]++;
|
|
3452
3452
|
core_bentley_1.Logger.logError("i18n", this.createLogMessage(args));
|
|
3453
3453
|
}
|
|
3454
3454
|
createLogMessage(args) {
|
|
3455
|
-
|
|
3456
|
-
let message = (
|
|
3457
|
-
|
|
3458
|
-
for (let i = (
|
|
3459
|
-
|
|
3455
|
+
cov_2l9mmpbx71().f[21]++;
|
|
3456
|
+
let message = (cov_2l9mmpbx71().s[77]++, args[0]);
|
|
3457
|
+
cov_2l9mmpbx71().s[78]++;
|
|
3458
|
+
for (let i = (cov_2l9mmpbx71().s[79]++, 1); i < args.length; ++i) {
|
|
3459
|
+
cov_2l9mmpbx71().s[80]++;
|
|
3460
3460
|
if (typeof args[i] === "string") {
|
|
3461
|
-
|
|
3462
|
-
|
|
3461
|
+
cov_2l9mmpbx71().b[45][0]++;
|
|
3462
|
+
cov_2l9mmpbx71().s[81]++;
|
|
3463
3463
|
message += `\n ${args[i]}`;
|
|
3464
3464
|
} else {
|
|
3465
|
-
|
|
3465
|
+
cov_2l9mmpbx71().b[45][1]++;
|
|
3466
3466
|
}
|
|
3467
3467
|
}
|
|
3468
|
-
|
|
3468
|
+
cov_2l9mmpbx71().s[82]++;
|
|
3469
3469
|
return message;
|
|
3470
3470
|
}
|
|
3471
3471
|
}
|
|
3472
|
-
|
|
3472
|
+
cov_2l9mmpbx71().s[83]++;
|
|
3473
3473
|
TranslationLogger.type = "logger";
|
|
3474
3474
|
|
|
3475
3475
|
/***/ }),
|
|
@@ -14296,8 +14296,8 @@ module.exports = getFuncName;
|
|
|
14296
14296
|
"use strict";
|
|
14297
14297
|
|
|
14298
14298
|
|
|
14299
|
-
var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14300
|
-
var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14299
|
+
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");
|
|
14300
|
+
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");
|
|
14301
14301
|
|
|
14302
14302
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14303
14303
|
|
|
@@ -14729,15 +14729,15 @@ module.exports = Browser;
|
|
|
14729
14729
|
"use strict";
|
|
14730
14730
|
|
|
14731
14731
|
|
|
14732
|
-
var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14733
|
-
var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14734
|
-
var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14735
|
-
var _assertThisInitialized = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14736
|
-
var _inherits = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14737
|
-
var _possibleConstructorReturn = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14738
|
-
var _getPrototypeOf = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14739
|
-
var _defineProperty = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14740
|
-
var _toArray = __webpack_require__(/*! @babel/runtime/helpers/toArray */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
14732
|
+
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");
|
|
14733
|
+
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");
|
|
14734
|
+
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");
|
|
14735
|
+
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");
|
|
14736
|
+
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");
|
|
14737
|
+
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");
|
|
14738
|
+
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");
|
|
14739
|
+
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");
|
|
14740
|
+
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");
|
|
14741
14741
|
|
|
14742
14742
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14743
14743
|
|
|
@@ -23939,6 +23939,12 @@ class ReadonlySortedArray {
|
|
|
23939
23939
|
for (let i = 0; i < this.length; i++)
|
|
23940
23940
|
func(this._array[i]);
|
|
23941
23941
|
}
|
|
23942
|
+
/** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
|
|
23943
|
+
slice(start, end) {
|
|
23944
|
+
const slice = new ReadonlySortedArray(this._compare, this._duplicatePolicy, this._clone);
|
|
23945
|
+
slice._array = this._array.slice(start, end);
|
|
23946
|
+
return slice;
|
|
23947
|
+
}
|
|
23942
23948
|
/**
|
|
23943
23949
|
* Computes the position at which the specified value should be inserted to maintain sorted order.
|
|
23944
23950
|
* @param value The value whose position is to be computed.
|
|
@@ -24069,6 +24075,12 @@ class SortedArray extends ReadonlySortedArray {
|
|
|
24069
24075
|
* @returns the index of the deleted value, or -1 if no such element exists.
|
|
24070
24076
|
*/
|
|
24071
24077
|
remove(value) { return this._remove(value); }
|
|
24078
|
+
/** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
|
|
24079
|
+
slice(start, end) {
|
|
24080
|
+
const slice = new SortedArray(this._compare, this._duplicatePolicy, this._clone);
|
|
24081
|
+
slice._array = this._array.slice(start, end);
|
|
24082
|
+
return slice;
|
|
24083
|
+
}
|
|
24072
24084
|
}
|
|
24073
24085
|
|
|
24074
24086
|
|
|
@@ -25800,10 +25812,10 @@ function partitionArray(array, criterion) {
|
|
|
25800
25812
|
|
|
25801
25813
|
/***/ }),
|
|
25802
25814
|
|
|
25803
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25804
|
-
|
|
25805
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25806
|
-
|
|
25815
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js":
|
|
25816
|
+
/*!**************************************************************************************************************************!*\
|
|
25817
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***!
|
|
25818
|
+
\**************************************************************************************************************************/
|
|
25807
25819
|
/***/ ((module) => {
|
|
25808
25820
|
|
|
25809
25821
|
function _arrayLikeToArray(arr, len) {
|
|
@@ -25815,10 +25827,10 @@ module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exp
|
|
|
25815
25827
|
|
|
25816
25828
|
/***/ }),
|
|
25817
25829
|
|
|
25818
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25819
|
-
|
|
25820
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25821
|
-
|
|
25830
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js":
|
|
25831
|
+
/*!************************************************************************************************************************!*\
|
|
25832
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js ***!
|
|
25833
|
+
\************************************************************************************************************************/
|
|
25822
25834
|
/***/ ((module) => {
|
|
25823
25835
|
|
|
25824
25836
|
function _arrayWithHoles(arr) {
|
|
@@ -25828,10 +25840,10 @@ module.exports = _arrayWithHoles, module.exports.__esModule = true, module.expor
|
|
|
25828
25840
|
|
|
25829
25841
|
/***/ }),
|
|
25830
25842
|
|
|
25831
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25832
|
-
|
|
25833
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25834
|
-
|
|
25843
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js":
|
|
25844
|
+
/*!*******************************************************************************************************************************!*\
|
|
25845
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js ***!
|
|
25846
|
+
\*******************************************************************************************************************************/
|
|
25835
25847
|
/***/ ((module) => {
|
|
25836
25848
|
|
|
25837
25849
|
function _assertThisInitialized(self) {
|
|
@@ -25844,10 +25856,10 @@ module.exports = _assertThisInitialized, module.exports.__esModule = true, modul
|
|
|
25844
25856
|
|
|
25845
25857
|
/***/ }),
|
|
25846
25858
|
|
|
25847
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25848
|
-
|
|
25849
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25850
|
-
|
|
25859
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/classCallCheck.js":
|
|
25860
|
+
/*!************************************************************************************************************************!*\
|
|
25861
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/classCallCheck.js ***!
|
|
25862
|
+
\************************************************************************************************************************/
|
|
25851
25863
|
/***/ ((module) => {
|
|
25852
25864
|
|
|
25853
25865
|
function _classCallCheck(instance, Constructor) {
|
|
@@ -25859,13 +25871,13 @@ module.exports = _classCallCheck, module.exports.__esModule = true, module.expor
|
|
|
25859
25871
|
|
|
25860
25872
|
/***/ }),
|
|
25861
25873
|
|
|
25862
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25863
|
-
|
|
25864
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25865
|
-
|
|
25874
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/createClass.js":
|
|
25875
|
+
/*!*********************************************************************************************************************!*\
|
|
25876
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/createClass.js ***!
|
|
25877
|
+
\*********************************************************************************************************************/
|
|
25866
25878
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
25867
25879
|
|
|
25868
|
-
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25880
|
+
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js");
|
|
25869
25881
|
function _defineProperties(target, props) {
|
|
25870
25882
|
for (var i = 0; i < props.length; i++) {
|
|
25871
25883
|
var descriptor = props[i];
|
|
@@ -25887,13 +25899,13 @@ module.exports = _createClass, module.exports.__esModule = true, module.exports[
|
|
|
25887
25899
|
|
|
25888
25900
|
/***/ }),
|
|
25889
25901
|
|
|
25890
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25891
|
-
|
|
25892
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25893
|
-
|
|
25902
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/defineProperty.js":
|
|
25903
|
+
/*!************************************************************************************************************************!*\
|
|
25904
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/defineProperty.js ***!
|
|
25905
|
+
\************************************************************************************************************************/
|
|
25894
25906
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
25895
25907
|
|
|
25896
|
-
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25908
|
+
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js");
|
|
25897
25909
|
function _defineProperty(obj, key, value) {
|
|
25898
25910
|
key = toPropertyKey(key);
|
|
25899
25911
|
if (key in obj) {
|
|
@@ -25912,10 +25924,10 @@ module.exports = _defineProperty, module.exports.__esModule = true, module.expor
|
|
|
25912
25924
|
|
|
25913
25925
|
/***/ }),
|
|
25914
25926
|
|
|
25915
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25916
|
-
|
|
25917
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25918
|
-
|
|
25927
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js":
|
|
25928
|
+
/*!************************************************************************************************************************!*\
|
|
25929
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js ***!
|
|
25930
|
+
\************************************************************************************************************************/
|
|
25919
25931
|
/***/ ((module) => {
|
|
25920
25932
|
|
|
25921
25933
|
function _getPrototypeOf(o) {
|
|
@@ -25928,13 +25940,13 @@ module.exports = _getPrototypeOf, module.exports.__esModule = true, module.expor
|
|
|
25928
25940
|
|
|
25929
25941
|
/***/ }),
|
|
25930
25942
|
|
|
25931
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25932
|
-
|
|
25933
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25934
|
-
|
|
25943
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/inherits.js":
|
|
25944
|
+
/*!******************************************************************************************************************!*\
|
|
25945
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/inherits.js ***!
|
|
25946
|
+
\******************************************************************************************************************/
|
|
25935
25947
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
25936
25948
|
|
|
25937
|
-
var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25949
|
+
var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js");
|
|
25938
25950
|
function _inherits(subClass, superClass) {
|
|
25939
25951
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
25940
25952
|
throw new TypeError("Super expression must either be null or a function");
|
|
@@ -25955,10 +25967,10 @@ module.exports = _inherits, module.exports.__esModule = true, module.exports["de
|
|
|
25955
25967
|
|
|
25956
25968
|
/***/ }),
|
|
25957
25969
|
|
|
25958
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25959
|
-
|
|
25960
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25961
|
-
|
|
25970
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/iterableToArray.js":
|
|
25971
|
+
/*!*************************************************************************************************************************!*\
|
|
25972
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/iterableToArray.js ***!
|
|
25973
|
+
\*************************************************************************************************************************/
|
|
25962
25974
|
/***/ ((module) => {
|
|
25963
25975
|
|
|
25964
25976
|
function _iterableToArray(iter) {
|
|
@@ -25968,10 +25980,10 @@ module.exports = _iterableToArray, module.exports.__esModule = true, module.expo
|
|
|
25968
25980
|
|
|
25969
25981
|
/***/ }),
|
|
25970
25982
|
|
|
25971
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25972
|
-
|
|
25973
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25974
|
-
|
|
25983
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/nonIterableRest.js":
|
|
25984
|
+
/*!*************************************************************************************************************************!*\
|
|
25985
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/nonIterableRest.js ***!
|
|
25986
|
+
\*************************************************************************************************************************/
|
|
25975
25987
|
/***/ ((module) => {
|
|
25976
25988
|
|
|
25977
25989
|
function _nonIterableRest() {
|
|
@@ -25981,14 +25993,14 @@ module.exports = _nonIterableRest, module.exports.__esModule = true, module.expo
|
|
|
25981
25993
|
|
|
25982
25994
|
/***/ }),
|
|
25983
25995
|
|
|
25984
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25985
|
-
|
|
25986
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25987
|
-
|
|
25996
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js":
|
|
25997
|
+
/*!***********************************************************************************************************************************!*\
|
|
25998
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***!
|
|
25999
|
+
\***********************************************************************************************************************************/
|
|
25988
26000
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
25989
26001
|
|
|
25990
|
-
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
25991
|
-
var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26002
|
+
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
|
|
26003
|
+
var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
|
|
25992
26004
|
function _possibleConstructorReturn(self, call) {
|
|
25993
26005
|
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
25994
26006
|
return call;
|
|
@@ -26001,10 +26013,10 @@ module.exports = _possibleConstructorReturn, module.exports.__esModule = true, m
|
|
|
26001
26013
|
|
|
26002
26014
|
/***/ }),
|
|
26003
26015
|
|
|
26004
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26005
|
-
|
|
26006
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26007
|
-
|
|
26016
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js":
|
|
26017
|
+
/*!************************************************************************************************************************!*\
|
|
26018
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js ***!
|
|
26019
|
+
\************************************************************************************************************************/
|
|
26008
26020
|
/***/ ((module) => {
|
|
26009
26021
|
|
|
26010
26022
|
function _setPrototypeOf(o, p) {
|
|
@@ -26018,16 +26030,16 @@ module.exports = _setPrototypeOf, module.exports.__esModule = true, module.expor
|
|
|
26018
26030
|
|
|
26019
26031
|
/***/ }),
|
|
26020
26032
|
|
|
26021
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26022
|
-
|
|
26023
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26024
|
-
|
|
26033
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toArray.js":
|
|
26034
|
+
/*!*****************************************************************************************************************!*\
|
|
26035
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toArray.js ***!
|
|
26036
|
+
\*****************************************************************************************************************/
|
|
26025
26037
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
26026
26038
|
|
|
26027
|
-
var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26028
|
-
var iterableToArray = __webpack_require__(/*! ./iterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26029
|
-
var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26030
|
-
var nonIterableRest = __webpack_require__(/*! ./nonIterableRest.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26039
|
+
var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js");
|
|
26040
|
+
var iterableToArray = __webpack_require__(/*! ./iterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/iterableToArray.js");
|
|
26041
|
+
var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js");
|
|
26042
|
+
var nonIterableRest = __webpack_require__(/*! ./nonIterableRest.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/nonIterableRest.js");
|
|
26031
26043
|
function _toArray(arr) {
|
|
26032
26044
|
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest();
|
|
26033
26045
|
}
|
|
@@ -26035,13 +26047,13 @@ module.exports = _toArray, module.exports.__esModule = true, module.exports["def
|
|
|
26035
26047
|
|
|
26036
26048
|
/***/ }),
|
|
26037
26049
|
|
|
26038
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26039
|
-
|
|
26040
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26041
|
-
|
|
26050
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPrimitive.js":
|
|
26051
|
+
/*!*********************************************************************************************************************!*\
|
|
26052
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPrimitive.js ***!
|
|
26053
|
+
\*********************************************************************************************************************/
|
|
26042
26054
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
26043
26055
|
|
|
26044
|
-
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26056
|
+
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
|
|
26045
26057
|
function _toPrimitive(input, hint) {
|
|
26046
26058
|
if (_typeof(input) !== "object" || input === null) return input;
|
|
26047
26059
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -26056,14 +26068,14 @@ module.exports = _toPrimitive, module.exports.__esModule = true, module.exports[
|
|
|
26056
26068
|
|
|
26057
26069
|
/***/ }),
|
|
26058
26070
|
|
|
26059
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26060
|
-
|
|
26061
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26062
|
-
|
|
26071
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js":
|
|
26072
|
+
/*!***********************************************************************************************************************!*\
|
|
26073
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPropertyKey.js ***!
|
|
26074
|
+
\***********************************************************************************************************************/
|
|
26063
26075
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
26064
26076
|
|
|
26065
|
-
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26066
|
-
var toPrimitive = __webpack_require__(/*! ./toPrimitive.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26077
|
+
var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
|
|
26078
|
+
var toPrimitive = __webpack_require__(/*! ./toPrimitive.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/toPrimitive.js");
|
|
26067
26079
|
function _toPropertyKey(arg) {
|
|
26068
26080
|
var key = toPrimitive(arg, "string");
|
|
26069
26081
|
return _typeof(key) === "symbol" ? key : String(key);
|
|
@@ -26072,10 +26084,10 @@ module.exports = _toPropertyKey, module.exports.__esModule = true, module.export
|
|
|
26072
26084
|
|
|
26073
26085
|
/***/ }),
|
|
26074
26086
|
|
|
26075
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26076
|
-
|
|
26077
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26078
|
-
|
|
26087
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js":
|
|
26088
|
+
/*!****************************************************************************************************************!*\
|
|
26089
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/typeof.js ***!
|
|
26090
|
+
\****************************************************************************************************************/
|
|
26079
26091
|
/***/ ((module) => {
|
|
26080
26092
|
|
|
26081
26093
|
function _typeof(obj) {
|
|
@@ -26091,13 +26103,13 @@ module.exports = _typeof, module.exports.__esModule = true, module.exports["defa
|
|
|
26091
26103
|
|
|
26092
26104
|
/***/ }),
|
|
26093
26105
|
|
|
26094
|
-
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26095
|
-
|
|
26096
|
-
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26097
|
-
|
|
26106
|
+
/***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js":
|
|
26107
|
+
/*!************************************************************************************************************************************!*\
|
|
26108
|
+
!*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***!
|
|
26109
|
+
\************************************************************************************************************************************/
|
|
26098
26110
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
26099
26111
|
|
|
26100
|
-
var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.
|
|
26112
|
+
var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.21.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js");
|
|
26101
26113
|
function _unsupportedIterableToArray(o, minLen) {
|
|
26102
26114
|
if (!o) return;
|
|
26103
26115
|
if (typeof o === "string") return arrayLikeToArray(o, minLen);
|
|
@@ -26618,874 +26630,874 @@ var exports = __webpack_exports__;
|
|
|
26618
26630
|
/*!************************************************!*\
|
|
26619
26631
|
!*** ./lib/cjs/test/ITwinLocalization.test.js ***!
|
|
26620
26632
|
\************************************************/
|
|
26621
|
-
|
|
26622
|
-
/*---------------------------------------------------------------------------------------------
|
|
26623
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
26624
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26625
|
-
*--------------------------------------------------------------------------------------------*/
|
|
26626
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
26627
|
-
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.3.7/node_modules/chai/index.js");
|
|
26628
|
-
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
26629
|
-
describe("ITwinLocalization", () => {
|
|
26630
|
-
let localization;
|
|
26631
|
-
let germanLocalization;
|
|
26632
|
-
describe("#constructor", () => {
|
|
26633
|
-
let itwinLocalization;
|
|
26634
|
-
it("set default namespace", async () => {
|
|
26635
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
26636
|
-
await itwinLocalization.initialize([]);
|
|
26637
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26638
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26639
|
-
});
|
|
26640
|
-
it("set default language as english", async () => {
|
|
26641
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "en" } });
|
|
26642
|
-
await itwinLocalization.initialize([]);
|
|
26643
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "en");
|
|
26644
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26645
|
-
});
|
|
26646
|
-
it("set default language as NOT english", async () => {
|
|
26647
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "de" } });
|
|
26648
|
-
await itwinLocalization.initialize([]);
|
|
26649
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "de");
|
|
26650
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
26651
|
-
});
|
|
26652
|
-
it("set fallback language as NOT english", async () => {
|
|
26653
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", fallbackLng: "de" } });
|
|
26654
|
-
await itwinLocalization.initialize([]);
|
|
26655
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.fallbackLng, "de");
|
|
26656
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("OnlyGerman"), "Hallo");
|
|
26657
|
-
});
|
|
26658
|
-
});
|
|
26659
|
-
describe("#initialize", () => {
|
|
26660
|
-
let itwinLocalization;
|
|
26661
|
-
it("cannot fetch from unregistered namespaces", async () => {
|
|
26662
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26663
|
-
await localization.initialize([]);
|
|
26664
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "FirstTrivial");
|
|
26665
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "FirstTrivial");
|
|
26666
|
-
});
|
|
26667
|
-
describe("with no default namespace predefined", () => {
|
|
26668
|
-
before(() => {
|
|
26669
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
26670
|
-
});
|
|
26671
|
-
it("no default namespace set when initialized with empty array", async () => {
|
|
26672
|
-
await itwinLocalization.initialize([]);
|
|
26673
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, undefined);
|
|
26674
|
-
});
|
|
26675
|
-
it("initialize with single namespace", async () => {
|
|
26676
|
-
var _a;
|
|
26677
|
-
await itwinLocalization.initialize(["Test"]);
|
|
26678
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Test");
|
|
26679
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Test"));
|
|
26680
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26681
|
-
});
|
|
26682
|
-
it("initialize with two namespaces recognizes both namespaces", async () => {
|
|
26683
|
-
var _a, _b;
|
|
26684
|
-
await itwinLocalization.initialize(["Default", "Test"]);
|
|
26685
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26686
|
-
chai_1.assert.isTrue((_b = itwinLocalization.i18next.options.ns) === null || _b === void 0 ? void 0 : _b.includes("Test"));
|
|
26687
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26688
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26689
|
-
});
|
|
26690
|
-
it("initialize with two namespaces sets first as default", async () => {
|
|
26691
|
-
await itwinLocalization.initialize(["Default", "Test"]);
|
|
26692
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26693
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26694
|
-
});
|
|
26695
|
-
it("initialize with duplicate namespace values does not break anything", async () => {
|
|
26696
|
-
var _a;
|
|
26697
|
-
await itwinLocalization.initialize(["Default", "Default"]);
|
|
26698
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26699
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26700
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26701
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26702
|
-
});
|
|
26703
|
-
});
|
|
26704
|
-
describe("with default namespace", () => {
|
|
26705
|
-
before(() => {
|
|
26706
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
26707
|
-
});
|
|
26708
|
-
it("default namespace set when initialized with empty array", async () => {
|
|
26709
|
-
await itwinLocalization.initialize([]);
|
|
26710
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26711
|
-
});
|
|
26712
|
-
it("default namespace not overridden by one namespace", async () => {
|
|
26713
|
-
await itwinLocalization.initialize(["Test"]);
|
|
26714
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26715
|
-
});
|
|
26716
|
-
it("default namespace not overridden by two namespaces", async () => {
|
|
26717
|
-
await itwinLocalization.initialize(["NotExist", "Test"]);
|
|
26718
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26719
|
-
});
|
|
26720
|
-
it("duplicate namespace value does not break default namespace", async () => {
|
|
26721
|
-
await itwinLocalization.initialize(["Default"]);
|
|
26722
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26723
|
-
});
|
|
26724
|
-
it("default namespace is in list of all namespaces initalized with empty array", async () => {
|
|
26725
|
-
var _a;
|
|
26726
|
-
await itwinLocalization.initialize([]);
|
|
26727
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26728
|
-
});
|
|
26729
|
-
it("default namespace is in list of all namespaces", async () => {
|
|
26730
|
-
var _a;
|
|
26731
|
-
await itwinLocalization.initialize(["Test"]);
|
|
26732
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26733
|
-
});
|
|
26734
|
-
});
|
|
26735
|
-
});
|
|
26736
|
-
describe("#getLocalizedKeys", () => {
|
|
26737
|
-
before(async () => {
|
|
26738
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26739
|
-
await localization.initialize(["Default", "Test"]);
|
|
26740
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
26741
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
26742
|
-
});
|
|
26743
|
-
it("no substitution", () => {
|
|
26744
|
-
chai_1.assert.equal(localization.getLocalizedKeys("MyString"), "MyString");
|
|
26745
|
-
});
|
|
26746
|
-
describe("Default Namespace", () => {
|
|
26747
|
-
it("first level string", () => {
|
|
26748
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default)");
|
|
26749
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default german)");
|
|
26750
|
-
});
|
|
26751
|
-
it("second level string", () => {
|
|
26752
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
26753
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
26754
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default german)");
|
|
26755
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default german)");
|
|
26756
|
-
});
|
|
26757
|
-
it("first level string with keys", () => {
|
|
26758
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default)");
|
|
26759
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
26760
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default german)");
|
|
26761
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default german)");
|
|
26762
|
-
});
|
|
26763
|
-
it("second level string with keys", () => {
|
|
26764
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
26765
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
26766
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default german)");
|
|
26767
|
-
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default german)");
|
|
26768
|
-
});
|
|
26769
|
-
it("first level missing key doesn't find a value", () => {
|
|
26770
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
26771
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
26772
|
-
});
|
|
26773
|
-
it("second level missing key doesn't find a value", () => {
|
|
26774
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
26775
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
26776
|
-
});
|
|
26777
|
-
});
|
|
26778
|
-
describe("Given Namespace", () => {
|
|
26779
|
-
it("first level string", () => {
|
|
26780
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:FirstTrivial}"), "hi First level string (default)");
|
|
26781
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:FirstTrivial}"), "hi First level string (test)");
|
|
26782
|
-
});
|
|
26783
|
-
it("second level string", () => {
|
|
26784
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
26785
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
26786
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondTrivial.Test1}"), "Second level string 1 (test)");
|
|
26787
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:SecondTrivial.Test2}"), "bye Second level string 2 (test)");
|
|
26788
|
-
});
|
|
26789
|
-
it("first level string with keys", () => {
|
|
26790
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:FirstSubstitution1}"), "First level {{str}} (default)");
|
|
26791
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
26792
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:FirstSubstitution1}"), "First level {{str}} (test)");
|
|
26793
|
-
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (test)");
|
|
26794
|
-
});
|
|
26795
|
-
it("second level string with keys", () => {
|
|
26796
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
26797
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
26798
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (test)");
|
|
26799
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (test)");
|
|
26800
|
-
});
|
|
26801
|
-
it("first level missing key doesn't find a value", () => {
|
|
26802
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{Default:MissingKeyString}"), "no MissingKeyString");
|
|
26803
|
-
chai_1.assert.equal(localization.getLocalizedKeys("no %{Test:MissingKeyString}"), "no MissingKeyString");
|
|
26804
|
-
});
|
|
26805
|
-
it("second level missing key doesn't find a value", () => {
|
|
26806
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
26807
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
26808
|
-
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
26809
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
26810
|
-
});
|
|
26811
|
-
});
|
|
26812
|
-
describe("Nonexisting Namespace", () => {
|
|
26813
|
-
it("first level fails", () => {
|
|
26814
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:FirstTrivial}"), "FirstTrivial");
|
|
26815
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:MissingKeyString}"), "MissingKeyString");
|
|
26816
|
-
});
|
|
26817
|
-
it("second level fails", () => {
|
|
26818
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:SecondTrivial.Test1}"), "SecondTrivial.Test1");
|
|
26819
|
-
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:Missing.String}"), "Missing.String");
|
|
26820
|
-
});
|
|
26821
|
-
});
|
|
26822
|
-
});
|
|
26823
|
-
// The goal is not to test i18next's interpolation,
|
|
26824
|
-
// but just to have some simple tests to make sure the
|
|
26825
|
-
// basics work through the ITwinLocalization class.
|
|
26826
|
-
// For interpolation options, see: https://www.i18next.com/translation-function/interpolation
|
|
26827
|
-
describe("#getLocalizedString", () => {
|
|
26828
|
-
before(async () => {
|
|
26829
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26830
|
-
await localization.initialize(["Default", "Test"]);
|
|
26831
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
26832
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
26833
|
-
});
|
|
26834
|
-
describe("Default Namespace", () => {
|
|
26835
|
-
it("first level with no substitution", () => {
|
|
26836
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26837
|
-
});
|
|
26838
|
-
it("first level with no substitution with fallback keys", () => {
|
|
26839
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
26840
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default)");
|
|
26841
|
-
});
|
|
26842
|
-
it("more than two fallback keys succeeds", () => {
|
|
26843
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist1", "NotExist2"]), "First level string (default)");
|
|
26844
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "FirstTrivial", "NotExist2"]), "First level string (default)");
|
|
26845
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "NotExist2", "FirstTrivial"]), "First level string (default)");
|
|
26846
|
-
chai_1.assert.equal(localization.getLocalizedString(["1", "2", "3", "4", "5", "FirstTrivial"]), "First level string (default)");
|
|
26847
|
-
});
|
|
26848
|
-
it("second level with no substitution", () => {
|
|
26849
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26850
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26851
|
-
});
|
|
26852
|
-
it("second level with no substitution with fallback keys", () => {
|
|
26853
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
26854
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default)");
|
|
26855
|
-
});
|
|
26856
|
-
it("first level with substitution", () => {
|
|
26857
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26858
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26859
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26860
|
-
});
|
|
26861
|
-
it("first level with substitution with fallback keys", () => {
|
|
26862
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26863
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26864
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26865
|
-
});
|
|
26866
|
-
it("second level with substitution", () => {
|
|
26867
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26868
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26869
|
-
});
|
|
26870
|
-
it("second level with substitution with fallback keys", () => {
|
|
26871
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26872
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26873
|
-
});
|
|
26874
|
-
it("first level missing key doesn't find a value", () => {
|
|
26875
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
26876
|
-
});
|
|
26877
|
-
it("first level missing all keys doesn't find a value", () => {
|
|
26878
|
-
chai_1.assert.equal(localization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
26879
|
-
});
|
|
26880
|
-
it("second level missing key doesn't find a value", () => {
|
|
26881
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26882
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "MissingKeyObject.MissingString"]), "MissingKeyObject.MissingString");
|
|
26883
|
-
});
|
|
26884
|
-
it("read from en-US fallback", () => {
|
|
26885
|
-
chai_1.assert.equal(localization.getLocalizedString("OnlyEnglishUS"), "HelloUS");
|
|
26886
|
-
});
|
|
26887
|
-
});
|
|
26888
|
-
describe("Default Namespace (German)", () => {
|
|
26889
|
-
it("first level with no substitution", () => {
|
|
26890
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
26891
|
-
});
|
|
26892
|
-
it("first level with no substitution with fallback keys", () => {
|
|
26893
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default german)");
|
|
26894
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default german)");
|
|
26895
|
-
});
|
|
26896
|
-
it("second level with no substitution", () => {
|
|
26897
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
26898
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
26899
|
-
});
|
|
26900
|
-
it("second level with no substitution with fallback keys", () => {
|
|
26901
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default german)");
|
|
26902
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default german)");
|
|
26903
|
-
});
|
|
26904
|
-
it("first level with substitution", () => {
|
|
26905
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
26906
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
26907
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
26908
|
-
});
|
|
26909
|
-
it("first level with substitution with fallback keys", () => {
|
|
26910
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
26911
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
26912
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
26913
|
-
});
|
|
26914
|
-
it("second level with substitution", () => {
|
|
26915
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
26916
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
26917
|
-
});
|
|
26918
|
-
it("second level with substitution with fallback keys", () => {
|
|
26919
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
26920
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
26921
|
-
});
|
|
26922
|
-
it("first level missing key doesn't find a value", () => {
|
|
26923
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
26924
|
-
});
|
|
26925
|
-
it("first level missing all keys doesn't find a value", () => {
|
|
26926
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
26927
|
-
});
|
|
26928
|
-
it("second level missing key doesn't find a value", () => {
|
|
26929
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26930
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26931
|
-
});
|
|
26932
|
-
});
|
|
26933
|
-
describe("Given Namespace", () => {
|
|
26934
|
-
it("first level with no substitution", () => {
|
|
26935
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26936
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26937
|
-
});
|
|
26938
|
-
it("first level with no substitution with fallback keys", () => {
|
|
26939
|
-
chai_1.assert.equal(localization.getLocalizedString(["Default:FirstTrivial", "Not:NotExist"]), "First level string (default)");
|
|
26940
|
-
chai_1.assert.equal(localization.getLocalizedString(["Default:NotExist", "Test:FirstTrivial"]), "First level string (test)");
|
|
26941
|
-
});
|
|
26942
|
-
it("second level with no substitution", () => {
|
|
26943
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26944
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26945
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
26946
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
26947
|
-
});
|
|
26948
|
-
it("second level with no substitution with fallback keys", () => {
|
|
26949
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
26950
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
26951
|
-
});
|
|
26952
|
-
it("first level with substitution", () => {
|
|
26953
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26954
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26955
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26956
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
26957
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
26958
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
26959
|
-
});
|
|
26960
|
-
it("first level with substitution with fallback keys", () => {
|
|
26961
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26962
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:FirstSubstitution1", "Default:NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
26963
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26964
|
-
});
|
|
26965
|
-
it("second level with substitution", () => {
|
|
26966
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26967
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26968
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
26969
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
26970
|
-
});
|
|
26971
|
-
it("second level with substitution with fallback keys", () => {
|
|
26972
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26973
|
-
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondSubstitution.Test2", "Default:NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
26974
|
-
});
|
|
26975
|
-
it("first level missing key doesn't find a value", () => {
|
|
26976
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
26977
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
26978
|
-
});
|
|
26979
|
-
it("second level missing key doesn't find a value", () => {
|
|
26980
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26981
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26982
|
-
});
|
|
26983
|
-
it("read from en-US fallback", () => {
|
|
26984
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:OnlyEnglishUS"), "HelloUS");
|
|
26985
|
-
});
|
|
26986
|
-
});
|
|
26987
|
-
describe("Given Namespace (German)", () => {
|
|
26988
|
-
it("first level with no substitution", () => {
|
|
26989
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default german)");
|
|
26990
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (german)");
|
|
26991
|
-
});
|
|
26992
|
-
it("second level with no substitution", () => {
|
|
26993
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
26994
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
26995
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (german)");
|
|
26996
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (german)");
|
|
26997
|
-
});
|
|
26998
|
-
it("first level with substitution", () => {
|
|
26999
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
27000
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
27001
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
27002
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
27003
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
27004
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
27005
|
-
});
|
|
27006
|
-
it("second level with substitution", () => {
|
|
27007
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
27008
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
27009
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
27010
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
27011
|
-
});
|
|
27012
|
-
it("first level missing key doesn't find a value", () => {
|
|
27013
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
27014
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
27015
|
-
});
|
|
27016
|
-
it("second level missing key doesn't find a value", () => {
|
|
27017
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
27018
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
27019
|
-
});
|
|
27020
|
-
});
|
|
27021
|
-
describe("Nonexisting Namespace", () => {
|
|
27022
|
-
it("first level fails", () => {
|
|
27023
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
|
|
27024
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
|
|
27025
|
-
});
|
|
27026
|
-
it("second level fails", () => {
|
|
27027
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
27028
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
|
|
27029
|
-
});
|
|
27030
|
-
it("fallback key fails", () => {
|
|
27031
|
-
chai_1.assert.equal(localization.getLocalizedString(["Nonexisting:FirstTrivial", "NotExist"]), "NotExist");
|
|
27032
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Nonexisting:Missing.String"]), "Missing.String");
|
|
27033
|
-
});
|
|
27034
|
-
});
|
|
27035
|
-
// Test a few options to make sure they get passed through correctly
|
|
27036
|
-
describe("With Options", () => {
|
|
27037
|
-
it("returnDetails throws error", () => {
|
|
27038
|
-
chai_1.assert.throws(() => {
|
|
27039
|
-
localization.getLocalizedString("X", { returnDetails: true });
|
|
27040
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27041
|
-
});
|
|
27042
|
-
it("returnObjects throws error", () => {
|
|
27043
|
-
chai_1.assert.throws(() => {
|
|
27044
|
-
localization.getLocalizedString("X", { returnObjects: true });
|
|
27045
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27046
|
-
});
|
|
27047
|
-
it("returnDetails and returnObjects throws error", () => {
|
|
27048
|
-
chai_1.assert.throws(() => {
|
|
27049
|
-
localization.getLocalizedString("X", { returnDetails: true, returnObjects: true });
|
|
27050
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27051
|
-
});
|
|
27052
|
-
it("default value", () => {
|
|
27053
|
-
chai_1.assert.equal(localization.getLocalizedString("Missing", { defaultValue: "default" }), "default");
|
|
27054
|
-
});
|
|
27055
|
-
it("override fallback language", () => {
|
|
27056
|
-
// Doesn't fallback to English
|
|
27057
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { fallbackLng: "de" }), "OnlyEnglish");
|
|
27058
|
-
});
|
|
27059
|
-
it("set namespace", () => {
|
|
27060
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
27061
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (test)");
|
|
27062
|
-
});
|
|
27063
|
-
});
|
|
27064
|
-
});
|
|
27065
|
-
describe("#getLocalizedString with namespace passed in as an option", () => {
|
|
27066
|
-
before(async () => {
|
|
27067
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27068
|
-
await localization.initialize(["Default", "Test"]);
|
|
27069
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27070
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
27071
|
-
});
|
|
27072
|
-
describe("Keys Without Namespaces", () => {
|
|
27073
|
-
it("first level with no substitution", () => {
|
|
27074
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
27075
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
27076
|
-
});
|
|
27077
|
-
it("first level with no substitution with fallback keys", () => {
|
|
27078
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Default" }), "First level string (default)");
|
|
27079
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
27080
|
-
});
|
|
27081
|
-
it("second level with no substitution", () => {
|
|
27082
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default)");
|
|
27083
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default)");
|
|
27084
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
27085
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (test)");
|
|
27086
|
-
});
|
|
27087
|
-
it("second level with no substitution with fallback keys", () => {
|
|
27088
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"], { ns: "Default" }), "Second level string 1 (default)");
|
|
27089
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"], { ns: "Test" }), "Second level string 2 (test)");
|
|
27090
|
-
});
|
|
27091
|
-
it("first level with substitution", () => {
|
|
27092
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27093
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
27094
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
27095
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
27096
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27097
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27098
|
-
});
|
|
27099
|
-
it("first level with substitution with fallback keys", () => {
|
|
27100
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27101
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27102
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27103
|
-
});
|
|
27104
|
-
it("second level with substitution", () => {
|
|
27105
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27106
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
27107
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
27108
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27109
|
-
});
|
|
27110
|
-
it("second level with substitution with fallback keys", () => {
|
|
27111
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27112
|
-
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27113
|
-
});
|
|
27114
|
-
it("first level missing key doesn't find a value", () => {
|
|
27115
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
27116
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
27117
|
-
});
|
|
27118
|
-
it("second level missing key doesn't find a value", () => {
|
|
27119
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
27120
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
27121
|
-
});
|
|
27122
|
-
});
|
|
27123
|
-
describe("Keys Without Namespaces (German)", () => {
|
|
27124
|
-
it("first level with no substitution", () => {
|
|
27125
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default german)");
|
|
27126
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (german)");
|
|
27127
|
-
});
|
|
27128
|
-
it("second level with no substitution", () => {
|
|
27129
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default german)");
|
|
27130
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default german)");
|
|
27131
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (german)");
|
|
27132
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (german)");
|
|
27133
|
-
});
|
|
27134
|
-
it("first level with substitution", () => {
|
|
27135
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
27136
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
27137
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
27138
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
27139
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
27140
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
27141
|
-
});
|
|
27142
|
-
it("second level with substitution", () => {
|
|
27143
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
27144
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
27145
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
27146
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
27147
|
-
});
|
|
27148
|
-
it("first level missing key doesn't find a value", () => {
|
|
27149
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
27150
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
27151
|
-
});
|
|
27152
|
-
it("second level missing key doesn't find a value", () => {
|
|
27153
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
27154
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
27155
|
-
});
|
|
27156
|
-
});
|
|
27157
|
-
describe("Keys With Namespaces", () => {
|
|
27158
|
-
it("key with same namespace works", () => {
|
|
27159
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
27160
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
27161
|
-
});
|
|
27162
|
-
it("key with different namespace overrides given namespace", () => {
|
|
27163
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Default" }), "First level string (test)");
|
|
27164
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
27165
|
-
});
|
|
27166
|
-
it("key with same namespace works with fallback keys", () => {
|
|
27167
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Default" }), "First level string (default)");
|
|
27168
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
27169
|
-
});
|
|
27170
|
-
it("key with different namespace overrides given namespace with fallback keys", () => {
|
|
27171
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Default" }), "First level string (test)");
|
|
27172
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Test" }), "First level string (default)");
|
|
27173
|
-
});
|
|
27174
|
-
it("missing key does not find a value", () => {
|
|
27175
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
27176
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString(["Missing1", "MissingKeyObject.MissingString"], { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
27177
|
-
});
|
|
27178
|
-
});
|
|
27179
|
-
describe("Nonexisting Namespace", () => {
|
|
27180
|
-
it("first level fails", () => {
|
|
27181
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Nonexisting" }), "FirstTrivial");
|
|
27182
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Nonexisting" }), "MissingKeyString");
|
|
27183
|
-
});
|
|
27184
|
-
it("second level fails", () => {
|
|
27185
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Nonexisting" }), "SecondTrivial.Test1");
|
|
27186
|
-
chai_1.assert.equal(localization.getLocalizedString("Missing.String", { ns: "Nonexisting" }), "Missing.String");
|
|
27187
|
-
});
|
|
27188
|
-
it("empty string namespace falls back to default namespace", () => {
|
|
27189
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "" }), "First level string (default)");
|
|
27190
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "" }), "Second level string 1 (default)");
|
|
27191
|
-
});
|
|
27192
|
-
it("fallback key fails", () => {
|
|
27193
|
-
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Nonexisting" }), "NotExist");
|
|
27194
|
-
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Missing.String"], { ns: "Nonexisting" }), "Missing.String");
|
|
27195
|
-
});
|
|
27196
|
-
it("use key with valid namespace instead", () => {
|
|
27197
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Nonexisting" }), "First level string (default)");
|
|
27198
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Nonexisting" }), "First level string (test)");
|
|
27199
|
-
});
|
|
27200
|
-
it("providing key with invalid namespace fails", () => {
|
|
27201
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting2:FirstTrivial", { ns: "Nonexisting1" }), "FirstTrivial");
|
|
27202
|
-
});
|
|
27203
|
-
});
|
|
27204
|
-
// Test a few options to make sure they get passed through correctly
|
|
27205
|
-
describe("With Options", () => {
|
|
27206
|
-
it("returnDetails throws error", () => {
|
|
27207
|
-
chai_1.assert.throws(() => {
|
|
27208
|
-
localization.getLocalizedString("X", { ns: "Default", returnDetails: true });
|
|
27209
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27210
|
-
});
|
|
27211
|
-
it("returnObjects throws error", () => {
|
|
27212
|
-
chai_1.assert.throws(() => {
|
|
27213
|
-
localization.getLocalizedString("X", { ns: "Default", returnObjects: true });
|
|
27214
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27215
|
-
});
|
|
27216
|
-
it("returnDetails and returnObjects throws error", () => {
|
|
27217
|
-
chai_1.assert.throws(() => {
|
|
27218
|
-
localization.getLocalizedString("X", { ns: "Default", returnDetails: true, returnObjects: true });
|
|
27219
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27220
|
-
});
|
|
27221
|
-
it("default value", () => {
|
|
27222
|
-
chai_1.assert.equal(localization.getLocalizedString("Missing", { ns: "Default", defaultValue: "default" }), "default");
|
|
27223
|
-
});
|
|
27224
|
-
it("override fallback language", () => {
|
|
27225
|
-
// Doesn't fallback to English
|
|
27226
|
-
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { ns: "Default", fallbackLng: "de" }), "OnlyEnglish");
|
|
27227
|
-
});
|
|
27228
|
-
});
|
|
27229
|
-
});
|
|
27230
|
-
describe("#getEnglishString", () => {
|
|
27231
|
-
before(async () => {
|
|
27232
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27233
|
-
await localization.initialize(["Default", "Test"]);
|
|
27234
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27235
|
-
await germanLocalization.initialize(["Default", "Test"]);
|
|
27236
|
-
});
|
|
27237
|
-
describe("Given Namespace", () => {
|
|
27238
|
-
it("first level with no substitution", () => {
|
|
27239
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
27240
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
27241
|
-
});
|
|
27242
|
-
it("first level with no substitution with fallback keys", () => {
|
|
27243
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
27244
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
27245
|
-
});
|
|
27246
|
-
it("second level with no substitution", () => {
|
|
27247
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
27248
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
27249
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
27250
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
27251
|
-
});
|
|
27252
|
-
it("second level with no substitution with fallback keys", () => {
|
|
27253
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
27254
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
27255
|
-
});
|
|
27256
|
-
it("first level with substitution", () => {
|
|
27257
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27258
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
27259
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
27260
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
27261
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27262
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27263
|
-
});
|
|
27264
|
-
it("first level with substitution with fallback keys", () => {
|
|
27265
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27266
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27267
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27268
|
-
});
|
|
27269
|
-
it("second level with substitution", () => {
|
|
27270
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27271
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
27272
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
27273
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27274
|
-
});
|
|
27275
|
-
it("second level with substitution with fallback keys", () => {
|
|
27276
|
-
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27277
|
-
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27278
|
-
});
|
|
27279
|
-
it("first level missing key doesn't find a value", () => {
|
|
27280
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
27281
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
27282
|
-
});
|
|
27283
|
-
it("second level missing key doesn't find a value", () => {
|
|
27284
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
27285
|
-
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
27286
|
-
});
|
|
27287
|
-
});
|
|
27288
|
-
describe("Given Namespace with German default language returns English strings", () => {
|
|
27289
|
-
it("first level with no substitution", () => {
|
|
27290
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
27291
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
27292
|
-
});
|
|
27293
|
-
it("first level with no substitution with fallback keys", () => {
|
|
27294
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
27295
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
27296
|
-
});
|
|
27297
|
-
it("second level with no substitution", () => {
|
|
27298
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
27299
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
27300
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
27301
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
27302
|
-
});
|
|
27303
|
-
it("second level with no substitution with fallback keys", () => {
|
|
27304
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
27305
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
27306
|
-
});
|
|
27307
|
-
it("first level with substitution", () => {
|
|
27308
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27309
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
27310
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
27311
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
27312
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27313
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27314
|
-
});
|
|
27315
|
-
it("first level with substitution with fallback keys", () => {
|
|
27316
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27317
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27318
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27319
|
-
});
|
|
27320
|
-
it("second level with substitution", () => {
|
|
27321
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27322
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
27323
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
27324
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27325
|
-
});
|
|
27326
|
-
it("second level with substitution with fallback keys", () => {
|
|
27327
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27328
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27329
|
-
});
|
|
27330
|
-
it("first level missing key doesn't find a value", () => {
|
|
27331
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
27332
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
27333
|
-
});
|
|
27334
|
-
it("second level missing key doesn't find a value", () => {
|
|
27335
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
27336
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
27337
|
-
});
|
|
27338
|
-
});
|
|
27339
|
-
describe("Nonexisting Namespace", () => {
|
|
27340
|
-
it("first level fails", () => {
|
|
27341
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "FirstTrivial"), "FirstTrivial");
|
|
27342
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "MissingKeyString"), "MissingKeyString");
|
|
27343
|
-
});
|
|
27344
|
-
it("second level fails", () => {
|
|
27345
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
27346
|
-
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "Missing.String"), "Missing.String");
|
|
27347
|
-
});
|
|
27348
|
-
it("empty string namespace is treated as default namespace", () => {
|
|
27349
|
-
chai_1.assert.equal(localization.getEnglishString("", "FirstTrivial"), "First level string (default)");
|
|
27350
|
-
chai_1.assert.equal(localization.getEnglishString("", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
27351
|
-
});
|
|
27352
|
-
});
|
|
27353
|
-
// Test a few options to make sure they get passed through correctly
|
|
27354
|
-
describe("With Options", () => {
|
|
27355
|
-
it("returnDetails throws error", () => {
|
|
27356
|
-
chai_1.assert.throws(() => {
|
|
27357
|
-
localization.getEnglishString("Default", "X", { returnDetails: true });
|
|
27358
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27359
|
-
});
|
|
27360
|
-
it("returnObjects throws error", () => {
|
|
27361
|
-
chai_1.assert.throws(() => {
|
|
27362
|
-
localization.getEnglishString("Default", "X", { returnObjects: true });
|
|
27363
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27364
|
-
});
|
|
27365
|
-
it("returnDetails and returnObjects throws error", () => {
|
|
27366
|
-
chai_1.assert.throws(() => {
|
|
27367
|
-
localization.getEnglishString("Default", "X", { returnDetails: true, returnObjects: true });
|
|
27368
|
-
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27369
|
-
});
|
|
27370
|
-
it("default value", () => {
|
|
27371
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "Missing", { defaultValue: "default" }), "default");
|
|
27372
|
-
});
|
|
27373
|
-
it("english takes priority over fallback language", () => {
|
|
27374
|
-
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "OnlyEnglish", { fallbackLng: "de" }), "Hello");
|
|
27375
|
-
});
|
|
27376
|
-
// White box test
|
|
27377
|
-
it("given namespace overrides namespace translation option", () => {
|
|
27378
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
27379
|
-
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
|
|
27380
|
-
});
|
|
27381
|
-
});
|
|
27382
|
-
});
|
|
27383
|
-
// Returned promises never have anything of substance, being only empty or resolving to null...
|
|
27384
|
-
// describe("#getNamespacePromise", () => {
|
|
27385
|
-
// });
|
|
27386
|
-
describe("#getLanguageList", () => {
|
|
27387
|
-
let languages;
|
|
27388
|
-
it("english language list includes en and en-US", async () => {
|
|
27389
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27390
|
-
await localization.initialize([]);
|
|
27391
|
-
languages = localization.getLanguageList();
|
|
27392
|
-
chai_1.assert.isTrue(languages.includes("en-US"));
|
|
27393
|
-
chai_1.assert.isTrue(languages.includes("en"));
|
|
27394
|
-
});
|
|
27395
|
-
it("when non-english language is set as default, that language and english are included in langauge list", async () => {
|
|
27396
|
-
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27397
|
-
await germanLocalization.initialize([]);
|
|
27398
|
-
languages = germanLocalization.getLanguageList();
|
|
27399
|
-
chai_1.assert.isTrue(languages.includes("en"));
|
|
27400
|
-
chai_1.assert.isTrue(languages.includes("de"));
|
|
27401
|
-
});
|
|
27402
|
-
});
|
|
27403
|
-
describe("#changeLanguage", () => {
|
|
27404
|
-
it("change from english to another language", async () => {
|
|
27405
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27406
|
-
await localization.initialize(["Default"]);
|
|
27407
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
27408
|
-
await localization.changeLanguage("de");
|
|
27409
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
27410
|
-
});
|
|
27411
|
-
it("change from another language to english", async () => {
|
|
27412
|
-
localization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27413
|
-
await localization.initialize(["Default"]);
|
|
27414
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
27415
|
-
await localization.changeLanguage("en");
|
|
27416
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
27417
|
-
});
|
|
27418
|
-
});
|
|
27419
|
-
describe("#registerNamespace", () => {
|
|
27420
|
-
let itwinLocalization;
|
|
27421
|
-
beforeEach(async () => {
|
|
27422
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
27423
|
-
});
|
|
27424
|
-
it("can read from namespace after it is registered", async () => {
|
|
27425
|
-
await itwinLocalization.initialize([]);
|
|
27426
|
-
await itwinLocalization.registerNamespace("Test");
|
|
27427
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
27428
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
27429
|
-
});
|
|
27430
|
-
it("zero initial, register one", async () => {
|
|
27431
|
-
await itwinLocalization.initialize([]);
|
|
27432
|
-
await itwinLocalization.registerNamespace("test1");
|
|
27433
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27434
|
-
});
|
|
27435
|
-
it("zero initial, register two", async () => {
|
|
27436
|
-
await itwinLocalization.initialize([]);
|
|
27437
|
-
await itwinLocalization.registerNamespace("test1");
|
|
27438
|
-
await itwinLocalization.registerNamespace("test2");
|
|
27439
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27440
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
27441
|
-
});
|
|
27442
|
-
it("one initial, register one", async () => {
|
|
27443
|
-
await itwinLocalization.initialize(["initial1"]);
|
|
27444
|
-
await itwinLocalization.registerNamespace("test1");
|
|
27445
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27446
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27447
|
-
});
|
|
27448
|
-
it("one initial, register two", async () => {
|
|
27449
|
-
await itwinLocalization.initialize(["initial1"]);
|
|
27450
|
-
await itwinLocalization.registerNamespace("test1");
|
|
27451
|
-
await itwinLocalization.registerNamespace("test2");
|
|
27452
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27453
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
27454
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27455
|
-
});
|
|
27456
|
-
it("two initial, register one", async () => {
|
|
27457
|
-
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
27458
|
-
await itwinLocalization.registerNamespace("test1");
|
|
27459
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27460
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27461
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
27462
|
-
});
|
|
27463
|
-
it("two initial, register two", async () => {
|
|
27464
|
-
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
27465
|
-
await itwinLocalization.registerNamespace("test1");
|
|
27466
|
-
await itwinLocalization.registerNamespace("test2");
|
|
27467
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27468
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27469
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
27470
|
-
});
|
|
27471
|
-
it("register duplicate namespaces", async () => {
|
|
27472
|
-
await itwinLocalization.initialize([]);
|
|
27473
|
-
await itwinLocalization.registerNamespace("Test");
|
|
27474
|
-
await itwinLocalization.registerNamespace("Test");
|
|
27475
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
27476
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
27477
|
-
});
|
|
27478
|
-
it("register duplicate namespace of initial namespace doesn't break anything", async () => {
|
|
27479
|
-
await itwinLocalization.initialize(["Test"]);
|
|
27480
|
-
await itwinLocalization.registerNamespace("Test");
|
|
27481
|
-
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
27482
|
-
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
27483
|
-
});
|
|
27484
|
-
});
|
|
27485
|
-
// unregisterNamespace() isn't used and basically does nothing
|
|
27486
|
-
// describe("#unregisterNamespace", () => {
|
|
27487
|
-
// });
|
|
27488
|
-
});
|
|
26633
|
+
|
|
26634
|
+
/*---------------------------------------------------------------------------------------------
|
|
26635
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
26636
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26637
|
+
*--------------------------------------------------------------------------------------------*/
|
|
26638
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
26639
|
+
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.3.7/node_modules/chai/index.js");
|
|
26640
|
+
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
26641
|
+
describe("ITwinLocalization", () => {
|
|
26642
|
+
let localization;
|
|
26643
|
+
let germanLocalization;
|
|
26644
|
+
describe("#constructor", () => {
|
|
26645
|
+
let itwinLocalization;
|
|
26646
|
+
it("set default namespace", async () => {
|
|
26647
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
26648
|
+
await itwinLocalization.initialize([]);
|
|
26649
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26650
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26651
|
+
});
|
|
26652
|
+
it("set default language as english", async () => {
|
|
26653
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "en" } });
|
|
26654
|
+
await itwinLocalization.initialize([]);
|
|
26655
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "en");
|
|
26656
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26657
|
+
});
|
|
26658
|
+
it("set default language as NOT english", async () => {
|
|
26659
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "de" } });
|
|
26660
|
+
await itwinLocalization.initialize([]);
|
|
26661
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.lng, "de");
|
|
26662
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
26663
|
+
});
|
|
26664
|
+
it("set fallback language as NOT english", async () => {
|
|
26665
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", fallbackLng: "de" } });
|
|
26666
|
+
await itwinLocalization.initialize([]);
|
|
26667
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.fallbackLng, "de");
|
|
26668
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("OnlyGerman"), "Hallo");
|
|
26669
|
+
});
|
|
26670
|
+
});
|
|
26671
|
+
describe("#initialize", () => {
|
|
26672
|
+
let itwinLocalization;
|
|
26673
|
+
it("cannot fetch from unregistered namespaces", async () => {
|
|
26674
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26675
|
+
await localization.initialize([]);
|
|
26676
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "FirstTrivial");
|
|
26677
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "FirstTrivial");
|
|
26678
|
+
});
|
|
26679
|
+
describe("with no default namespace predefined", () => {
|
|
26680
|
+
before(() => {
|
|
26681
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
26682
|
+
});
|
|
26683
|
+
it("no default namespace set when initialized with empty array", async () => {
|
|
26684
|
+
await itwinLocalization.initialize([]);
|
|
26685
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, undefined);
|
|
26686
|
+
});
|
|
26687
|
+
it("initialize with single namespace", async () => {
|
|
26688
|
+
var _a;
|
|
26689
|
+
await itwinLocalization.initialize(["Test"]);
|
|
26690
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Test");
|
|
26691
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Test"));
|
|
26692
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26693
|
+
});
|
|
26694
|
+
it("initialize with two namespaces recognizes both namespaces", async () => {
|
|
26695
|
+
var _a, _b;
|
|
26696
|
+
await itwinLocalization.initialize(["Default", "Test"]);
|
|
26697
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26698
|
+
chai_1.assert.isTrue((_b = itwinLocalization.i18next.options.ns) === null || _b === void 0 ? void 0 : _b.includes("Test"));
|
|
26699
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26700
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26701
|
+
});
|
|
26702
|
+
it("initialize with two namespaces sets first as default", async () => {
|
|
26703
|
+
await itwinLocalization.initialize(["Default", "Test"]);
|
|
26704
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26705
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26706
|
+
});
|
|
26707
|
+
it("initialize with duplicate namespace values does not break anything", async () => {
|
|
26708
|
+
var _a;
|
|
26709
|
+
await itwinLocalization.initialize(["Default", "Default"]);
|
|
26710
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26711
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26712
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26713
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26714
|
+
});
|
|
26715
|
+
});
|
|
26716
|
+
describe("with default namespace", () => {
|
|
26717
|
+
before(() => {
|
|
26718
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
26719
|
+
});
|
|
26720
|
+
it("default namespace set when initialized with empty array", async () => {
|
|
26721
|
+
await itwinLocalization.initialize([]);
|
|
26722
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26723
|
+
});
|
|
26724
|
+
it("default namespace not overridden by one namespace", async () => {
|
|
26725
|
+
await itwinLocalization.initialize(["Test"]);
|
|
26726
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26727
|
+
});
|
|
26728
|
+
it("default namespace not overridden by two namespaces", async () => {
|
|
26729
|
+
await itwinLocalization.initialize(["NotExist", "Test"]);
|
|
26730
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26731
|
+
});
|
|
26732
|
+
it("duplicate namespace value does not break default namespace", async () => {
|
|
26733
|
+
await itwinLocalization.initialize(["Default"]);
|
|
26734
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26735
|
+
});
|
|
26736
|
+
it("default namespace is in list of all namespaces initalized with empty array", async () => {
|
|
26737
|
+
var _a;
|
|
26738
|
+
await itwinLocalization.initialize([]);
|
|
26739
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26740
|
+
});
|
|
26741
|
+
it("default namespace is in list of all namespaces", async () => {
|
|
26742
|
+
var _a;
|
|
26743
|
+
await itwinLocalization.initialize(["Test"]);
|
|
26744
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26745
|
+
});
|
|
26746
|
+
});
|
|
26747
|
+
});
|
|
26748
|
+
describe("#getLocalizedKeys", () => {
|
|
26749
|
+
before(async () => {
|
|
26750
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26751
|
+
await localization.initialize(["Default", "Test"]);
|
|
26752
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
26753
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
26754
|
+
});
|
|
26755
|
+
it("no substitution", () => {
|
|
26756
|
+
chai_1.assert.equal(localization.getLocalizedKeys("MyString"), "MyString");
|
|
26757
|
+
});
|
|
26758
|
+
describe("Default Namespace", () => {
|
|
26759
|
+
it("first level string", () => {
|
|
26760
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default)");
|
|
26761
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default german)");
|
|
26762
|
+
});
|
|
26763
|
+
it("second level string", () => {
|
|
26764
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
26765
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
26766
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default german)");
|
|
26767
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default german)");
|
|
26768
|
+
});
|
|
26769
|
+
it("first level string with keys", () => {
|
|
26770
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default)");
|
|
26771
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
26772
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default german)");
|
|
26773
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default german)");
|
|
26774
|
+
});
|
|
26775
|
+
it("second level string with keys", () => {
|
|
26776
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
26777
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
26778
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default german)");
|
|
26779
|
+
chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default german)");
|
|
26780
|
+
});
|
|
26781
|
+
it("first level missing key doesn't find a value", () => {
|
|
26782
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
26783
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
|
|
26784
|
+
});
|
|
26785
|
+
it("second level missing key doesn't find a value", () => {
|
|
26786
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
26787
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
26788
|
+
});
|
|
26789
|
+
});
|
|
26790
|
+
describe("Given Namespace", () => {
|
|
26791
|
+
it("first level string", () => {
|
|
26792
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:FirstTrivial}"), "hi First level string (default)");
|
|
26793
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:FirstTrivial}"), "hi First level string (test)");
|
|
26794
|
+
});
|
|
26795
|
+
it("second level string", () => {
|
|
26796
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondTrivial.Test1}"), "Second level string 1 (default)");
|
|
26797
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:SecondTrivial.Test2}"), "bye Second level string 2 (default)");
|
|
26798
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondTrivial.Test1}"), "Second level string 1 (test)");
|
|
26799
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:SecondTrivial.Test2}"), "bye Second level string 2 (test)");
|
|
26800
|
+
});
|
|
26801
|
+
it("first level string with keys", () => {
|
|
26802
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:FirstSubstitution1}"), "First level {{str}} (default)");
|
|
26803
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
|
|
26804
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:FirstSubstitution1}"), "First level {{str}} (test)");
|
|
26805
|
+
chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (test)");
|
|
26806
|
+
});
|
|
26807
|
+
it("second level string with keys", () => {
|
|
26808
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
|
|
26809
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
|
|
26810
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (test)");
|
|
26811
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (test)");
|
|
26812
|
+
});
|
|
26813
|
+
it("first level missing key doesn't find a value", () => {
|
|
26814
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{Default:MissingKeyString}"), "no MissingKeyString");
|
|
26815
|
+
chai_1.assert.equal(localization.getLocalizedKeys("no %{Test:MissingKeyString}"), "no MissingKeyString");
|
|
26816
|
+
});
|
|
26817
|
+
it("second level missing key doesn't find a value", () => {
|
|
26818
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
26819
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Default:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
26820
|
+
chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
|
|
26821
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Test:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
|
|
26822
|
+
});
|
|
26823
|
+
});
|
|
26824
|
+
describe("Nonexisting Namespace", () => {
|
|
26825
|
+
it("first level fails", () => {
|
|
26826
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:FirstTrivial}"), "FirstTrivial");
|
|
26827
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:MissingKeyString}"), "MissingKeyString");
|
|
26828
|
+
});
|
|
26829
|
+
it("second level fails", () => {
|
|
26830
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:SecondTrivial.Test1}"), "SecondTrivial.Test1");
|
|
26831
|
+
chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:Missing.String}"), "Missing.String");
|
|
26832
|
+
});
|
|
26833
|
+
});
|
|
26834
|
+
});
|
|
26835
|
+
// The goal is not to test i18next's interpolation,
|
|
26836
|
+
// but just to have some simple tests to make sure the
|
|
26837
|
+
// basics work through the ITwinLocalization class.
|
|
26838
|
+
// For interpolation options, see: https://www.i18next.com/translation-function/interpolation
|
|
26839
|
+
describe("#getLocalizedString", () => {
|
|
26840
|
+
before(async () => {
|
|
26841
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26842
|
+
await localization.initialize(["Default", "Test"]);
|
|
26843
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
26844
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
26845
|
+
});
|
|
26846
|
+
describe("Default Namespace", () => {
|
|
26847
|
+
it("first level with no substitution", () => {
|
|
26848
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26849
|
+
});
|
|
26850
|
+
it("first level with no substitution with fallback keys", () => {
|
|
26851
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
26852
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default)");
|
|
26853
|
+
});
|
|
26854
|
+
it("more than two fallback keys succeeds", () => {
|
|
26855
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist1", "NotExist2"]), "First level string (default)");
|
|
26856
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "FirstTrivial", "NotExist2"]), "First level string (default)");
|
|
26857
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "NotExist2", "FirstTrivial"]), "First level string (default)");
|
|
26858
|
+
chai_1.assert.equal(localization.getLocalizedString(["1", "2", "3", "4", "5", "FirstTrivial"]), "First level string (default)");
|
|
26859
|
+
});
|
|
26860
|
+
it("second level with no substitution", () => {
|
|
26861
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26862
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26863
|
+
});
|
|
26864
|
+
it("second level with no substitution with fallback keys", () => {
|
|
26865
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
26866
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default)");
|
|
26867
|
+
});
|
|
26868
|
+
it("first level with substitution", () => {
|
|
26869
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26870
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26871
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26872
|
+
});
|
|
26873
|
+
it("first level with substitution with fallback keys", () => {
|
|
26874
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26875
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26876
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26877
|
+
});
|
|
26878
|
+
it("second level with substitution", () => {
|
|
26879
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26880
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26881
|
+
});
|
|
26882
|
+
it("second level with substitution with fallback keys", () => {
|
|
26883
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26884
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26885
|
+
});
|
|
26886
|
+
it("first level missing key doesn't find a value", () => {
|
|
26887
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
26888
|
+
});
|
|
26889
|
+
it("first level missing all keys doesn't find a value", () => {
|
|
26890
|
+
chai_1.assert.equal(localization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
26891
|
+
});
|
|
26892
|
+
it("second level missing key doesn't find a value", () => {
|
|
26893
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26894
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "MissingKeyObject.MissingString"]), "MissingKeyObject.MissingString");
|
|
26895
|
+
});
|
|
26896
|
+
it("read from en-US fallback", () => {
|
|
26897
|
+
chai_1.assert.equal(localization.getLocalizedString("OnlyEnglishUS"), "HelloUS");
|
|
26898
|
+
});
|
|
26899
|
+
});
|
|
26900
|
+
describe("Default Namespace (German)", () => {
|
|
26901
|
+
it("first level with no substitution", () => {
|
|
26902
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
|
|
26903
|
+
});
|
|
26904
|
+
it("first level with no substitution with fallback keys", () => {
|
|
26905
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default german)");
|
|
26906
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default german)");
|
|
26907
|
+
});
|
|
26908
|
+
it("second level with no substitution", () => {
|
|
26909
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
26910
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
26911
|
+
});
|
|
26912
|
+
it("second level with no substitution with fallback keys", () => {
|
|
26913
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default german)");
|
|
26914
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default german)");
|
|
26915
|
+
});
|
|
26916
|
+
it("first level with substitution", () => {
|
|
26917
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
26918
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
26919
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
26920
|
+
});
|
|
26921
|
+
it("first level with substitution with fallback keys", () => {
|
|
26922
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
26923
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
26924
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
26925
|
+
});
|
|
26926
|
+
it("second level with substitution", () => {
|
|
26927
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
26928
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
26929
|
+
});
|
|
26930
|
+
it("second level with substitution with fallback keys", () => {
|
|
26931
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
26932
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
26933
|
+
});
|
|
26934
|
+
it("first level missing key doesn't find a value", () => {
|
|
26935
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
26936
|
+
});
|
|
26937
|
+
it("first level missing all keys doesn't find a value", () => {
|
|
26938
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
|
|
26939
|
+
});
|
|
26940
|
+
it("second level missing key doesn't find a value", () => {
|
|
26941
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26942
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26943
|
+
});
|
|
26944
|
+
});
|
|
26945
|
+
describe("Given Namespace", () => {
|
|
26946
|
+
it("first level with no substitution", () => {
|
|
26947
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26948
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26949
|
+
});
|
|
26950
|
+
it("first level with no substitution with fallback keys", () => {
|
|
26951
|
+
chai_1.assert.equal(localization.getLocalizedString(["Default:FirstTrivial", "Not:NotExist"]), "First level string (default)");
|
|
26952
|
+
chai_1.assert.equal(localization.getLocalizedString(["Default:NotExist", "Test:FirstTrivial"]), "First level string (test)");
|
|
26953
|
+
});
|
|
26954
|
+
it("second level with no substitution", () => {
|
|
26955
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26956
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26957
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
26958
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
26959
|
+
});
|
|
26960
|
+
it("second level with no substitution with fallback keys", () => {
|
|
26961
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
26962
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
26963
|
+
});
|
|
26964
|
+
it("first level with substitution", () => {
|
|
26965
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26966
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26967
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26968
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
26969
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
26970
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
26971
|
+
});
|
|
26972
|
+
it("first level with substitution with fallback keys", () => {
|
|
26973
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26974
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:FirstSubstitution1", "Default:NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
26975
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26976
|
+
});
|
|
26977
|
+
it("second level with substitution", () => {
|
|
26978
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26979
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26980
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
26981
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
26982
|
+
});
|
|
26983
|
+
it("second level with substitution with fallback keys", () => {
|
|
26984
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26985
|
+
chai_1.assert.equal(localization.getLocalizedString(["Test:SecondSubstitution.Test2", "Default:NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
26986
|
+
});
|
|
26987
|
+
it("first level missing key doesn't find a value", () => {
|
|
26988
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
26989
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
26990
|
+
});
|
|
26991
|
+
it("second level missing key doesn't find a value", () => {
|
|
26992
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26993
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26994
|
+
});
|
|
26995
|
+
it("read from en-US fallback", () => {
|
|
26996
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:OnlyEnglishUS"), "HelloUS");
|
|
26997
|
+
});
|
|
26998
|
+
});
|
|
26999
|
+
describe("Given Namespace (German)", () => {
|
|
27000
|
+
it("first level with no substitution", () => {
|
|
27001
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default german)");
|
|
27002
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (german)");
|
|
27003
|
+
});
|
|
27004
|
+
it("second level with no substitution", () => {
|
|
27005
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default german)");
|
|
27006
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default german)");
|
|
27007
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (german)");
|
|
27008
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (german)");
|
|
27009
|
+
});
|
|
27010
|
+
it("first level with substitution", () => {
|
|
27011
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
27012
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
27013
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
27014
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
27015
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
27016
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
27017
|
+
});
|
|
27018
|
+
it("second level with substitution", () => {
|
|
27019
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
27020
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
27021
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
27022
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
27023
|
+
});
|
|
27024
|
+
it("first level missing key doesn't find a value", () => {
|
|
27025
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
27026
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
27027
|
+
});
|
|
27028
|
+
it("second level missing key doesn't find a value", () => {
|
|
27029
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
27030
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
27031
|
+
});
|
|
27032
|
+
});
|
|
27033
|
+
describe("Nonexisting Namespace", () => {
|
|
27034
|
+
it("first level fails", () => {
|
|
27035
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
|
|
27036
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
|
|
27037
|
+
});
|
|
27038
|
+
it("second level fails", () => {
|
|
27039
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
27040
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
|
|
27041
|
+
});
|
|
27042
|
+
it("fallback key fails", () => {
|
|
27043
|
+
chai_1.assert.equal(localization.getLocalizedString(["Nonexisting:FirstTrivial", "NotExist"]), "NotExist");
|
|
27044
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Nonexisting:Missing.String"]), "Missing.String");
|
|
27045
|
+
});
|
|
27046
|
+
});
|
|
27047
|
+
// Test a few options to make sure they get passed through correctly
|
|
27048
|
+
describe("With Options", () => {
|
|
27049
|
+
it("returnDetails throws error", () => {
|
|
27050
|
+
chai_1.assert.throws(() => {
|
|
27051
|
+
localization.getLocalizedString("X", { returnDetails: true });
|
|
27052
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27053
|
+
});
|
|
27054
|
+
it("returnObjects throws error", () => {
|
|
27055
|
+
chai_1.assert.throws(() => {
|
|
27056
|
+
localization.getLocalizedString("X", { returnObjects: true });
|
|
27057
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27058
|
+
});
|
|
27059
|
+
it("returnDetails and returnObjects throws error", () => {
|
|
27060
|
+
chai_1.assert.throws(() => {
|
|
27061
|
+
localization.getLocalizedString("X", { returnDetails: true, returnObjects: true });
|
|
27062
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27063
|
+
});
|
|
27064
|
+
it("default value", () => {
|
|
27065
|
+
chai_1.assert.equal(localization.getLocalizedString("Missing", { defaultValue: "default" }), "default");
|
|
27066
|
+
});
|
|
27067
|
+
it("override fallback language", () => {
|
|
27068
|
+
// Doesn't fallback to English
|
|
27069
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { fallbackLng: "de" }), "OnlyEnglish");
|
|
27070
|
+
});
|
|
27071
|
+
it("set namespace", () => {
|
|
27072
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
27073
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (test)");
|
|
27074
|
+
});
|
|
27075
|
+
});
|
|
27076
|
+
});
|
|
27077
|
+
describe("#getLocalizedString with namespace passed in as an option", () => {
|
|
27078
|
+
before(async () => {
|
|
27079
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27080
|
+
await localization.initialize(["Default", "Test"]);
|
|
27081
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27082
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
27083
|
+
});
|
|
27084
|
+
describe("Keys Without Namespaces", () => {
|
|
27085
|
+
it("first level with no substitution", () => {
|
|
27086
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
27087
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
27088
|
+
});
|
|
27089
|
+
it("first level with no substitution with fallback keys", () => {
|
|
27090
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Default" }), "First level string (default)");
|
|
27091
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
27092
|
+
});
|
|
27093
|
+
it("second level with no substitution", () => {
|
|
27094
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default)");
|
|
27095
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default)");
|
|
27096
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
27097
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (test)");
|
|
27098
|
+
});
|
|
27099
|
+
it("second level with no substitution with fallback keys", () => {
|
|
27100
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"], { ns: "Default" }), "Second level string 1 (default)");
|
|
27101
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"], { ns: "Test" }), "Second level string 2 (test)");
|
|
27102
|
+
});
|
|
27103
|
+
it("first level with substitution", () => {
|
|
27104
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27105
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
27106
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
27107
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
27108
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27109
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27110
|
+
});
|
|
27111
|
+
it("first level with substitution with fallback keys", () => {
|
|
27112
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27113
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27114
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27115
|
+
});
|
|
27116
|
+
it("second level with substitution", () => {
|
|
27117
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27118
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
27119
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
27120
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27121
|
+
});
|
|
27122
|
+
it("second level with substitution with fallback keys", () => {
|
|
27123
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27124
|
+
chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27125
|
+
});
|
|
27126
|
+
it("first level missing key doesn't find a value", () => {
|
|
27127
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
27128
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
27129
|
+
});
|
|
27130
|
+
it("second level missing key doesn't find a value", () => {
|
|
27131
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
27132
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
27133
|
+
});
|
|
27134
|
+
});
|
|
27135
|
+
describe("Keys Without Namespaces (German)", () => {
|
|
27136
|
+
it("first level with no substitution", () => {
|
|
27137
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default german)");
|
|
27138
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (german)");
|
|
27139
|
+
});
|
|
27140
|
+
it("second level with no substitution", () => {
|
|
27141
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default german)");
|
|
27142
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default german)");
|
|
27143
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (german)");
|
|
27144
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (german)");
|
|
27145
|
+
});
|
|
27146
|
+
it("first level with substitution", () => {
|
|
27147
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
27148
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
27149
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
27150
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
27151
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
27152
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
27153
|
+
});
|
|
27154
|
+
it("second level with substitution", () => {
|
|
27155
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
27156
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
27157
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
27158
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
27159
|
+
});
|
|
27160
|
+
it("first level missing key doesn't find a value", () => {
|
|
27161
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
27162
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
27163
|
+
});
|
|
27164
|
+
it("second level missing key doesn't find a value", () => {
|
|
27165
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
27166
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
27167
|
+
});
|
|
27168
|
+
});
|
|
27169
|
+
describe("Keys With Namespaces", () => {
|
|
27170
|
+
it("key with same namespace works", () => {
|
|
27171
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
27172
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
27173
|
+
});
|
|
27174
|
+
it("key with different namespace overrides given namespace", () => {
|
|
27175
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Default" }), "First level string (test)");
|
|
27176
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
27177
|
+
});
|
|
27178
|
+
it("key with same namespace works with fallback keys", () => {
|
|
27179
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Default" }), "First level string (default)");
|
|
27180
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
27181
|
+
});
|
|
27182
|
+
it("key with different namespace overrides given namespace with fallback keys", () => {
|
|
27183
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Default" }), "First level string (test)");
|
|
27184
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Test" }), "First level string (default)");
|
|
27185
|
+
});
|
|
27186
|
+
it("missing key does not find a value", () => {
|
|
27187
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
27188
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString(["Missing1", "MissingKeyObject.MissingString"], { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
27189
|
+
});
|
|
27190
|
+
});
|
|
27191
|
+
describe("Nonexisting Namespace", () => {
|
|
27192
|
+
it("first level fails", () => {
|
|
27193
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Nonexisting" }), "FirstTrivial");
|
|
27194
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Nonexisting" }), "MissingKeyString");
|
|
27195
|
+
});
|
|
27196
|
+
it("second level fails", () => {
|
|
27197
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Nonexisting" }), "SecondTrivial.Test1");
|
|
27198
|
+
chai_1.assert.equal(localization.getLocalizedString("Missing.String", { ns: "Nonexisting" }), "Missing.String");
|
|
27199
|
+
});
|
|
27200
|
+
it("empty string namespace falls back to default namespace", () => {
|
|
27201
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "" }), "First level string (default)");
|
|
27202
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "" }), "Second level string 1 (default)");
|
|
27203
|
+
});
|
|
27204
|
+
it("fallback key fails", () => {
|
|
27205
|
+
chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Nonexisting" }), "NotExist");
|
|
27206
|
+
chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Missing.String"], { ns: "Nonexisting" }), "Missing.String");
|
|
27207
|
+
});
|
|
27208
|
+
it("use key with valid namespace instead", () => {
|
|
27209
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Nonexisting" }), "First level string (default)");
|
|
27210
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Nonexisting" }), "First level string (test)");
|
|
27211
|
+
});
|
|
27212
|
+
it("providing key with invalid namespace fails", () => {
|
|
27213
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting2:FirstTrivial", { ns: "Nonexisting1" }), "FirstTrivial");
|
|
27214
|
+
});
|
|
27215
|
+
});
|
|
27216
|
+
// Test a few options to make sure they get passed through correctly
|
|
27217
|
+
describe("With Options", () => {
|
|
27218
|
+
it("returnDetails throws error", () => {
|
|
27219
|
+
chai_1.assert.throws(() => {
|
|
27220
|
+
localization.getLocalizedString("X", { ns: "Default", returnDetails: true });
|
|
27221
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27222
|
+
});
|
|
27223
|
+
it("returnObjects throws error", () => {
|
|
27224
|
+
chai_1.assert.throws(() => {
|
|
27225
|
+
localization.getLocalizedString("X", { ns: "Default", returnObjects: true });
|
|
27226
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27227
|
+
});
|
|
27228
|
+
it("returnDetails and returnObjects throws error", () => {
|
|
27229
|
+
chai_1.assert.throws(() => {
|
|
27230
|
+
localization.getLocalizedString("X", { ns: "Default", returnDetails: true, returnObjects: true });
|
|
27231
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27232
|
+
});
|
|
27233
|
+
it("default value", () => {
|
|
27234
|
+
chai_1.assert.equal(localization.getLocalizedString("Missing", { ns: "Default", defaultValue: "default" }), "default");
|
|
27235
|
+
});
|
|
27236
|
+
it("override fallback language", () => {
|
|
27237
|
+
// Doesn't fallback to English
|
|
27238
|
+
chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { ns: "Default", fallbackLng: "de" }), "OnlyEnglish");
|
|
27239
|
+
});
|
|
27240
|
+
});
|
|
27241
|
+
});
|
|
27242
|
+
describe("#getEnglishString", () => {
|
|
27243
|
+
before(async () => {
|
|
27244
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27245
|
+
await localization.initialize(["Default", "Test"]);
|
|
27246
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27247
|
+
await germanLocalization.initialize(["Default", "Test"]);
|
|
27248
|
+
});
|
|
27249
|
+
describe("Given Namespace", () => {
|
|
27250
|
+
it("first level with no substitution", () => {
|
|
27251
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
27252
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
27253
|
+
});
|
|
27254
|
+
it("first level with no substitution with fallback keys", () => {
|
|
27255
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
27256
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
27257
|
+
});
|
|
27258
|
+
it("second level with no substitution", () => {
|
|
27259
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
27260
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
27261
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
27262
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
27263
|
+
});
|
|
27264
|
+
it("second level with no substitution with fallback keys", () => {
|
|
27265
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
27266
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
27267
|
+
});
|
|
27268
|
+
it("first level with substitution", () => {
|
|
27269
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27270
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
27271
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
27272
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
27273
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27274
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27275
|
+
});
|
|
27276
|
+
it("first level with substitution with fallback keys", () => {
|
|
27277
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27278
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27279
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27280
|
+
});
|
|
27281
|
+
it("second level with substitution", () => {
|
|
27282
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27283
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
27284
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
27285
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27286
|
+
});
|
|
27287
|
+
it("second level with substitution with fallback keys", () => {
|
|
27288
|
+
chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27289
|
+
chai_1.assert.equal(localization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27290
|
+
});
|
|
27291
|
+
it("first level missing key doesn't find a value", () => {
|
|
27292
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
27293
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
27294
|
+
});
|
|
27295
|
+
it("second level missing key doesn't find a value", () => {
|
|
27296
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
27297
|
+
chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
27298
|
+
});
|
|
27299
|
+
});
|
|
27300
|
+
describe("Given Namespace with German default language returns English strings", () => {
|
|
27301
|
+
it("first level with no substitution", () => {
|
|
27302
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
|
|
27303
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
|
|
27304
|
+
});
|
|
27305
|
+
it("first level with no substitution with fallback keys", () => {
|
|
27306
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
|
|
27307
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
|
|
27308
|
+
});
|
|
27309
|
+
it("second level with no substitution", () => {
|
|
27310
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
27311
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
27312
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
27313
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
27314
|
+
});
|
|
27315
|
+
it("second level with no substitution with fallback keys", () => {
|
|
27316
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
|
|
27317
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
|
|
27318
|
+
});
|
|
27319
|
+
it("first level with substitution", () => {
|
|
27320
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27321
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
27322
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
27323
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
27324
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27325
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27326
|
+
});
|
|
27327
|
+
it("first level with substitution with fallback keys", () => {
|
|
27328
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
27329
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
27330
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
27331
|
+
});
|
|
27332
|
+
it("second level with substitution", () => {
|
|
27333
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27334
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
27335
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
27336
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27337
|
+
});
|
|
27338
|
+
it("second level with substitution with fallback keys", () => {
|
|
27339
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
27340
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
27341
|
+
});
|
|
27342
|
+
it("first level missing key doesn't find a value", () => {
|
|
27343
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
|
|
27344
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
|
|
27345
|
+
});
|
|
27346
|
+
it("second level missing key doesn't find a value", () => {
|
|
27347
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
27348
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
27349
|
+
});
|
|
27350
|
+
});
|
|
27351
|
+
describe("Nonexisting Namespace", () => {
|
|
27352
|
+
it("first level fails", () => {
|
|
27353
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "FirstTrivial"), "FirstTrivial");
|
|
27354
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "MissingKeyString"), "MissingKeyString");
|
|
27355
|
+
});
|
|
27356
|
+
it("second level fails", () => {
|
|
27357
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
27358
|
+
chai_1.assert.equal(localization.getEnglishString("Nonexisting", "Missing.String"), "Missing.String");
|
|
27359
|
+
});
|
|
27360
|
+
it("empty string namespace is treated as default namespace", () => {
|
|
27361
|
+
chai_1.assert.equal(localization.getEnglishString("", "FirstTrivial"), "First level string (default)");
|
|
27362
|
+
chai_1.assert.equal(localization.getEnglishString("", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
27363
|
+
});
|
|
27364
|
+
});
|
|
27365
|
+
// Test a few options to make sure they get passed through correctly
|
|
27366
|
+
describe("With Options", () => {
|
|
27367
|
+
it("returnDetails throws error", () => {
|
|
27368
|
+
chai_1.assert.throws(() => {
|
|
27369
|
+
localization.getEnglishString("Default", "X", { returnDetails: true });
|
|
27370
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27371
|
+
});
|
|
27372
|
+
it("returnObjects throws error", () => {
|
|
27373
|
+
chai_1.assert.throws(() => {
|
|
27374
|
+
localization.getEnglishString("Default", "X", { returnObjects: true });
|
|
27375
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27376
|
+
});
|
|
27377
|
+
it("returnDetails and returnObjects throws error", () => {
|
|
27378
|
+
chai_1.assert.throws(() => {
|
|
27379
|
+
localization.getEnglishString("Default", "X", { returnDetails: true, returnObjects: true });
|
|
27380
|
+
}, "Translation key must map to a string, but the given options will result in an object");
|
|
27381
|
+
});
|
|
27382
|
+
it("default value", () => {
|
|
27383
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "Missing", { defaultValue: "default" }), "default");
|
|
27384
|
+
});
|
|
27385
|
+
it("english takes priority over fallback language", () => {
|
|
27386
|
+
chai_1.assert.equal(germanLocalization.getEnglishString("Default", "OnlyEnglish", { fallbackLng: "de" }), "Hello");
|
|
27387
|
+
});
|
|
27388
|
+
// White box test
|
|
27389
|
+
it("given namespace overrides namespace translation option", () => {
|
|
27390
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
27391
|
+
chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
|
|
27392
|
+
});
|
|
27393
|
+
});
|
|
27394
|
+
});
|
|
27395
|
+
// Returned promises never have anything of substance, being only empty or resolving to null...
|
|
27396
|
+
// describe("#getNamespacePromise", () => {
|
|
27397
|
+
// });
|
|
27398
|
+
describe("#getLanguageList", () => {
|
|
27399
|
+
let languages;
|
|
27400
|
+
it("english language list includes en and en-US", async () => {
|
|
27401
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27402
|
+
await localization.initialize([]);
|
|
27403
|
+
languages = localization.getLanguageList();
|
|
27404
|
+
chai_1.assert.isTrue(languages.includes("en-US"));
|
|
27405
|
+
chai_1.assert.isTrue(languages.includes("en"));
|
|
27406
|
+
});
|
|
27407
|
+
it("when non-english language is set as default, that language and english are included in langauge list", async () => {
|
|
27408
|
+
germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27409
|
+
await germanLocalization.initialize([]);
|
|
27410
|
+
languages = germanLocalization.getLanguageList();
|
|
27411
|
+
chai_1.assert.isTrue(languages.includes("en"));
|
|
27412
|
+
chai_1.assert.isTrue(languages.includes("de"));
|
|
27413
|
+
});
|
|
27414
|
+
});
|
|
27415
|
+
describe("#changeLanguage", () => {
|
|
27416
|
+
it("change from english to another language", async () => {
|
|
27417
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
27418
|
+
await localization.initialize(["Default"]);
|
|
27419
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
27420
|
+
await localization.changeLanguage("de");
|
|
27421
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
27422
|
+
});
|
|
27423
|
+
it("change from another language to english", async () => {
|
|
27424
|
+
localization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
|
|
27425
|
+
await localization.initialize(["Default"]);
|
|
27426
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
|
|
27427
|
+
await localization.changeLanguage("en");
|
|
27428
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
|
|
27429
|
+
});
|
|
27430
|
+
});
|
|
27431
|
+
describe("#registerNamespace", () => {
|
|
27432
|
+
let itwinLocalization;
|
|
27433
|
+
beforeEach(async () => {
|
|
27434
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
|
|
27435
|
+
});
|
|
27436
|
+
it("can read from namespace after it is registered", async () => {
|
|
27437
|
+
await itwinLocalization.initialize([]);
|
|
27438
|
+
await itwinLocalization.registerNamespace("Test");
|
|
27439
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
27440
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
27441
|
+
});
|
|
27442
|
+
it("zero initial, register one", async () => {
|
|
27443
|
+
await itwinLocalization.initialize([]);
|
|
27444
|
+
await itwinLocalization.registerNamespace("test1");
|
|
27445
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27446
|
+
});
|
|
27447
|
+
it("zero initial, register two", async () => {
|
|
27448
|
+
await itwinLocalization.initialize([]);
|
|
27449
|
+
await itwinLocalization.registerNamespace("test1");
|
|
27450
|
+
await itwinLocalization.registerNamespace("test2");
|
|
27451
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27452
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
27453
|
+
});
|
|
27454
|
+
it("one initial, register one", async () => {
|
|
27455
|
+
await itwinLocalization.initialize(["initial1"]);
|
|
27456
|
+
await itwinLocalization.registerNamespace("test1");
|
|
27457
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27458
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27459
|
+
});
|
|
27460
|
+
it("one initial, register two", async () => {
|
|
27461
|
+
await itwinLocalization.initialize(["initial1"]);
|
|
27462
|
+
await itwinLocalization.registerNamespace("test1");
|
|
27463
|
+
await itwinLocalization.registerNamespace("test2");
|
|
27464
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27465
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
|
|
27466
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27467
|
+
});
|
|
27468
|
+
it("two initial, register one", async () => {
|
|
27469
|
+
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
27470
|
+
await itwinLocalization.registerNamespace("test1");
|
|
27471
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27472
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27473
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
27474
|
+
});
|
|
27475
|
+
it("two initial, register two", async () => {
|
|
27476
|
+
await itwinLocalization.initialize(["initial1", "initial2"]);
|
|
27477
|
+
await itwinLocalization.registerNamespace("test1");
|
|
27478
|
+
await itwinLocalization.registerNamespace("test2");
|
|
27479
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
|
|
27480
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
|
|
27481
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
|
|
27482
|
+
});
|
|
27483
|
+
it("register duplicate namespaces", async () => {
|
|
27484
|
+
await itwinLocalization.initialize([]);
|
|
27485
|
+
await itwinLocalization.registerNamespace("Test");
|
|
27486
|
+
await itwinLocalization.registerNamespace("Test");
|
|
27487
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
27488
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
27489
|
+
});
|
|
27490
|
+
it("register duplicate namespace of initial namespace doesn't break anything", async () => {
|
|
27491
|
+
await itwinLocalization.initialize(["Test"]);
|
|
27492
|
+
await itwinLocalization.registerNamespace("Test");
|
|
27493
|
+
chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
|
|
27494
|
+
chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
27495
|
+
});
|
|
27496
|
+
});
|
|
27497
|
+
// unregisterNamespace() isn't used and basically does nothing
|
|
27498
|
+
// describe("#unregisterNamespace", () => {
|
|
27499
|
+
// });
|
|
27500
|
+
});
|
|
27489
27501
|
|
|
27490
27502
|
})();
|
|
27491
27503
|
|