@itwin/core-i18n 3.7.1 → 3.7.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 +6 -1
- 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 +929 -929
- package/lib/cjs/test/webpack/bundled-tests.js +1099 -1099
- 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,16 +10,16 @@
|
|
|
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
20
|
function cov_2l9mmpbx71() {
|
|
21
21
|
var path = "D:\\vsts_a\\4\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js";
|
|
22
|
-
var hash = "
|
|
22
|
+
var hash = "24e58bea480e0876d4033d5608415d9c06c3e4a5";
|
|
23
23
|
var global = new Function("return this")();
|
|
24
24
|
var gcv = "__coverage__";
|
|
25
25
|
var coverageData = {
|
|
@@ -3089,10 +3089,10 @@ function cov_2l9mmpbx71() {
|
|
|
3089
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: ["/*---------------------------------------------------------------------------------------------\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"]
|
|
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"]
|
|
3093
3093
|
},
|
|
3094
3094
|
_coverageSchema: "1a1c01bbd47fc00a2c39e90264f33305004495a9",
|
|
3095
|
-
hash: "
|
|
3095
|
+
hash: "24e58bea480e0876d4033d5608415d9c06c3e4a5"
|
|
3096
3096
|
};
|
|
3097
3097
|
var coverage = global[gcv] || (global[gcv] = {});
|
|
3098
3098
|
if (!coverage[path] || coverage[path].hash !== hash) {
|
|
@@ -3126,9 +3126,9 @@ const i18next_browser_languagedetector_1 = (cov_2l9mmpbx71().s[5]++, __importDef
|
|
|
3126
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
3127
|
const core_bentley_1 = (cov_2l9mmpbx71().s[7]++, __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js"));
|
|
3128
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
|
|
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) {
|
|
@@ -3199,21 +3199,21 @@ class ITwinLocalization {
|
|
|
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
3219
|
cov_2l9mmpbx71().f[3]++;
|
|
@@ -3224,18 +3224,18 @@ class ITwinLocalization {
|
|
|
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
3241
|
cov_2l9mmpbx71().f[5]++;
|
|
@@ -3259,13 +3259,13 @@ class ITwinLocalization {
|
|
|
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
3271
|
cov_2l9mmpbx71().f[6]++;
|
|
@@ -3287,12 +3287,12 @@ class ITwinLocalization {
|
|
|
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
3298
|
cov_2l9mmpbx71().f[8]++;
|
|
@@ -3323,9 +3323,9 @@ class ITwinLocalization {
|
|
|
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
3331
|
cov_2l9mmpbx71().f[9]++;
|
|
@@ -3344,13 +3344,13 @@ class ITwinLocalization {
|
|
|
3344
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
3356
|
cov_2l9mmpbx71().f[12]++;
|
|
@@ -26630,874 +26630,874 @@ var exports = __webpack_exports__;
|
|
|
26630
26630
|
/*!************************************************!*\
|
|
26631
26631
|
!*** ./lib/cjs/test/ITwinLocalization.test.js ***!
|
|
26632
26632
|
\************************************************/
|
|
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
|
-
});
|
|
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
|
+
});
|
|
27501
27501
|
|
|
27502
27502
|
})();
|
|
27503
27503
|
|