@itwin/core-i18n 5.14.0-dev.17 → 5.14.0-dev.18
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/lib/cjs/test/webpack/bundled-tests.instrumented.js +122 -122
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.js.map +1 -1
- package/lib/cjs/test/webpack/vendors-common_temp_node_modules_pnpm_cross-fetch_4_1_0_node_modules_cross-fetch_dist_browser-44272f.bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/vendors-common_temp_node_modules_pnpm_cross-fetch_4_1_0_node_modules_cross-fetch_dist_browser-44272f.bundled-tests.js.map +1 -1
- package/package.json +6 -6
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
/** @packageDocumentation
|
|
18
18
|
* @module Localization
|
|
19
19
|
*/
|
|
20
|
-
function
|
|
21
|
-
var path = "C:\\agent\\_work\\
|
|
22
|
-
var hash = "
|
|
20
|
+
function cov_1wctd2lw3r() {
|
|
21
|
+
var path = "C:\\agent\\_work\\2\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js";
|
|
22
|
+
var hash = "11843a9389894bd74427d7137f54e50ca9e52905";
|
|
23
23
|
var global = new Function("return this")();
|
|
24
24
|
var gcv = "__coverage__";
|
|
25
25
|
var coverageData = {
|
|
26
|
-
path: "C:\\agent\\_work\\
|
|
26
|
+
path: "C:\\agent\\_work\\2\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js",
|
|
27
27
|
statementMap: {
|
|
28
28
|
"0": {
|
|
29
29
|
start: {
|
|
@@ -1995,13 +1995,13 @@ function cov_ogldeftyv() {
|
|
|
1995
1995
|
inputSourceMap: {
|
|
1996
1996
|
version: 3,
|
|
1997
1997
|
file: "ITwinLocalization.js",
|
|
1998
|
-
sources: ["C:\\agent\\_work\\
|
|
1998
|
+
sources: ["C:\\agent\\_work\\2\\s\\core\\i18n\\src\\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c,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,CAAC;YACrC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAC7B,OAAO,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAChC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC",
|
|
2001
2001
|
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, { HttpBackendOptions as 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 /** 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 // i18next can return errors from other concurrent namespace loads in this callback.\r\n const wasLoaded = this.getLanguageList().some((language) => this.i18next.hasResourceBundle(language, name));\r\n if (!wasLoaded)\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"]
|
|
2002
2002
|
},
|
|
2003
2003
|
_coverageSchema: "1a1c01bbd47fc00a2c39e90264f33305004495a9",
|
|
2004
|
-
hash: "
|
|
2004
|
+
hash: "11843a9389894bd74427d7137f54e50ca9e52905"
|
|
2005
2005
|
};
|
|
2006
2006
|
var coverage = global[gcv] || (global[gcv] = {});
|
|
2007
2007
|
if (!coverage[path] || coverage[path].hash !== hash) {
|
|
@@ -2010,31 +2010,31 @@ function cov_ogldeftyv() {
|
|
|
2010
2010
|
var actualCoverage = coverage[path];
|
|
2011
2011
|
{
|
|
2012
2012
|
// @ts-ignore
|
|
2013
|
-
|
|
2013
|
+
cov_1wctd2lw3r = function () {
|
|
2014
2014
|
return actualCoverage;
|
|
2015
2015
|
};
|
|
2016
2016
|
}
|
|
2017
2017
|
return actualCoverage;
|
|
2018
2018
|
}
|
|
2019
|
-
|
|
2020
|
-
var __importDefault = (
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
return (
|
|
2019
|
+
cov_1wctd2lw3r();
|
|
2020
|
+
var __importDefault = (cov_1wctd2lw3r().s[0]++, (cov_1wctd2lw3r().b[0][0]++, this) && (cov_1wctd2lw3r().b[0][1]++, this.__importDefault) || (cov_1wctd2lw3r().b[0][2]++, function (mod) {
|
|
2021
|
+
cov_1wctd2lw3r().f[0]++;
|
|
2022
|
+
cov_1wctd2lw3r().s[1]++;
|
|
2023
|
+
return (cov_1wctd2lw3r().b[2][0]++, mod) && (cov_1wctd2lw3r().b[2][1]++, mod.__esModule) ? (cov_1wctd2lw3r().b[1][0]++, mod) : (cov_1wctd2lw3r().b[1][1]++, {
|
|
2024
2024
|
"default": mod
|
|
2025
2025
|
});
|
|
2026
2026
|
}));
|
|
2027
|
-
|
|
2027
|
+
cov_1wctd2lw3r().s[2]++;
|
|
2028
2028
|
Object.defineProperty(exports, "__esModule", ({
|
|
2029
2029
|
value: true
|
|
2030
2030
|
}));
|
|
2031
|
-
|
|
2031
|
+
cov_1wctd2lw3r().s[3]++;
|
|
2032
2032
|
exports.ITwinLocalization = void 0;
|
|
2033
|
-
const i18next_1 = (
|
|
2034
|
-
const i18next_browser_languagedetector_1 = (
|
|
2035
|
-
const i18next_http_backend_1 = (
|
|
2036
|
-
const core_bentley_1 = (
|
|
2037
|
-
const DEFAULT_MAX_RETRIES = (
|
|
2033
|
+
const i18next_1 = (cov_1wctd2lw3r().s[4]++, __importDefault(__webpack_require__(/*! i18next */ "../../common/temp/node_modules/.pnpm/i18next@21.10.0/node_modules/i18next/dist/cjs/i18next.js")));
|
|
2034
|
+
const i18next_browser_languagedetector_1 = (cov_1wctd2lw3r().s[5]++, __importDefault(__webpack_require__(/*! i18next-browser-languagedetector */ "../../common/temp/node_modules/.pnpm/i18next-browser-languagedetector@6.1.8/node_modules/i18next-browser-languagedetector/dist/cjs/i18nextBrowserLanguageDetector.js")));
|
|
2035
|
+
const i18next_http_backend_1 = (cov_1wctd2lw3r().s[6]++, __importDefault(__webpack_require__(/*! i18next-http-backend */ "../../common/temp/node_modules/.pnpm/i18next-http-backend@3.0.6/node_modules/i18next-http-backend/esm/index.js")));
|
|
2036
|
+
const core_bentley_1 = (cov_1wctd2lw3r().s[7]++, __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js"));
|
|
2037
|
+
const DEFAULT_MAX_RETRIES = (cov_1wctd2lw3r().s[8]++, 1); // a low number prevents wasted time and potential timeouts when requesting localization files throws an error
|
|
2038
2038
|
/** Supplies localizations for iTwin.js
|
|
2039
2039
|
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
2040
2040
|
* @public
|
|
@@ -2044,25 +2044,25 @@ class ITwinLocalization {
|
|
|
2044
2044
|
_initOptions;
|
|
2045
2045
|
_backendOptions;
|
|
2046
2046
|
_detectionOptions;
|
|
2047
|
-
_namespaces = (
|
|
2047
|
+
_namespaces = (cov_1wctd2lw3r().s[9]++, new Map());
|
|
2048
2048
|
constructor(options) {
|
|
2049
|
-
|
|
2050
|
-
|
|
2049
|
+
cov_1wctd2lw3r().f[1]++;
|
|
2050
|
+
cov_1wctd2lw3r().s[10]++;
|
|
2051
2051
|
this.i18next = i18next_1.default.createInstance();
|
|
2052
|
-
|
|
2052
|
+
cov_1wctd2lw3r().s[11]++;
|
|
2053
2053
|
this._backendOptions = {
|
|
2054
|
-
loadPath: (
|
|
2054
|
+
loadPath: (cov_1wctd2lw3r().b[3][0]++, options?.urlTemplate) ?? (cov_1wctd2lw3r().b[3][1]++, "locales/{{lng}}/{{ns}}.json"),
|
|
2055
2055
|
crossDomain: true,
|
|
2056
2056
|
...options?.backendHttpOptions
|
|
2057
2057
|
};
|
|
2058
|
-
|
|
2058
|
+
cov_1wctd2lw3r().s[12]++;
|
|
2059
2059
|
this._detectionOptions = {
|
|
2060
2060
|
order: ["querystring", "navigator", "htmlTag"],
|
|
2061
2061
|
lookupQuerystring: "lng",
|
|
2062
2062
|
caches: [],
|
|
2063
2063
|
...options?.detectorOptions
|
|
2064
2064
|
};
|
|
2065
|
-
|
|
2065
|
+
cov_1wctd2lw3r().s[13]++;
|
|
2066
2066
|
this._initOptions = {
|
|
2067
2067
|
interpolation: {
|
|
2068
2068
|
escapeValue: true
|
|
@@ -2073,41 +2073,41 @@ class ITwinLocalization {
|
|
|
2073
2073
|
detection: this._detectionOptions,
|
|
2074
2074
|
...options?.initOptions
|
|
2075
2075
|
};
|
|
2076
|
-
|
|
2077
|
-
this.i18next.use((
|
|
2076
|
+
cov_1wctd2lw3r().s[14]++;
|
|
2077
|
+
this.i18next.use((cov_1wctd2lw3r().b[4][0]++, options?.detectorPlugin) ?? (cov_1wctd2lw3r().b[4][1]++, i18next_browser_languagedetector_1.default)).use((cov_1wctd2lw3r().b[5][0]++, options?.backendPlugin) ?? (cov_1wctd2lw3r().b[5][1]++, i18next_http_backend_1.default)).use(TranslationLogger);
|
|
2078
2078
|
}
|
|
2079
2079
|
async initialize(namespaces) {
|
|
2080
|
-
|
|
2080
|
+
cov_1wctd2lw3r().f[2]++;
|
|
2081
2081
|
// Also consider namespaces passed into constructor
|
|
2082
|
-
const initNamespaces = (
|
|
2083
|
-
const combinedNamespaces = (
|
|
2084
|
-
const defaultNamespace = (
|
|
2085
|
-
|
|
2082
|
+
const initNamespaces = (cov_1wctd2lw3r().s[15]++, [(cov_1wctd2lw3r().b[6][0]++, this._initOptions.ns) || (cov_1wctd2lw3r().b[6][1]++, [])].flat());
|
|
2083
|
+
const combinedNamespaces = (cov_1wctd2lw3r().s[16]++, new Set([...namespaces, ...initNamespaces])); // without duplicates
|
|
2084
|
+
const defaultNamespace = (cov_1wctd2lw3r().s[17]++, (cov_1wctd2lw3r().b[7][0]++, this._initOptions.defaultNS) ?? (cov_1wctd2lw3r().b[7][1]++, namespaces[0]));
|
|
2085
|
+
cov_1wctd2lw3r().s[18]++;
|
|
2086
2086
|
if (defaultNamespace) {
|
|
2087
|
-
|
|
2088
|
-
|
|
2087
|
+
cov_1wctd2lw3r().b[8][0]++;
|
|
2088
|
+
cov_1wctd2lw3r().s[19]++;
|
|
2089
2089
|
combinedNamespaces.add(defaultNamespace);
|
|
2090
2090
|
} else {
|
|
2091
|
-
|
|
2091
|
+
cov_1wctd2lw3r().b[8][1]++;
|
|
2092
2092
|
} // Make sure default namespace is in namespaces list
|
|
2093
|
-
const initOptions = (
|
|
2093
|
+
const initOptions = (cov_1wctd2lw3r().s[20]++, {
|
|
2094
2094
|
...this._initOptions,
|
|
2095
2095
|
defaultNS: defaultNamespace,
|
|
2096
2096
|
ns: [...combinedNamespaces]
|
|
2097
2097
|
});
|
|
2098
2098
|
// if in a development environment, set debugging
|
|
2099
|
-
|
|
2099
|
+
cov_1wctd2lw3r().s[21]++;
|
|
2100
2100
|
if (false) // removed by dead control flow
|
|
2101
2101
|
{} else {
|
|
2102
|
-
|
|
2102
|
+
cov_1wctd2lw3r().b[9][1]++;
|
|
2103
2103
|
}
|
|
2104
|
-
const initPromise = (
|
|
2105
|
-
|
|
2104
|
+
const initPromise = (cov_1wctd2lw3r().s[23]++, this.i18next.init(initOptions));
|
|
2105
|
+
cov_1wctd2lw3r().s[24]++;
|
|
2106
2106
|
for (const ns of namespaces) {
|
|
2107
|
-
|
|
2107
|
+
cov_1wctd2lw3r().s[25]++;
|
|
2108
2108
|
this._namespaces.set(ns, initPromise);
|
|
2109
2109
|
}
|
|
2110
|
-
|
|
2110
|
+
cov_1wctd2lw3r().s[26]++;
|
|
2111
2111
|
return initPromise;
|
|
2112
2112
|
}
|
|
2113
2113
|
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
@@ -2127,11 +2127,11 @@ class ITwinLocalization {
|
|
|
2127
2127
|
* @public
|
|
2128
2128
|
*/
|
|
2129
2129
|
getLocalizedKeys(line) {
|
|
2130
|
-
|
|
2131
|
-
|
|
2130
|
+
cov_1wctd2lw3r().f[3]++;
|
|
2131
|
+
cov_1wctd2lw3r().s[27]++;
|
|
2132
2132
|
return line.replace(/\%\{(.+?)\}/g, (_match, tag) => {
|
|
2133
|
-
|
|
2134
|
-
|
|
2133
|
+
cov_1wctd2lw3r().f[4]++;
|
|
2134
|
+
cov_1wctd2lw3r().s[28]++;
|
|
2135
2135
|
return this.getLocalizedString(tag);
|
|
2136
2136
|
});
|
|
2137
2137
|
}
|
|
@@ -2149,25 +2149,25 @@ class ITwinLocalization {
|
|
|
2149
2149
|
* @public
|
|
2150
2150
|
*/
|
|
2151
2151
|
getLocalizedString(key, options) {
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
if ((
|
|
2155
|
-
|
|
2156
|
-
|
|
2152
|
+
cov_1wctd2lw3r().f[5]++;
|
|
2153
|
+
cov_1wctd2lw3r().s[29]++;
|
|
2154
|
+
if ((cov_1wctd2lw3r().b[11][0]++, options?.returnDetails) || (cov_1wctd2lw3r().b[11][1]++, options?.returnObjects)) {
|
|
2155
|
+
cov_1wctd2lw3r().b[10][0]++;
|
|
2156
|
+
cov_1wctd2lw3r().s[30]++;
|
|
2157
2157
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
2158
2158
|
} else {
|
|
2159
|
-
|
|
2159
|
+
cov_1wctd2lw3r().b[10][1]++;
|
|
2160
2160
|
}
|
|
2161
|
-
const value = (
|
|
2162
|
-
|
|
2161
|
+
const value = (cov_1wctd2lw3r().s[31]++, this.i18next.t(key, options));
|
|
2162
|
+
cov_1wctd2lw3r().s[32]++;
|
|
2163
2163
|
if (typeof value !== "string") {
|
|
2164
|
-
|
|
2165
|
-
|
|
2164
|
+
cov_1wctd2lw3r().b[12][0]++;
|
|
2165
|
+
cov_1wctd2lw3r().s[33]++;
|
|
2166
2166
|
throw new Error("Translation key(s) string not found");
|
|
2167
2167
|
} else {
|
|
2168
|
-
|
|
2168
|
+
cov_1wctd2lw3r().b[12][1]++;
|
|
2169
2169
|
}
|
|
2170
|
-
|
|
2170
|
+
cov_1wctd2lw3r().s[34]++;
|
|
2171
2171
|
return value;
|
|
2172
2172
|
}
|
|
2173
2173
|
/** Gets the English translation.
|
|
@@ -2178,31 +2178,31 @@ class ITwinLocalization {
|
|
|
2178
2178
|
* @internal
|
|
2179
2179
|
*/
|
|
2180
2180
|
getEnglishString(namespace, key, options) {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
if ((
|
|
2184
|
-
|
|
2185
|
-
|
|
2181
|
+
cov_1wctd2lw3r().f[6]++;
|
|
2182
|
+
cov_1wctd2lw3r().s[35]++;
|
|
2183
|
+
if ((cov_1wctd2lw3r().b[14][0]++, options?.returnDetails) || (cov_1wctd2lw3r().b[14][1]++, options?.returnObjects)) {
|
|
2184
|
+
cov_1wctd2lw3r().b[13][0]++;
|
|
2185
|
+
cov_1wctd2lw3r().s[36]++;
|
|
2186
2186
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
2187
2187
|
} else {
|
|
2188
|
-
|
|
2188
|
+
cov_1wctd2lw3r().b[13][1]++;
|
|
2189
2189
|
}
|
|
2190
|
-
|
|
2190
|
+
cov_1wctd2lw3r().s[37]++;
|
|
2191
2191
|
options = {
|
|
2192
2192
|
...options,
|
|
2193
2193
|
ns: namespace // ensure namespace argument is used
|
|
2194
2194
|
};
|
|
2195
|
-
const en = (
|
|
2196
|
-
const str = (
|
|
2197
|
-
|
|
2195
|
+
const en = (cov_1wctd2lw3r().s[38]++, this.i18next.getFixedT("en", namespace));
|
|
2196
|
+
const str = (cov_1wctd2lw3r().s[39]++, en(key, options));
|
|
2197
|
+
cov_1wctd2lw3r().s[40]++;
|
|
2198
2198
|
if (typeof str !== "string") {
|
|
2199
|
-
|
|
2200
|
-
|
|
2199
|
+
cov_1wctd2lw3r().b[15][0]++;
|
|
2200
|
+
cov_1wctd2lw3r().s[41]++;
|
|
2201
2201
|
throw new Error("Translation key(s) not found");
|
|
2202
2202
|
} else {
|
|
2203
|
-
|
|
2203
|
+
cov_1wctd2lw3r().b[15][1]++;
|
|
2204
2204
|
}
|
|
2205
|
-
|
|
2205
|
+
cov_1wctd2lw3r().s[42]++;
|
|
2206
2206
|
return str;
|
|
2207
2207
|
}
|
|
2208
2208
|
/** Get the promise for an already registered Namespace.
|
|
@@ -2210,20 +2210,20 @@ class ITwinLocalization {
|
|
|
2210
2210
|
* @public
|
|
2211
2211
|
*/
|
|
2212
2212
|
getNamespacePromise(name) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2213
|
+
cov_1wctd2lw3r().f[7]++;
|
|
2214
|
+
cov_1wctd2lw3r().s[43]++;
|
|
2215
2215
|
return this._namespaces.get(name);
|
|
2216
2216
|
}
|
|
2217
2217
|
/** @internal */
|
|
2218
2218
|
getLanguageList() {
|
|
2219
|
-
|
|
2220
|
-
|
|
2219
|
+
cov_1wctd2lw3r().f[8]++;
|
|
2220
|
+
cov_1wctd2lw3r().s[44]++;
|
|
2221
2221
|
return this.i18next.languages;
|
|
2222
2222
|
}
|
|
2223
2223
|
/** override the language detected in the browser */
|
|
2224
2224
|
async changeLanguage(language) {
|
|
2225
|
-
|
|
2226
|
-
|
|
2225
|
+
cov_1wctd2lw3r().f[9]++;
|
|
2226
|
+
cov_1wctd2lw3r().s[45]++;
|
|
2227
2227
|
return this.i18next.changeLanguage(language);
|
|
2228
2228
|
}
|
|
2229
2229
|
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
@@ -2235,94 +2235,94 @@ class ITwinLocalization {
|
|
|
2235
2235
|
* @public
|
|
2236
2236
|
*/
|
|
2237
2237
|
async registerNamespace(name) {
|
|
2238
|
-
|
|
2239
|
-
const existing = (
|
|
2240
|
-
|
|
2238
|
+
cov_1wctd2lw3r().f[10]++;
|
|
2239
|
+
const existing = (cov_1wctd2lw3r().s[46]++, this._namespaces.get(name));
|
|
2240
|
+
cov_1wctd2lw3r().s[47]++;
|
|
2241
2241
|
if (existing !== undefined) {
|
|
2242
|
-
|
|
2243
|
-
|
|
2242
|
+
cov_1wctd2lw3r().b[16][0]++;
|
|
2243
|
+
cov_1wctd2lw3r().s[48]++;
|
|
2244
2244
|
return existing;
|
|
2245
2245
|
} else {
|
|
2246
|
-
|
|
2246
|
+
cov_1wctd2lw3r().b[16][1]++;
|
|
2247
2247
|
}
|
|
2248
|
-
const theReadPromise = (
|
|
2249
|
-
|
|
2250
|
-
|
|
2248
|
+
const theReadPromise = (cov_1wctd2lw3r().s[49]++, new Promise(resolve => {
|
|
2249
|
+
cov_1wctd2lw3r().f[11]++;
|
|
2250
|
+
cov_1wctd2lw3r().s[50]++;
|
|
2251
2251
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
2252
2252
|
this.i18next.loadNamespaces(name, err => {
|
|
2253
|
-
|
|
2254
|
-
|
|
2253
|
+
cov_1wctd2lw3r().f[12]++;
|
|
2254
|
+
cov_1wctd2lw3r().s[51]++;
|
|
2255
2255
|
if (!err) {
|
|
2256
|
-
|
|
2257
|
-
|
|
2256
|
+
cov_1wctd2lw3r().b[17][0]++;
|
|
2257
|
+
cov_1wctd2lw3r().s[52]++;
|
|
2258
2258
|
return resolve();
|
|
2259
2259
|
} else {
|
|
2260
|
-
|
|
2260
|
+
cov_1wctd2lw3r().b[17][1]++;
|
|
2261
2261
|
}
|
|
2262
2262
|
// i18next can return errors from other concurrent namespace loads in this callback.
|
|
2263
|
-
const wasLoaded = (
|
|
2264
|
-
|
|
2265
|
-
|
|
2263
|
+
const wasLoaded = (cov_1wctd2lw3r().s[53]++, this.getLanguageList().some(language => {
|
|
2264
|
+
cov_1wctd2lw3r().f[13]++;
|
|
2265
|
+
cov_1wctd2lw3r().s[54]++;
|
|
2266
2266
|
return this.i18next.hasResourceBundle(language, name);
|
|
2267
2267
|
}));
|
|
2268
|
-
|
|
2268
|
+
cov_1wctd2lw3r().s[55]++;
|
|
2269
2269
|
if (!wasLoaded) {
|
|
2270
|
-
|
|
2271
|
-
|
|
2270
|
+
cov_1wctd2lw3r().b[18][0]++;
|
|
2271
|
+
cov_1wctd2lw3r().s[56]++;
|
|
2272
2272
|
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
2273
2273
|
} else {
|
|
2274
|
-
|
|
2274
|
+
cov_1wctd2lw3r().b[18][1]++;
|
|
2275
2275
|
}
|
|
2276
|
-
|
|
2276
|
+
cov_1wctd2lw3r().s[57]++;
|
|
2277
2277
|
resolve();
|
|
2278
2278
|
});
|
|
2279
2279
|
}));
|
|
2280
|
-
|
|
2280
|
+
cov_1wctd2lw3r().s[58]++;
|
|
2281
2281
|
this._namespaces.set(name, theReadPromise);
|
|
2282
|
-
|
|
2282
|
+
cov_1wctd2lw3r().s[59]++;
|
|
2283
2283
|
return theReadPromise;
|
|
2284
2284
|
}
|
|
2285
2285
|
/** @internal */
|
|
2286
2286
|
unregisterNamespace(name) {
|
|
2287
|
-
|
|
2288
|
-
|
|
2287
|
+
cov_1wctd2lw3r().f[14]++;
|
|
2288
|
+
cov_1wctd2lw3r().s[60]++;
|
|
2289
2289
|
this._namespaces.delete(name);
|
|
2290
2290
|
}
|
|
2291
2291
|
}
|
|
2292
|
-
|
|
2292
|
+
cov_1wctd2lw3r().s[61]++;
|
|
2293
2293
|
exports.ITwinLocalization = ITwinLocalization;
|
|
2294
2294
|
class TranslationLogger {
|
|
2295
|
-
static type = (
|
|
2295
|
+
static type = (cov_1wctd2lw3r().s[62]++, "logger");
|
|
2296
2296
|
log(args) {
|
|
2297
|
-
|
|
2298
|
-
|
|
2297
|
+
cov_1wctd2lw3r().f[15]++;
|
|
2298
|
+
cov_1wctd2lw3r().s[63]++;
|
|
2299
2299
|
core_bentley_1.Logger.logInfo("i18n", this.createLogMessage(args));
|
|
2300
2300
|
}
|
|
2301
2301
|
warn(args) {
|
|
2302
|
-
|
|
2303
|
-
|
|
2302
|
+
cov_1wctd2lw3r().f[16]++;
|
|
2303
|
+
cov_1wctd2lw3r().s[64]++;
|
|
2304
2304
|
core_bentley_1.Logger.logWarning("i18n", this.createLogMessage(args));
|
|
2305
2305
|
}
|
|
2306
2306
|
error(args) {
|
|
2307
|
-
|
|
2308
|
-
|
|
2307
|
+
cov_1wctd2lw3r().f[17]++;
|
|
2308
|
+
cov_1wctd2lw3r().s[65]++;
|
|
2309
2309
|
core_bentley_1.Logger.logError("i18n", this.createLogMessage(args));
|
|
2310
2310
|
}
|
|
2311
2311
|
createLogMessage(args) {
|
|
2312
|
-
|
|
2313
|
-
let message = (
|
|
2314
|
-
|
|
2315
|
-
for (let i = (
|
|
2316
|
-
|
|
2312
|
+
cov_1wctd2lw3r().f[18]++;
|
|
2313
|
+
let message = (cov_1wctd2lw3r().s[66]++, args[0]);
|
|
2314
|
+
cov_1wctd2lw3r().s[67]++;
|
|
2315
|
+
for (let i = (cov_1wctd2lw3r().s[68]++, 1); i < args.length; ++i) {
|
|
2316
|
+
cov_1wctd2lw3r().s[69]++;
|
|
2317
2317
|
if (typeof args[i] === "string") {
|
|
2318
|
-
|
|
2319
|
-
|
|
2318
|
+
cov_1wctd2lw3r().b[19][0]++;
|
|
2319
|
+
cov_1wctd2lw3r().s[70]++;
|
|
2320
2320
|
message += `\n ${args[i]}`;
|
|
2321
2321
|
} else {
|
|
2322
|
-
|
|
2322
|
+
cov_1wctd2lw3r().b[19][1]++;
|
|
2323
2323
|
}
|
|
2324
2324
|
}
|
|
2325
|
-
|
|
2325
|
+
cov_1wctd2lw3r().s[71]++;
|
|
2326
2326
|
return message;
|
|
2327
2327
|
}
|
|
2328
2328
|
}
|