@itwin/core-i18n 3.4.6 → 3.4.7
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 +98 -98
- package/lib/cjs/ITwinLocalization.js +226 -226
- 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 +124 -124
- package/lib/cjs/test/ITwinLocalization.test.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js +326 -326
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.js +350 -350
- package/lib/cjs/test/webpack/bundled-tests.js.map +1 -1
- package/lib/esm/ITwinLocalization.d.ts +98 -98
- package/lib/esm/ITwinLocalization.js +219 -219
- 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 +122 -122
- package/lib/esm/test/ITwinLocalization.test.js.map +1 -1
- package/package.json +7 -7
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
-
/*---------------------------------------------------------------------------------------------
|
|
13
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
14
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
12
|
+
/*---------------------------------------------------------------------------------------------
|
|
13
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
14
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
15
15
|
*--------------------------------------------------------------------------------------------*/
|
|
16
16
|
|
|
17
|
-
/** @packageDocumentation
|
|
18
|
-
* @module Localization
|
|
17
|
+
/** @packageDocumentation
|
|
18
|
+
* @module Localization
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
var path = "D:\\vsts_a\\
|
|
23
|
-
var hash = "
|
|
21
|
+
function cov_1exkrud5g4() {
|
|
22
|
+
var path = "D:\\vsts_a\\2\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js";
|
|
23
|
+
var hash = "de1b46530a1a03ee53c292484f8dd6b9cf660cd7";
|
|
24
24
|
var global = new Function("return this")();
|
|
25
25
|
var gcv = "__coverage__";
|
|
26
26
|
var coverageData = {
|
|
27
|
-
path: "D:\\vsts_a\\
|
|
27
|
+
path: "D:\\vsts_a\\2\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js",
|
|
28
28
|
statementMap: {
|
|
29
29
|
"0": {
|
|
30
30
|
start: {
|
|
@@ -3076,13 +3076,13 @@ function cov_1n64vqx5d7() {
|
|
|
3076
3076
|
inputSourceMap: {
|
|
3077
3077
|
version: 3,
|
|
3078
3078
|
file: "ITwinLocalization.js",
|
|
3079
|
-
sources: ["D:\\vsts_a\\
|
|
3079
|
+
sources: ["D:\\vsts_a\\2\\s\\core\\i18n\\src\\ITwinLocalization.ts"],
|
|
3080
3080
|
names: [],
|
|
3081
3081
|
mappings: "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",
|
|
3082
|
-
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 namespace is a separate param and the key does not include the namespace.\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 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"]
|
|
3082
|
+
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 namespace is a separate param and the key does not include the namespace.\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 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"]
|
|
3083
3083
|
},
|
|
3084
3084
|
_coverageSchema: "1a1c01bbd47fc00a2c39e90264f33305004495a9",
|
|
3085
|
-
hash: "
|
|
3085
|
+
hash: "de1b46530a1a03ee53c292484f8dd6b9cf660cd7"
|
|
3086
3086
|
};
|
|
3087
3087
|
var coverage = global[gcv] || (global[gcv] = {});
|
|
3088
3088
|
|
|
@@ -3093,64 +3093,64 @@ function cov_1n64vqx5d7() {
|
|
|
3093
3093
|
var actualCoverage = coverage[path];
|
|
3094
3094
|
{
|
|
3095
3095
|
// @ts-ignore
|
|
3096
|
-
|
|
3096
|
+
cov_1exkrud5g4 = function () {
|
|
3097
3097
|
return actualCoverage;
|
|
3098
3098
|
};
|
|
3099
3099
|
}
|
|
3100
3100
|
return actualCoverage;
|
|
3101
3101
|
}
|
|
3102
3102
|
|
|
3103
|
-
|
|
3103
|
+
cov_1exkrud5g4();
|
|
3104
3104
|
|
|
3105
|
-
var __importDefault = (
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
return (
|
|
3105
|
+
var __importDefault = (cov_1exkrud5g4().s[0]++, (cov_1exkrud5g4().b[0][0]++, this) && (cov_1exkrud5g4().b[0][1]++, this.__importDefault) || (cov_1exkrud5g4().b[0][2]++, function (mod) {
|
|
3106
|
+
cov_1exkrud5g4().f[0]++;
|
|
3107
|
+
cov_1exkrud5g4().s[1]++;
|
|
3108
|
+
return (cov_1exkrud5g4().b[2][0]++, mod) && (cov_1exkrud5g4().b[2][1]++, mod.__esModule) ? (cov_1exkrud5g4().b[1][0]++, mod) : (cov_1exkrud5g4().b[1][1]++, {
|
|
3109
3109
|
"default": mod
|
|
3110
3110
|
});
|
|
3111
3111
|
}));
|
|
3112
3112
|
|
|
3113
|
-
|
|
3113
|
+
cov_1exkrud5g4().s[2]++;
|
|
3114
3114
|
Object.defineProperty(exports, "__esModule", ({
|
|
3115
3115
|
value: true
|
|
3116
3116
|
}));
|
|
3117
|
-
|
|
3117
|
+
cov_1exkrud5g4().s[3]++;
|
|
3118
3118
|
exports.ITwinLocalization = void 0;
|
|
3119
|
-
const i18next_1 = (
|
|
3120
|
-
const i18next_browser_languagedetector_1 = (
|
|
3121
|
-
const i18next_http_backend_1 = (
|
|
3122
|
-
const core_bentley_1 = (
|
|
3123
|
-
const DEFAULT_MAX_RETRIES = (
|
|
3124
|
-
|
|
3125
|
-
/** Supplies localizations for iTwin.js
|
|
3126
|
-
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
3127
|
-
* @public
|
|
3119
|
+
const i18next_1 = (cov_1exkrud5g4().s[4]++, __importDefault(__webpack_require__(/*! i18next */ "../../common/temp/node_modules/.pnpm/i18next@21.9.2/node_modules/i18next/dist/cjs/i18next.js")));
|
|
3120
|
+
const i18next_browser_languagedetector_1 = (cov_1exkrud5g4().s[5]++, __importDefault(__webpack_require__(/*! i18next-browser-languagedetector */ "../../common/temp/node_modules/.pnpm/i18next-browser-languagedetector@6.1.5/node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js")));
|
|
3121
|
+
const i18next_http_backend_1 = (cov_1exkrud5g4().s[6]++, __importDefault(__webpack_require__(/*! i18next-http-backend */ "../../common/temp/node_modules/.pnpm/i18next-http-backend@1.4.4/node_modules/i18next-http-backend/cjs/index.js")));
|
|
3122
|
+
const core_bentley_1 = (cov_1exkrud5g4().s[7]++, __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js"));
|
|
3123
|
+
const DEFAULT_MAX_RETRIES = (cov_1exkrud5g4().s[8]++, 1); // a low number prevents wasted time and potential timeouts when requesting localization files throws an error
|
|
3124
|
+
|
|
3125
|
+
/** Supplies localizations for iTwin.js
|
|
3126
|
+
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
3127
|
+
* @public
|
|
3128
3128
|
*/
|
|
3129
3129
|
|
|
3130
3130
|
class ITwinLocalization {
|
|
3131
3131
|
constructor(options) {
|
|
3132
|
-
|
|
3132
|
+
cov_1exkrud5g4().f[1]++;
|
|
3133
3133
|
|
|
3134
3134
|
var _a, _b, _c;
|
|
3135
3135
|
|
|
3136
|
-
|
|
3136
|
+
cov_1exkrud5g4().s[9]++;
|
|
3137
3137
|
this._namespaces = new Map();
|
|
3138
|
-
|
|
3138
|
+
cov_1exkrud5g4().s[10]++;
|
|
3139
3139
|
this.i18next = i18next_1.default.createInstance();
|
|
3140
|
-
|
|
3140
|
+
cov_1exkrud5g4().s[11]++;
|
|
3141
3141
|
this._backendOptions = {
|
|
3142
|
-
loadPath: (
|
|
3142
|
+
loadPath: (cov_1exkrud5g4().b[4][0]++, (_a = (cov_1exkrud5g4().b[6][0]++, options === null) || (cov_1exkrud5g4().b[6][1]++, options === void 0) ? (cov_1exkrud5g4().b[5][0]++, void 0) : (cov_1exkrud5g4().b[5][1]++, options.urlTemplate)) !== null) && (cov_1exkrud5g4().b[4][1]++, _a !== void 0) ? (cov_1exkrud5g4().b[3][0]++, _a) : (cov_1exkrud5g4().b[3][1]++, "locales/{{lng}}/{{ns}}.json"),
|
|
3143
3143
|
crossDomain: true,
|
|
3144
|
-
...((
|
|
3144
|
+
...((cov_1exkrud5g4().b[8][0]++, options === null) || (cov_1exkrud5g4().b[8][1]++, options === void 0) ? (cov_1exkrud5g4().b[7][0]++, void 0) : (cov_1exkrud5g4().b[7][1]++, options.backendHttpOptions))
|
|
3145
3145
|
};
|
|
3146
|
-
|
|
3146
|
+
cov_1exkrud5g4().s[12]++;
|
|
3147
3147
|
this._detectionOptions = {
|
|
3148
3148
|
order: ["querystring", "navigator", "htmlTag"],
|
|
3149
3149
|
lookupQuerystring: "lng",
|
|
3150
3150
|
caches: [],
|
|
3151
|
-
...((
|
|
3151
|
+
...((cov_1exkrud5g4().b[10][0]++, options === null) || (cov_1exkrud5g4().b[10][1]++, options === void 0) ? (cov_1exkrud5g4().b[9][0]++, void 0) : (cov_1exkrud5g4().b[9][1]++, options.detectorOptions))
|
|
3152
3152
|
};
|
|
3153
|
-
|
|
3153
|
+
cov_1exkrud5g4().s[13]++;
|
|
3154
3154
|
this._initOptions = {
|
|
3155
3155
|
interpolation: {
|
|
3156
3156
|
escapeValue: true
|
|
@@ -3159,255 +3159,255 @@ class ITwinLocalization {
|
|
|
3159
3159
|
maxRetries: DEFAULT_MAX_RETRIES,
|
|
3160
3160
|
backend: this._backendOptions,
|
|
3161
3161
|
detection: this._detectionOptions,
|
|
3162
|
-
...((
|
|
3162
|
+
...((cov_1exkrud5g4().b[12][0]++, options === null) || (cov_1exkrud5g4().b[12][1]++, options === void 0) ? (cov_1exkrud5g4().b[11][0]++, void 0) : (cov_1exkrud5g4().b[11][1]++, options.initOptions))
|
|
3163
3163
|
};
|
|
3164
|
-
|
|
3165
|
-
this.i18next.use((
|
|
3164
|
+
cov_1exkrud5g4().s[14]++;
|
|
3165
|
+
this.i18next.use((cov_1exkrud5g4().b[14][0]++, (_b = (cov_1exkrud5g4().b[16][0]++, options === null) || (cov_1exkrud5g4().b[16][1]++, options === void 0) ? (cov_1exkrud5g4().b[15][0]++, void 0) : (cov_1exkrud5g4().b[15][1]++, options.detectorPlugin)) !== null) && (cov_1exkrud5g4().b[14][1]++, _b !== void 0) ? (cov_1exkrud5g4().b[13][0]++, _b) : (cov_1exkrud5g4().b[13][1]++, i18next_browser_languagedetector_1.default)).use((cov_1exkrud5g4().b[18][0]++, (_c = (cov_1exkrud5g4().b[20][0]++, options === null) || (cov_1exkrud5g4().b[20][1]++, options === void 0) ? (cov_1exkrud5g4().b[19][0]++, void 0) : (cov_1exkrud5g4().b[19][1]++, options.backendPlugin)) !== null) && (cov_1exkrud5g4().b[18][1]++, _c !== void 0) ? (cov_1exkrud5g4().b[17][0]++, _c) : (cov_1exkrud5g4().b[17][1]++, i18next_http_backend_1.default)).use(TranslationLogger);
|
|
3166
3166
|
}
|
|
3167
3167
|
|
|
3168
3168
|
async initialize(namespaces) {
|
|
3169
|
-
|
|
3169
|
+
cov_1exkrud5g4().f[2]++;
|
|
3170
3170
|
|
|
3171
3171
|
var _a; // Also consider namespaces passed into constructor
|
|
3172
3172
|
|
|
3173
3173
|
|
|
3174
|
-
const initNamespaces = (
|
|
3175
|
-
const combinedNamespaces = (
|
|
3174
|
+
const initNamespaces = (cov_1exkrud5g4().s[15]++, [(cov_1exkrud5g4().b[21][0]++, this._initOptions.ns) || (cov_1exkrud5g4().b[21][1]++, [])].flat());
|
|
3175
|
+
const combinedNamespaces = (cov_1exkrud5g4().s[16]++, new Set([...namespaces, ...initNamespaces])); // without duplicates
|
|
3176
3176
|
|
|
3177
|
-
const defaultNamespace = (
|
|
3178
|
-
|
|
3177
|
+
const defaultNamespace = (cov_1exkrud5g4().s[17]++, (cov_1exkrud5g4().b[23][0]++, (_a = this._initOptions.defaultNS) !== null) && (cov_1exkrud5g4().b[23][1]++, _a !== void 0) ? (cov_1exkrud5g4().b[22][0]++, _a) : (cov_1exkrud5g4().b[22][1]++, namespaces[0]));
|
|
3178
|
+
cov_1exkrud5g4().s[18]++;
|
|
3179
3179
|
|
|
3180
3180
|
if (defaultNamespace) {
|
|
3181
|
-
|
|
3182
|
-
|
|
3181
|
+
cov_1exkrud5g4().b[24][0]++;
|
|
3182
|
+
cov_1exkrud5g4().s[19]++;
|
|
3183
3183
|
combinedNamespaces.add(defaultNamespace);
|
|
3184
3184
|
} else {
|
|
3185
|
-
|
|
3185
|
+
cov_1exkrud5g4().b[24][1]++;
|
|
3186
3186
|
} // Make sure default namespace is in namespaces list
|
|
3187
3187
|
|
|
3188
3188
|
|
|
3189
|
-
const initOptions = (
|
|
3189
|
+
const initOptions = (cov_1exkrud5g4().s[20]++, { ...this._initOptions,
|
|
3190
3190
|
defaultNS: defaultNamespace,
|
|
3191
3191
|
ns: [...combinedNamespaces]
|
|
3192
3192
|
}); // if in a development environment, set debugging
|
|
3193
3193
|
|
|
3194
|
-
|
|
3194
|
+
cov_1exkrud5g4().s[21]++;
|
|
3195
3195
|
|
|
3196
3196
|
if (false) {} else {
|
|
3197
|
-
|
|
3197
|
+
cov_1exkrud5g4().b[25][1]++;
|
|
3198
3198
|
}
|
|
3199
3199
|
|
|
3200
|
-
const initPromise = (
|
|
3201
|
-
|
|
3200
|
+
const initPromise = (cov_1exkrud5g4().s[23]++, this.i18next.init(initOptions));
|
|
3201
|
+
cov_1exkrud5g4().s[24]++;
|
|
3202
3202
|
|
|
3203
3203
|
for (const ns of namespaces) {
|
|
3204
|
-
|
|
3204
|
+
cov_1exkrud5g4().s[25]++;
|
|
3205
3205
|
|
|
3206
3206
|
this._namespaces.set(ns, initPromise);
|
|
3207
3207
|
}
|
|
3208
3208
|
|
|
3209
|
-
|
|
3209
|
+
cov_1exkrud5g4().s[26]++;
|
|
3210
3210
|
return initPromise;
|
|
3211
3211
|
}
|
|
3212
|
-
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
3213
|
-
* For example:
|
|
3214
|
-
* ``` ts
|
|
3215
|
-
* "MyKeys": {
|
|
3216
|
-
* "Key1": "First value",
|
|
3217
|
-
* "Key2": "Second value"
|
|
3218
|
-
* }
|
|
3219
|
-
* ```
|
|
3220
|
-
*
|
|
3221
|
-
* ``` ts
|
|
3222
|
-
* i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!"
|
|
3223
|
-
* ```
|
|
3224
|
-
* @param line The input line, potentially containing %{keys}.
|
|
3225
|
-
* @returns The line with all %{keys} translated
|
|
3226
|
-
* @public
|
|
3212
|
+
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
3213
|
+
* For example:
|
|
3214
|
+
* ``` ts
|
|
3215
|
+
* "MyKeys": {
|
|
3216
|
+
* "Key1": "First value",
|
|
3217
|
+
* "Key2": "Second value"
|
|
3218
|
+
* }
|
|
3219
|
+
* ```
|
|
3220
|
+
*
|
|
3221
|
+
* ``` ts
|
|
3222
|
+
* i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!"
|
|
3223
|
+
* ```
|
|
3224
|
+
* @param line The input line, potentially containing %{keys}.
|
|
3225
|
+
* @returns The line with all %{keys} translated
|
|
3226
|
+
* @public
|
|
3227
3227
|
*/
|
|
3228
3228
|
|
|
3229
3229
|
|
|
3230
3230
|
getLocalizedKeys(line) {
|
|
3231
|
-
|
|
3232
|
-
|
|
3231
|
+
cov_1exkrud5g4().f[3]++;
|
|
3232
|
+
cov_1exkrud5g4().s[27]++;
|
|
3233
3233
|
return line.replace(/\%\{(.+?)\}/g, (_match, tag) => {
|
|
3234
|
-
|
|
3235
|
-
|
|
3234
|
+
cov_1exkrud5g4().f[4]++;
|
|
3235
|
+
cov_1exkrud5g4().s[28]++;
|
|
3236
3236
|
return this.getLocalizedString(tag);
|
|
3237
3237
|
});
|
|
3238
3238
|
}
|
|
3239
|
-
/** Return the translated value of a key.
|
|
3240
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
3241
|
-
* @note The key includes the namespace, which identifies the particular localization file that contains the property,
|
|
3242
|
-
* followed by a colon, followed by the property in the JSON file.
|
|
3243
|
-
* For example:
|
|
3244
|
-
* ``` ts
|
|
3245
|
-
* const dataString: string = IModelApp.localization.getLocalizedString("iModelJs:BackgroundMap.BingDataAttribution");
|
|
3246
|
-
* ```
|
|
3247
|
-
* assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.
|
|
3248
|
-
* @returns The string corresponding to the first key that resolves.
|
|
3249
|
-
* @throws Error if no keys resolve to a string.
|
|
3250
|
-
* @public
|
|
3239
|
+
/** Return the translated value of a key.
|
|
3240
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
3241
|
+
* @note The key includes the namespace, which identifies the particular localization file that contains the property,
|
|
3242
|
+
* followed by a colon, followed by the property in the JSON file.
|
|
3243
|
+
* For example:
|
|
3244
|
+
* ``` ts
|
|
3245
|
+
* const dataString: string = IModelApp.localization.getLocalizedString("iModelJs:BackgroundMap.BingDataAttribution");
|
|
3246
|
+
* ```
|
|
3247
|
+
* assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.
|
|
3248
|
+
* @returns The string corresponding to the first key that resolves.
|
|
3249
|
+
* @throws Error if no keys resolve to a string.
|
|
3250
|
+
* @public
|
|
3251
3251
|
*/
|
|
3252
3252
|
|
|
3253
3253
|
|
|
3254
3254
|
getLocalizedString(key, options) {
|
|
3255
|
-
|
|
3256
|
-
|
|
3255
|
+
cov_1exkrud5g4().f[5]++;
|
|
3256
|
+
cov_1exkrud5g4().s[29]++;
|
|
3257
3257
|
|
|
3258
|
-
if ((
|
|
3259
|
-
|
|
3260
|
-
|
|
3258
|
+
if ((cov_1exkrud5g4().b[27][0]++, (cov_1exkrud5g4().b[29][0]++, options === null) || (cov_1exkrud5g4().b[29][1]++, options === void 0) ? (cov_1exkrud5g4().b[28][0]++, void 0) : (cov_1exkrud5g4().b[28][1]++, options.returnDetails)) || (cov_1exkrud5g4().b[27][1]++, (cov_1exkrud5g4().b[31][0]++, options === null) || (cov_1exkrud5g4().b[31][1]++, options === void 0) ? (cov_1exkrud5g4().b[30][0]++, void 0) : (cov_1exkrud5g4().b[30][1]++, options.returnObjects))) {
|
|
3259
|
+
cov_1exkrud5g4().b[26][0]++;
|
|
3260
|
+
cov_1exkrud5g4().s[30]++;
|
|
3261
3261
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
3262
3262
|
} else {
|
|
3263
|
-
|
|
3263
|
+
cov_1exkrud5g4().b[26][1]++;
|
|
3264
3264
|
}
|
|
3265
3265
|
|
|
3266
|
-
const value = (
|
|
3267
|
-
|
|
3266
|
+
const value = (cov_1exkrud5g4().s[31]++, this.i18next.t(key, options));
|
|
3267
|
+
cov_1exkrud5g4().s[32]++;
|
|
3268
3268
|
|
|
3269
3269
|
if (typeof value !== "string") {
|
|
3270
|
-
|
|
3271
|
-
|
|
3270
|
+
cov_1exkrud5g4().b[32][0]++;
|
|
3271
|
+
cov_1exkrud5g4().s[33]++;
|
|
3272
3272
|
throw new Error("Translation key(s) string not found");
|
|
3273
3273
|
} else {
|
|
3274
|
-
|
|
3274
|
+
cov_1exkrud5g4().b[32][1]++;
|
|
3275
3275
|
}
|
|
3276
3276
|
|
|
3277
|
-
|
|
3277
|
+
cov_1exkrud5g4().s[34]++;
|
|
3278
3278
|
return value;
|
|
3279
3279
|
}
|
|
3280
|
-
/** Similar to `getLocalizedString` but the namespace is a separate param and the key does not include the namespace.
|
|
3281
|
-
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3282
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
3283
|
-
* @returns The string corresponding to the first key that resolves.
|
|
3284
|
-
* @throws Error if no keys resolve to a string.
|
|
3285
|
-
* @internal
|
|
3280
|
+
/** Similar to `getLocalizedString` but the namespace is a separate param and the key does not include the namespace.
|
|
3281
|
+
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3282
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
3283
|
+
* @returns The string corresponding to the first key that resolves.
|
|
3284
|
+
* @throws Error if no keys resolve to a string.
|
|
3285
|
+
* @internal
|
|
3286
3286
|
*/
|
|
3287
3287
|
|
|
3288
3288
|
|
|
3289
3289
|
getLocalizedStringWithNamespace(namespace, key, options) {
|
|
3290
|
-
|
|
3291
|
-
let fullKey = (
|
|
3292
|
-
|
|
3290
|
+
cov_1exkrud5g4().f[6]++;
|
|
3291
|
+
let fullKey = (cov_1exkrud5g4().s[35]++, "");
|
|
3292
|
+
cov_1exkrud5g4().s[36]++;
|
|
3293
3293
|
|
|
3294
3294
|
if (typeof key === "string") {
|
|
3295
|
-
|
|
3296
|
-
|
|
3295
|
+
cov_1exkrud5g4().b[33][0]++;
|
|
3296
|
+
cov_1exkrud5g4().s[37]++;
|
|
3297
3297
|
fullKey = `${namespace}:${key}`;
|
|
3298
3298
|
} else {
|
|
3299
|
-
|
|
3300
|
-
|
|
3299
|
+
cov_1exkrud5g4().b[33][1]++;
|
|
3300
|
+
cov_1exkrud5g4().s[38]++;
|
|
3301
3301
|
fullKey = key.map(subKey => {
|
|
3302
|
-
|
|
3303
|
-
|
|
3302
|
+
cov_1exkrud5g4().f[7]++;
|
|
3303
|
+
cov_1exkrud5g4().s[39]++;
|
|
3304
3304
|
return `${namespace}:${subKey}`;
|
|
3305
3305
|
});
|
|
3306
3306
|
}
|
|
3307
3307
|
|
|
3308
|
-
|
|
3308
|
+
cov_1exkrud5g4().s[40]++;
|
|
3309
3309
|
return this.getLocalizedString(fullKey, options);
|
|
3310
3310
|
}
|
|
3311
|
-
/** Gets the English translation.
|
|
3312
|
-
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3313
|
-
* @param key - the key that matches a property in the JSON localization file.
|
|
3314
|
-
* @returns The string corresponding to the first key that resolves.
|
|
3315
|
-
* @throws Error if no keys resolve to a string.
|
|
3316
|
-
* @internal
|
|
3311
|
+
/** Gets the English translation.
|
|
3312
|
+
* @param namespace - the namespace that identifies the particular localization file that contains the property.
|
|
3313
|
+
* @param key - the key that matches a property in the JSON localization file.
|
|
3314
|
+
* @returns The string corresponding to the first key that resolves.
|
|
3315
|
+
* @throws Error if no keys resolve to a string.
|
|
3316
|
+
* @internal
|
|
3317
3317
|
*/
|
|
3318
3318
|
|
|
3319
3319
|
|
|
3320
3320
|
getEnglishString(namespace, key, options) {
|
|
3321
|
-
|
|
3322
|
-
|
|
3321
|
+
cov_1exkrud5g4().f[8]++;
|
|
3322
|
+
cov_1exkrud5g4().s[41]++;
|
|
3323
3323
|
|
|
3324
|
-
if ((
|
|
3325
|
-
|
|
3326
|
-
|
|
3324
|
+
if ((cov_1exkrud5g4().b[35][0]++, (cov_1exkrud5g4().b[37][0]++, options === null) || (cov_1exkrud5g4().b[37][1]++, options === void 0) ? (cov_1exkrud5g4().b[36][0]++, void 0) : (cov_1exkrud5g4().b[36][1]++, options.returnDetails)) || (cov_1exkrud5g4().b[35][1]++, (cov_1exkrud5g4().b[39][0]++, options === null) || (cov_1exkrud5g4().b[39][1]++, options === void 0) ? (cov_1exkrud5g4().b[38][0]++, void 0) : (cov_1exkrud5g4().b[38][1]++, options.returnObjects))) {
|
|
3325
|
+
cov_1exkrud5g4().b[34][0]++;
|
|
3326
|
+
cov_1exkrud5g4().s[42]++;
|
|
3327
3327
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
3328
3328
|
} else {
|
|
3329
|
-
|
|
3329
|
+
cov_1exkrud5g4().b[34][1]++;
|
|
3330
3330
|
}
|
|
3331
3331
|
|
|
3332
|
-
const en = (
|
|
3333
|
-
const str = (
|
|
3334
|
-
|
|
3332
|
+
const en = (cov_1exkrud5g4().s[43]++, this.i18next.getFixedT("en", namespace));
|
|
3333
|
+
const str = (cov_1exkrud5g4().s[44]++, en(key, options));
|
|
3334
|
+
cov_1exkrud5g4().s[45]++;
|
|
3335
3335
|
|
|
3336
3336
|
if (typeof str !== "string") {
|
|
3337
|
-
|
|
3338
|
-
|
|
3337
|
+
cov_1exkrud5g4().b[40][0]++;
|
|
3338
|
+
cov_1exkrud5g4().s[46]++;
|
|
3339
3339
|
throw new Error("Translation key(s) not found");
|
|
3340
3340
|
} else {
|
|
3341
|
-
|
|
3341
|
+
cov_1exkrud5g4().b[40][1]++;
|
|
3342
3342
|
}
|
|
3343
3343
|
|
|
3344
|
-
|
|
3344
|
+
cov_1exkrud5g4().s[47]++;
|
|
3345
3345
|
return str;
|
|
3346
3346
|
}
|
|
3347
|
-
/** Get the promise for an already registered Namespace.
|
|
3348
|
-
* @param name - the name of the namespace
|
|
3349
|
-
* @public
|
|
3347
|
+
/** Get the promise for an already registered Namespace.
|
|
3348
|
+
* @param name - the name of the namespace
|
|
3349
|
+
* @public
|
|
3350
3350
|
*/
|
|
3351
3351
|
|
|
3352
3352
|
|
|
3353
3353
|
getNamespacePromise(name) {
|
|
3354
|
-
|
|
3355
|
-
|
|
3354
|
+
cov_1exkrud5g4().f[9]++;
|
|
3355
|
+
cov_1exkrud5g4().s[48]++;
|
|
3356
3356
|
return this._namespaces.get(name);
|
|
3357
3357
|
}
|
|
3358
3358
|
/** @internal */
|
|
3359
3359
|
|
|
3360
3360
|
|
|
3361
3361
|
getLanguageList() {
|
|
3362
|
-
|
|
3363
|
-
|
|
3362
|
+
cov_1exkrud5g4().f[10]++;
|
|
3363
|
+
cov_1exkrud5g4().s[49]++;
|
|
3364
3364
|
return this.i18next.languages;
|
|
3365
3365
|
}
|
|
3366
3366
|
/** override the language detected in the browser */
|
|
3367
3367
|
|
|
3368
3368
|
|
|
3369
3369
|
async changeLanguage(language) {
|
|
3370
|
-
|
|
3371
|
-
|
|
3370
|
+
cov_1exkrud5g4().f[11]++;
|
|
3371
|
+
cov_1exkrud5g4().s[50]++;
|
|
3372
3372
|
return this.i18next.changeLanguage(language);
|
|
3373
3373
|
}
|
|
3374
|
-
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
3375
|
-
* @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.
|
|
3376
|
-
* @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,
|
|
3377
|
-
* based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await
|
|
3378
|
-
* fulfillment of the readPromise Promise property of the returned LocalizationNamespace.
|
|
3379
|
-
* @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)
|
|
3380
|
-
* @public
|
|
3374
|
+
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
3375
|
+
* @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.
|
|
3376
|
+
* @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,
|
|
3377
|
+
* based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await
|
|
3378
|
+
* fulfillment of the readPromise Promise property of the returned LocalizationNamespace.
|
|
3379
|
+
* @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)
|
|
3380
|
+
* @public
|
|
3381
3381
|
*/
|
|
3382
3382
|
|
|
3383
3383
|
|
|
3384
3384
|
async registerNamespace(name) {
|
|
3385
|
-
|
|
3386
|
-
const existing = (
|
|
3387
|
-
|
|
3385
|
+
cov_1exkrud5g4().f[12]++;
|
|
3386
|
+
const existing = (cov_1exkrud5g4().s[51]++, this._namespaces.get(name));
|
|
3387
|
+
cov_1exkrud5g4().s[52]++;
|
|
3388
3388
|
|
|
3389
3389
|
if (existing !== undefined) {
|
|
3390
|
-
|
|
3391
|
-
|
|
3390
|
+
cov_1exkrud5g4().b[41][0]++;
|
|
3391
|
+
cov_1exkrud5g4().s[53]++;
|
|
3392
3392
|
return existing;
|
|
3393
3393
|
} else {
|
|
3394
|
-
|
|
3394
|
+
cov_1exkrud5g4().b[41][1]++;
|
|
3395
3395
|
}
|
|
3396
3396
|
|
|
3397
|
-
const theReadPromise = (
|
|
3398
|
-
|
|
3399
|
-
|
|
3397
|
+
const theReadPromise = (cov_1exkrud5g4().s[54]++, new Promise(resolve => {
|
|
3398
|
+
cov_1exkrud5g4().f[13]++;
|
|
3399
|
+
cov_1exkrud5g4().s[55]++;
|
|
3400
3400
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
3401
3401
|
this.i18next.loadNamespaces(name, err => {
|
|
3402
|
-
|
|
3403
|
-
|
|
3402
|
+
cov_1exkrud5g4().f[14]++;
|
|
3403
|
+
cov_1exkrud5g4().s[56]++;
|
|
3404
3404
|
|
|
3405
3405
|
if (!err) {
|
|
3406
|
-
|
|
3407
|
-
|
|
3406
|
+
cov_1exkrud5g4().b[42][0]++;
|
|
3407
|
+
cov_1exkrud5g4().s[57]++;
|
|
3408
3408
|
return resolve();
|
|
3409
3409
|
} else {
|
|
3410
|
-
|
|
3410
|
+
cov_1exkrud5g4().b[42][1]++;
|
|
3411
3411
|
} // Here we got a non-null err object.
|
|
3412
3412
|
// This method is called when the system has attempted to load the resources for the namespaces for each possible locale.
|
|
3413
3413
|
// For example 'fr-ca' might be the most specific locale, in which case 'fr' and 'en' are fallback locales.
|
|
@@ -3415,116 +3415,116 @@ class ITwinLocalization {
|
|
|
3415
3415
|
// 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.
|
|
3416
3416
|
|
|
3417
3417
|
|
|
3418
|
-
let locales = (
|
|
3419
|
-
|
|
3420
|
-
|
|
3418
|
+
let locales = (cov_1exkrud5g4().s[58]++, this.getLanguageList().map(thisLocale => {
|
|
3419
|
+
cov_1exkrud5g4().f[15]++;
|
|
3420
|
+
cov_1exkrud5g4().s[59]++;
|
|
3421
3421
|
return `/${thisLocale}/`;
|
|
3422
3422
|
}));
|
|
3423
|
-
|
|
3423
|
+
cov_1exkrud5g4().s[60]++;
|
|
3424
3424
|
|
|
3425
3425
|
try {
|
|
3426
|
-
|
|
3426
|
+
cov_1exkrud5g4().s[61]++;
|
|
3427
3427
|
|
|
3428
3428
|
for (const thisError of err) {
|
|
3429
|
-
|
|
3429
|
+
cov_1exkrud5g4().s[62]++;
|
|
3430
3430
|
|
|
3431
3431
|
if (typeof thisError === "string") {
|
|
3432
|
-
|
|
3433
|
-
|
|
3432
|
+
cov_1exkrud5g4().b[43][0]++;
|
|
3433
|
+
cov_1exkrud5g4().s[63]++;
|
|
3434
3434
|
locales = locales.filter(thisLocale => {
|
|
3435
|
-
|
|
3436
|
-
|
|
3435
|
+
cov_1exkrud5g4().f[16]++;
|
|
3436
|
+
cov_1exkrud5g4().s[64]++;
|
|
3437
3437
|
return !thisError.includes(thisLocale);
|
|
3438
3438
|
});
|
|
3439
3439
|
} else {
|
|
3440
|
-
|
|
3440
|
+
cov_1exkrud5g4().b[43][1]++;
|
|
3441
3441
|
}
|
|
3442
3442
|
}
|
|
3443
3443
|
} catch (e) {
|
|
3444
|
-
|
|
3444
|
+
cov_1exkrud5g4().s[65]++;
|
|
3445
3445
|
locales = [];
|
|
3446
3446
|
} // if we removed every locale from the array, it wasn't loaded.
|
|
3447
3447
|
|
|
3448
3448
|
|
|
3449
|
-
|
|
3449
|
+
cov_1exkrud5g4().s[66]++;
|
|
3450
3450
|
|
|
3451
3451
|
if (locales.length === 0) {
|
|
3452
|
-
|
|
3453
|
-
|
|
3452
|
+
cov_1exkrud5g4().b[44][0]++;
|
|
3453
|
+
cov_1exkrud5g4().s[67]++;
|
|
3454
3454
|
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
3455
3455
|
} else {
|
|
3456
|
-
|
|
3456
|
+
cov_1exkrud5g4().b[44][1]++;
|
|
3457
3457
|
}
|
|
3458
3458
|
|
|
3459
|
-
|
|
3459
|
+
cov_1exkrud5g4().s[68]++;
|
|
3460
3460
|
resolve();
|
|
3461
3461
|
});
|
|
3462
3462
|
}));
|
|
3463
|
-
|
|
3463
|
+
cov_1exkrud5g4().s[69]++;
|
|
3464
3464
|
|
|
3465
3465
|
this._namespaces.set(name, theReadPromise);
|
|
3466
3466
|
|
|
3467
|
-
|
|
3467
|
+
cov_1exkrud5g4().s[70]++;
|
|
3468
3468
|
return theReadPromise;
|
|
3469
3469
|
}
|
|
3470
3470
|
/** @internal */
|
|
3471
3471
|
|
|
3472
3472
|
|
|
3473
3473
|
unregisterNamespace(name) {
|
|
3474
|
-
|
|
3475
|
-
|
|
3474
|
+
cov_1exkrud5g4().f[17]++;
|
|
3475
|
+
cov_1exkrud5g4().s[71]++;
|
|
3476
3476
|
|
|
3477
3477
|
this._namespaces.delete(name);
|
|
3478
3478
|
}
|
|
3479
3479
|
|
|
3480
3480
|
}
|
|
3481
3481
|
|
|
3482
|
-
|
|
3482
|
+
cov_1exkrud5g4().s[72]++;
|
|
3483
3483
|
exports.ITwinLocalization = ITwinLocalization;
|
|
3484
3484
|
|
|
3485
3485
|
class TranslationLogger {
|
|
3486
3486
|
log(args) {
|
|
3487
|
-
|
|
3488
|
-
|
|
3487
|
+
cov_1exkrud5g4().f[18]++;
|
|
3488
|
+
cov_1exkrud5g4().s[73]++;
|
|
3489
3489
|
core_bentley_1.Logger.logInfo("i18n", this.createLogMessage(args));
|
|
3490
3490
|
}
|
|
3491
3491
|
|
|
3492
3492
|
warn(args) {
|
|
3493
|
-
|
|
3494
|
-
|
|
3493
|
+
cov_1exkrud5g4().f[19]++;
|
|
3494
|
+
cov_1exkrud5g4().s[74]++;
|
|
3495
3495
|
core_bentley_1.Logger.logWarning("i18n", this.createLogMessage(args));
|
|
3496
3496
|
}
|
|
3497
3497
|
|
|
3498
3498
|
error(args) {
|
|
3499
|
-
|
|
3500
|
-
|
|
3499
|
+
cov_1exkrud5g4().f[20]++;
|
|
3500
|
+
cov_1exkrud5g4().s[75]++;
|
|
3501
3501
|
core_bentley_1.Logger.logError("i18n", this.createLogMessage(args));
|
|
3502
3502
|
}
|
|
3503
3503
|
|
|
3504
3504
|
createLogMessage(args) {
|
|
3505
|
-
|
|
3506
|
-
let message = (
|
|
3507
|
-
|
|
3505
|
+
cov_1exkrud5g4().f[21]++;
|
|
3506
|
+
let message = (cov_1exkrud5g4().s[76]++, args[0]);
|
|
3507
|
+
cov_1exkrud5g4().s[77]++;
|
|
3508
3508
|
|
|
3509
|
-
for (let i = (
|
|
3510
|
-
|
|
3509
|
+
for (let i = (cov_1exkrud5g4().s[78]++, 1); i < args.length; ++i) {
|
|
3510
|
+
cov_1exkrud5g4().s[79]++;
|
|
3511
3511
|
|
|
3512
3512
|
if (typeof args[i] === "string") {
|
|
3513
|
-
|
|
3514
|
-
|
|
3513
|
+
cov_1exkrud5g4().b[45][0]++;
|
|
3514
|
+
cov_1exkrud5g4().s[80]++;
|
|
3515
3515
|
message += `\n ${args[i]}`;
|
|
3516
3516
|
} else {
|
|
3517
|
-
|
|
3517
|
+
cov_1exkrud5g4().b[45][1]++;
|
|
3518
3518
|
}
|
|
3519
3519
|
}
|
|
3520
3520
|
|
|
3521
|
-
|
|
3521
|
+
cov_1exkrud5g4().s[81]++;
|
|
3522
3522
|
return message;
|
|
3523
3523
|
}
|
|
3524
3524
|
|
|
3525
3525
|
}
|
|
3526
3526
|
|
|
3527
|
-
|
|
3527
|
+
cov_1exkrud5g4().s[82]++;
|
|
3528
3528
|
TranslationLogger.type = "logger";
|
|
3529
3529
|
|
|
3530
3530
|
/***/ }),
|
|
@@ -26618,130 +26618,130 @@ var exports = __webpack_exports__;
|
|
|
26618
26618
|
/*!************************************************!*\
|
|
26619
26619
|
!*** ./lib/cjs/test/ITwinLocalization.test.js ***!
|
|
26620
26620
|
\************************************************/
|
|
26621
|
-
|
|
26622
|
-
/*---------------------------------------------------------------------------------------------
|
|
26623
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
26624
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26625
|
-
*--------------------------------------------------------------------------------------------*/
|
|
26626
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
26627
|
-
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.3.6/node_modules/chai/index.js");
|
|
26628
|
-
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
26629
|
-
describe("ITwinLocalization", () => {
|
|
26630
|
-
let localization;
|
|
26631
|
-
describe("#initialize", () => {
|
|
26632
|
-
describe("with default namespace provided in constructor", () => {
|
|
26633
|
-
let itwinLocalization;
|
|
26634
|
-
before(() => {
|
|
26635
|
-
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
26636
|
-
});
|
|
26637
|
-
it("default namespace set when initialized with empty array", async () => {
|
|
26638
|
-
await itwinLocalization.initialize([]);
|
|
26639
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26640
|
-
});
|
|
26641
|
-
it("default namespace not overridden by one namespace", async () => {
|
|
26642
|
-
await itwinLocalization.initialize(["Test"]);
|
|
26643
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26644
|
-
});
|
|
26645
|
-
it("default namespace not overridden by two namespaces", async () => {
|
|
26646
|
-
await itwinLocalization.initialize(["NotExist", "Test"]);
|
|
26647
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26648
|
-
});
|
|
26649
|
-
it("duplicate namespace value does not break default namespace", async () => {
|
|
26650
|
-
await itwinLocalization.initialize(["Default"]);
|
|
26651
|
-
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26652
|
-
});
|
|
26653
|
-
it("default namespace is in list of all namespaces initalized with empty array", async () => {
|
|
26654
|
-
var _a;
|
|
26655
|
-
await itwinLocalization.initialize([]);
|
|
26656
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26657
|
-
});
|
|
26658
|
-
it("default namespace is in list of all namespaces", async () => {
|
|
26659
|
-
var _a;
|
|
26660
|
-
await itwinLocalization.initialize(["Test"]);
|
|
26661
|
-
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26662
|
-
});
|
|
26663
|
-
});
|
|
26664
|
-
});
|
|
26665
|
-
// The goal is not to test i18next's interpolation,
|
|
26666
|
-
// but just to have some simple tests to make sure the
|
|
26667
|
-
// basics work through the ITwinLocalization class.
|
|
26668
|
-
// For interpolation options, see: https://www.i18next.com/translation-function/interpolation
|
|
26669
|
-
describe("#getLocalizedString", () => {
|
|
26670
|
-
before(async () => {
|
|
26671
|
-
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26672
|
-
await localization.initialize(["Default", "Test"]);
|
|
26673
|
-
});
|
|
26674
|
-
describe("Default Namespace", () => {
|
|
26675
|
-
it("first level with no substitution", () => {
|
|
26676
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26677
|
-
});
|
|
26678
|
-
it("second level with no substitution", () => {
|
|
26679
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26680
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26681
|
-
});
|
|
26682
|
-
it("first level with substitution", () => {
|
|
26683
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26684
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26685
|
-
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26686
|
-
});
|
|
26687
|
-
it("second level with substitution", () => {
|
|
26688
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26689
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26690
|
-
});
|
|
26691
|
-
it("first level missing key doesn't find a value", () => {
|
|
26692
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
26693
|
-
});
|
|
26694
|
-
it("second level missing key doesn't find a value", () => {
|
|
26695
|
-
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26696
|
-
chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26697
|
-
});
|
|
26698
|
-
});
|
|
26699
|
-
describe("Given Namespace", () => {
|
|
26700
|
-
it("first level with no substitution", () => {
|
|
26701
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26702
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26703
|
-
});
|
|
26704
|
-
it("second level with no substitution", () => {
|
|
26705
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26706
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26707
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
26708
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
26709
|
-
});
|
|
26710
|
-
it("first level with substitution", () => {
|
|
26711
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26712
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26713
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26714
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
26715
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
26716
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
26717
|
-
});
|
|
26718
|
-
it("second level with substitution", () => {
|
|
26719
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26720
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26721
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
26722
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
26723
|
-
});
|
|
26724
|
-
it("first level missing key doesn't find a value", () => {
|
|
26725
|
-
chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
26726
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
26727
|
-
});
|
|
26728
|
-
it("second level missing key doesn't find a value", () => {
|
|
26729
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26730
|
-
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26731
|
-
});
|
|
26732
|
-
});
|
|
26733
|
-
describe("Nonexisting Namespace", () => {
|
|
26734
|
-
it("first level fails", () => {
|
|
26735
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
|
|
26736
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
|
|
26737
|
-
});
|
|
26738
|
-
it("second level fails", () => {
|
|
26739
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
26740
|
-
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
|
|
26741
|
-
});
|
|
26742
|
-
});
|
|
26743
|
-
});
|
|
26744
|
-
});
|
|
26621
|
+
|
|
26622
|
+
/*---------------------------------------------------------------------------------------------
|
|
26623
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
26624
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26625
|
+
*--------------------------------------------------------------------------------------------*/
|
|
26626
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
26627
|
+
const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.pnpm/chai@4.3.6/node_modules/chai/index.js");
|
|
26628
|
+
const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
|
|
26629
|
+
describe("ITwinLocalization", () => {
|
|
26630
|
+
let localization;
|
|
26631
|
+
describe("#initialize", () => {
|
|
26632
|
+
describe("with default namespace provided in constructor", () => {
|
|
26633
|
+
let itwinLocalization;
|
|
26634
|
+
before(() => {
|
|
26635
|
+
itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
|
|
26636
|
+
});
|
|
26637
|
+
it("default namespace set when initialized with empty array", async () => {
|
|
26638
|
+
await itwinLocalization.initialize([]);
|
|
26639
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26640
|
+
});
|
|
26641
|
+
it("default namespace not overridden by one namespace", async () => {
|
|
26642
|
+
await itwinLocalization.initialize(["Test"]);
|
|
26643
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26644
|
+
});
|
|
26645
|
+
it("default namespace not overridden by two namespaces", async () => {
|
|
26646
|
+
await itwinLocalization.initialize(["NotExist", "Test"]);
|
|
26647
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26648
|
+
});
|
|
26649
|
+
it("duplicate namespace value does not break default namespace", async () => {
|
|
26650
|
+
await itwinLocalization.initialize(["Default"]);
|
|
26651
|
+
chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
|
|
26652
|
+
});
|
|
26653
|
+
it("default namespace is in list of all namespaces initalized with empty array", async () => {
|
|
26654
|
+
var _a;
|
|
26655
|
+
await itwinLocalization.initialize([]);
|
|
26656
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26657
|
+
});
|
|
26658
|
+
it("default namespace is in list of all namespaces", async () => {
|
|
26659
|
+
var _a;
|
|
26660
|
+
await itwinLocalization.initialize(["Test"]);
|
|
26661
|
+
chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
|
|
26662
|
+
});
|
|
26663
|
+
});
|
|
26664
|
+
});
|
|
26665
|
+
// The goal is not to test i18next's interpolation,
|
|
26666
|
+
// but just to have some simple tests to make sure the
|
|
26667
|
+
// basics work through the ITwinLocalization class.
|
|
26668
|
+
// For interpolation options, see: https://www.i18next.com/translation-function/interpolation
|
|
26669
|
+
describe("#getLocalizedString", () => {
|
|
26670
|
+
before(async () => {
|
|
26671
|
+
localization = new ITwinLocalization_1.ITwinLocalization();
|
|
26672
|
+
await localization.initialize(["Default", "Test"]);
|
|
26673
|
+
});
|
|
26674
|
+
describe("Default Namespace", () => {
|
|
26675
|
+
it("first level with no substitution", () => {
|
|
26676
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
|
|
26677
|
+
});
|
|
26678
|
+
it("second level with no substitution", () => {
|
|
26679
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26680
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26681
|
+
});
|
|
26682
|
+
it("first level with substitution", () => {
|
|
26683
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26684
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26685
|
+
chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26686
|
+
});
|
|
26687
|
+
it("second level with substitution", () => {
|
|
26688
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26689
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26690
|
+
});
|
|
26691
|
+
it("first level missing key doesn't find a value", () => {
|
|
26692
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
|
|
26693
|
+
});
|
|
26694
|
+
it("second level missing key doesn't find a value", () => {
|
|
26695
|
+
chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26696
|
+
chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26697
|
+
});
|
|
26698
|
+
});
|
|
26699
|
+
describe("Given Namespace", () => {
|
|
26700
|
+
it("first level with no substitution", () => {
|
|
26701
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
|
|
26702
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
|
|
26703
|
+
});
|
|
26704
|
+
it("second level with no substitution", () => {
|
|
26705
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
26706
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
|
|
26707
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
|
|
26708
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
|
|
26709
|
+
});
|
|
26710
|
+
it("first level with substitution", () => {
|
|
26711
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
26712
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
26713
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
26714
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
26715
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
26716
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
26717
|
+
});
|
|
26718
|
+
it("second level with substitution", () => {
|
|
26719
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
26720
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
26721
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
26722
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
26723
|
+
});
|
|
26724
|
+
it("first level missing key doesn't find a value", () => {
|
|
26725
|
+
chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
|
|
26726
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
|
|
26727
|
+
});
|
|
26728
|
+
it("second level missing key doesn't find a value", () => {
|
|
26729
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
|
|
26730
|
+
chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
|
|
26731
|
+
});
|
|
26732
|
+
});
|
|
26733
|
+
describe("Nonexisting Namespace", () => {
|
|
26734
|
+
it("first level fails", () => {
|
|
26735
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
|
|
26736
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
|
|
26737
|
+
});
|
|
26738
|
+
it("second level fails", () => {
|
|
26739
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
|
|
26740
|
+
chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
|
|
26741
|
+
});
|
|
26742
|
+
});
|
|
26743
|
+
});
|
|
26744
|
+
});
|
|
26745
26745
|
|
|
26746
26746
|
})();
|
|
26747
26747
|
|