@itwin/core-i18n 3.5.0-dev.5 → 3.5.0-dev.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ITwinLocalization.js","sourceRoot":"","sources":["../../src/ITwinLocalization.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,OAAoD,MAAM,SAAS,CAAC;AAC3E,OAAO,8BAAmD,MAAM,kCAAkC,CAAC;AACnG,OAAO,OAA2B,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,MAAM,mBAAmB,GAAW,CAAC,CAAC,CAAC,8GAA8G;AAcrJ;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAO5B,YAAmB,OAA6B;;QAF/B,gBAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;QAG9D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;QAExC,IAAI,CAAC,eAAe,GAAG;YACrB,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,6BAA6B;YAC/D,WAAW,EAAE,IAAI;YACjB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB;SAC/B,CAAC;QAEF,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,CAAC;YAC9C,iBAAiB,EAAE,KAAK;YACxB,MAAM,EAAE,EAAE;YACV,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe;SAC5B,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG;YAClB,aAAa,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;YACpC,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,mBAAmB;YAC/B,OAAO,EAAE,IAAI,CAAC,eAA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,CAAC,IAAc,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,gBAAgB,CAAC,IAAc;QACrC,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACpC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAC7B,OAAO,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/B;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;;AAXsB,sBAAI,GAAG,QAAQ,CAAC","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"]}
1
+ {"version":3,"file":"ITwinLocalization.js","sourceRoot":"","sources":["../../src/ITwinLocalization.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,OAAoD,MAAM,SAAS,CAAC;AAC3E,OAAO,8BAAmD,MAAM,kCAAkC,CAAC;AACnG,OAAO,OAA2B,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,MAAM,mBAAmB,GAAW,CAAC,CAAC,CAAC,8GAA8G;AAcrJ;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAO5B,YAAmB,OAA6B;;QAF/B,gBAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;QAG9D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;QAExC,IAAI,CAAC,eAAe,GAAG;YACrB,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,6BAA6B;YAC/D,WAAW,EAAE,IAAI;YACjB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB;SAC/B,CAAC;QAEF,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,S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CACF;AAED,MAAM,iBAAiB;IAEd,GAAG,CAAC,IAAc,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,IAAI,CAAC,IAAc,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,KAAK,CAAC,IAAc,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,gBAAgB,CAAC,IAAc;QACrC,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACpC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAC7B,OAAO,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/B;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;;AAXsB,sBAAI,GAAG,QAAQ,CAAC","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"]}
@@ -1,8 +1,8 @@
1
- export * from "./ITwinLocalization";
2
- /** @docs-package-description
3
- * The core-i18n package contains classes related to internationalization and localization.
4
- */
5
- /** @docs-group-description Localization
6
- * Classes for internationalization and localization of your app.
7
- */
1
+ export * from "./ITwinLocalization";
2
+ /** @docs-package-description
3
+ * The core-i18n package contains classes related to internationalization and localization.
4
+ */
5
+ /** @docs-group-description Localization
6
+ * Classes for internationalization and localization of your app.
7
+ */
8
8
  //# sourceMappingURL=core-i18n.d.ts.map
@@ -1,12 +1,12 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- export * from "./ITwinLocalization";
6
- /** @docs-package-description
7
- * The core-i18n package contains classes related to internationalization and localization.
8
- */
9
- /** @docs-group-description Localization
10
- * Classes for internationalization and localization of your app.
11
- */
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ export * from "./ITwinLocalization";
6
+ /** @docs-package-description
7
+ * The core-i18n package contains classes related to internationalization and localization.
8
+ */
9
+ /** @docs-group-description Localization
10
+ * Classes for internationalization and localization of your app.
11
+ */
12
12
  //# sourceMappingURL=core-i18n.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-i18n.js","sourceRoot":"","sources":["../../src/core-i18n.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AAEH;;GAEG","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\nexport * from \"./ITwinLocalization\";\n\n/** @docs-package-description\n * The core-i18n package contains classes related to internationalization and localization.\n */\n\n/** @docs-group-description Localization\n * Classes for internationalization and localization of your app.\n */\n"]}
1
+ {"version":3,"file":"core-i18n.js","sourceRoot":"","sources":["../../src/core-i18n.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AAEH;;GAEG","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\r\nexport * from \"./ITwinLocalization\";\r\n\r\n/** @docs-package-description\r\n * The core-i18n package contains classes related to internationalization and localization.\r\n */\r\n\r\n/** @docs-group-description Localization\r\n * Classes for internationalization and localization of your app.\r\n */\r\n"]}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=ITwinLocalization.test.d.ts.map
@@ -1,123 +1,123 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- import { assert } from "chai";
6
- import { ITwinLocalization } from "../ITwinLocalization";
7
- describe("ITwinLocalization", () => {
8
- let localization;
9
- describe("#initialize", () => {
10
- describe("with default namespace provided in constructor", () => {
11
- let itwinLocalization;
12
- before(() => {
13
- itwinLocalization = new ITwinLocalization({ initOptions: { defaultNS: "Default" } });
14
- });
15
- it("default namespace set when initialized with empty array", async () => {
16
- await itwinLocalization.initialize([]);
17
- assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
18
- });
19
- it("default namespace not overridden by one namespace", async () => {
20
- await itwinLocalization.initialize(["Test"]);
21
- assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
22
- });
23
- it("default namespace not overridden by two namespaces", async () => {
24
- await itwinLocalization.initialize(["NotExist", "Test"]);
25
- assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
26
- });
27
- it("duplicate namespace value does not break default namespace", async () => {
28
- await itwinLocalization.initialize(["Default"]);
29
- assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
30
- });
31
- it("default namespace is in list of all namespaces initalized with empty array", async () => {
32
- var _a;
33
- await itwinLocalization.initialize([]);
34
- assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
35
- });
36
- it("default namespace is in list of all namespaces", async () => {
37
- var _a;
38
- await itwinLocalization.initialize(["Test"]);
39
- assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
40
- });
41
- });
42
- });
43
- // The goal is not to test i18next's interpolation,
44
- // but just to have some simple tests to make sure the
45
- // basics work through the ITwinLocalization class.
46
- // For interpolation options, see: https://www.i18next.com/translation-function/interpolation
47
- describe("#getLocalizedString", () => {
48
- before(async () => {
49
- localization = new ITwinLocalization();
50
- await localization.initialize(["Default", "Test"]);
51
- });
52
- describe("Default Namespace", () => {
53
- it("first level with no substitution", () => {
54
- assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
55
- });
56
- it("second level with no substitution", () => {
57
- assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
58
- assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
59
- });
60
- it("first level with substitution", () => {
61
- assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
62
- assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
63
- assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
64
- });
65
- it("second level with substitution", () => {
66
- assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
67
- assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
68
- });
69
- it("first level missing key doesn't find a value", () => {
70
- assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
71
- });
72
- it("second level missing key doesn't find a value", () => {
73
- assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
74
- assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
75
- });
76
- });
77
- describe("Given Namespace", () => {
78
- it("first level with no substitution", () => {
79
- assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
80
- assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
81
- });
82
- it("second level with no substitution", () => {
83
- assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
84
- assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
85
- assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
86
- assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
87
- });
88
- it("first level with substitution", () => {
89
- assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
90
- assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
91
- assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
92
- assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
93
- assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
94
- assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
95
- });
96
- it("second level with substitution", () => {
97
- assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
98
- assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
99
- assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
100
- assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
101
- });
102
- it("first level missing key doesn't find a value", () => {
103
- assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
104
- assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
105
- });
106
- it("second level missing key doesn't find a value", () => {
107
- assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
108
- assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
109
- });
110
- });
111
- describe("Nonexisting Namespace", () => {
112
- it("first level fails", () => {
113
- assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
114
- assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
115
- });
116
- it("second level fails", () => {
117
- assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
118
- assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
119
- });
120
- });
121
- });
122
- });
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { assert } from "chai";
6
+ import { ITwinLocalization } from "../ITwinLocalization";
7
+ describe("ITwinLocalization", () => {
8
+ let localization;
9
+ describe("#initialize", () => {
10
+ describe("with default namespace provided in constructor", () => {
11
+ let itwinLocalization;
12
+ before(() => {
13
+ itwinLocalization = new ITwinLocalization({ initOptions: { defaultNS: "Default" } });
14
+ });
15
+ it("default namespace set when initialized with empty array", async () => {
16
+ await itwinLocalization.initialize([]);
17
+ assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
18
+ });
19
+ it("default namespace not overridden by one namespace", async () => {
20
+ await itwinLocalization.initialize(["Test"]);
21
+ assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
22
+ });
23
+ it("default namespace not overridden by two namespaces", async () => {
24
+ await itwinLocalization.initialize(["NotExist", "Test"]);
25
+ assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
26
+ });
27
+ it("duplicate namespace value does not break default namespace", async () => {
28
+ await itwinLocalization.initialize(["Default"]);
29
+ assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
30
+ });
31
+ it("default namespace is in list of all namespaces initalized with empty array", async () => {
32
+ var _a;
33
+ await itwinLocalization.initialize([]);
34
+ assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
35
+ });
36
+ it("default namespace is in list of all namespaces", async () => {
37
+ var _a;
38
+ await itwinLocalization.initialize(["Test"]);
39
+ assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
40
+ });
41
+ });
42
+ });
43
+ // The goal is not to test i18next's interpolation,
44
+ // but just to have some simple tests to make sure the
45
+ // basics work through the ITwinLocalization class.
46
+ // For interpolation options, see: https://www.i18next.com/translation-function/interpolation
47
+ describe("#getLocalizedString", () => {
48
+ before(async () => {
49
+ localization = new ITwinLocalization();
50
+ await localization.initialize(["Default", "Test"]);
51
+ });
52
+ describe("Default Namespace", () => {
53
+ it("first level with no substitution", () => {
54
+ assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
55
+ });
56
+ it("second level with no substitution", () => {
57
+ assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
58
+ assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
59
+ });
60
+ it("first level with substitution", () => {
61
+ assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
62
+ assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
63
+ assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
64
+ });
65
+ it("second level with substitution", () => {
66
+ assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
67
+ assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
68
+ });
69
+ it("first level missing key doesn't find a value", () => {
70
+ assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
71
+ });
72
+ it("second level missing key doesn't find a value", () => {
73
+ assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
74
+ assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
75
+ });
76
+ });
77
+ describe("Given Namespace", () => {
78
+ it("first level with no substitution", () => {
79
+ assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
80
+ assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
81
+ });
82
+ it("second level with no substitution", () => {
83
+ assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
84
+ assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
85
+ assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
86
+ assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
87
+ });
88
+ it("first level with substitution", () => {
89
+ assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
90
+ assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
91
+ assert.equal(localization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
92
+ assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
93
+ assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
94
+ assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
95
+ });
96
+ it("second level with substitution", () => {
97
+ assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
98
+ assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
99
+ assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
100
+ assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
101
+ });
102
+ it("first level missing key doesn't find a value", () => {
103
+ assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
104
+ assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
105
+ });
106
+ it("second level missing key doesn't find a value", () => {
107
+ assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
108
+ assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
109
+ });
110
+ });
111
+ describe("Nonexisting Namespace", () => {
112
+ it("first level fails", () => {
113
+ assert.equal(localization.getLocalizedString("Nonexisting:FirstTrivial"), "FirstTrivial");
114
+ assert.equal(localization.getLocalizedString("Nonexisting:MissingKeyString"), "MissingKeyString");
115
+ });
116
+ it("second level fails", () => {
117
+ assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
118
+ assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
119
+ });
120
+ });
121
+ });
122
+ });
123
123
  //# sourceMappingURL=ITwinLocalization.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ITwinLocalization.test.js","sourceRoot":"","sources":["../../../src/test/ITwinLocalization.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAEjC,IAAI,YAA0B,CAAC;IAE/B,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAE3B,QAAQ,CAAC,gDAAgD,EAAE,GAAG,EAAE;YAC9D,IAAI,iBAAoC,CAAC;YACzC,MAAM,CAAC,GAAG,EAAE;gBACV,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;YACvF,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,yDAAyD,EAAE,KAAK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A0B,CAAC,EAAE,kBAAkB,CAAC,CAAC;gBAC9F,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,EAAE,kBAAkB,CAAC,CAAC;YAC7F,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;gBACvD,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,kCAAkC,CAAC,EAAE,6BAA6B,CAAC,CAAC;gBACjH,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,qCAAqC,CAAC,EAAE,gCAAgC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;YAErC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;gBAC3B,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,0BAA0B,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC1F,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,EAAE,kBAAkB,CAAC,CAAC;YACpG,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;gBAC5B,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,iCAAiC,CAAC,EAAE,qBAAqB,CAAC,CAAC;gBACxG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,EAAE,gBAAgB,CAAC,CAAC;YAChG,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AAEL,CAAC,CAAC,CAAC","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\nimport { assert } from \"chai\";\nimport { Localization } from \"@itwin/core-common\";\nimport { ITwinLocalization } from \"../ITwinLocalization\";\n\ndescribe(\"ITwinLocalization\", () => {\n\n let localization: Localization;\n\n describe(\"#initialize\", () => {\n\n describe(\"with default namespace provided in constructor\", () => {\n let itwinLocalization: ITwinLocalization;\n before(() => {\n itwinLocalization = new ITwinLocalization({ initOptions: { defaultNS: \"Default\" } });\n });\n\n it(\"default namespace set when initialized with empty array\", async () => {\n await itwinLocalization.initialize([]);\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\n });\n\n it(\"default namespace not overridden by one namespace\", async () => {\n await itwinLocalization.initialize([\"Test\"]);\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\n });\n\n it(\"default namespace not overridden by two namespaces\", async () => {\n await itwinLocalization.initialize([\"NotExist\", \"Test\"]);\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\n });\n\n it(\"duplicate namespace value does not break default namespace\", async () => {\n await itwinLocalization.initialize([\"Default\"]);\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\n });\n\n it(\"default namespace is in list of all namespaces initalized with empty array\", async () => {\n await itwinLocalization.initialize([]);\n assert.isTrue(itwinLocalization.i18next.options.ns?.includes(\"Default\"));\n });\n\n it(\"default namespace is in list of all namespaces\", async () => {\n await itwinLocalization.initialize([\"Test\"]);\n assert.isTrue(itwinLocalization.i18next.options.ns?.includes(\"Default\"));\n });\n });\n });\n\n // The goal is not to test i18next's interpolation,\n // but just to have some simple tests to make sure the\n // basics work through the ITwinLocalization class.\n // For interpolation options, see: https://www.i18next.com/translation-function/interpolation\n describe(\"#getLocalizedString\", () => {\n\n before(async () => {\n localization = new ITwinLocalization();\n await localization.initialize([\"Default\", \"Test\"]);\n });\n\n describe(\"Default Namespace\", () => {\n\n it(\"first level with no substitution\", () => {\n assert.equal(localization.getLocalizedString(\"FirstTrivial\"), \"First level string (default)\");\n });\n\n it(\"second level with no substitution\", () => {\n assert.equal(localization.getLocalizedString(\"SecondTrivial.Test1\"), \"Second level string 1 (default)\");\n assert.equal(localization.getLocalizedString(\"SecondTrivial.Test2\"), \"Second level string 2 (default)\");\n });\n\n it(\"first level with substitution\", () => {\n assert.equal(localization.getLocalizedString(\"FirstSubstitution1\", { str: \"CUSTOM1\" }), \"First level CUSTOM1 (default)\");\n assert.equal(localization.getLocalizedString(\"FirstSubstitution1\", { str: \"CUSTOM2\" }), \"First level CUSTOM2 (default)\");\n assert.equal(localization.getLocalizedString(\"FirstSubstitution2\", { str1: \"CUSTOM1\", str2: \"CUSTOM2\" }), \"First level CUSTOM1 and CUSTOM2 (default)\");\n });\n\n it(\"second level with substitution\", () => {\n assert.equal(localization.getLocalizedString(\"SecondSubstitution.Test1\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Substitute Variable1 and Variable2 (default)\");\n assert.equal(localization.getLocalizedString(\"SecondSubstitution.Test2\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Reverse substitute Variable2 and Variable1 (default)\");\n });\n\n it(\"first level missing key doesn't find a value\", () => {\n assert.equal(localization.getLocalizedString(\"MissingKeyString\"), \"MissingKeyString\");\n });\n\n it(\"second level missing key doesn't find a value\", () => {\n assert.equal(localization.getLocalizedString(\"SecondTrivial.MissingString\"), \"SecondTrivial.MissingString\");\n assert.equal(localization.getLocalizedString(\"MissingKeyObject.MissingString\"), \"MissingKeyObject.MissingString\");\n });\n });\n\n describe(\"Given Namespace\", () => {\n\n it(\"first level with no substitution\", () => {\n assert.equal(localization.getLocalizedString(\"Default:FirstTrivial\"), \"First level string (default)\");\n assert.equal(localization.getLocalizedString(\"Test:FirstTrivial\"), \"First level string (test)\");\n });\n\n it(\"second level with no substitution\", () => {\n assert.equal(localization.getLocalizedString(\"Default:SecondTrivial.Test1\"), \"Second level string 1 (default)\");\n assert.equal(localization.getLocalizedString(\"Default:SecondTrivial.Test2\"), \"Second level string 2 (default)\");\n assert.equal(localization.getLocalizedString(\"Test:SecondTrivial.Test1\"), \"Second level string 1 (test)\");\n assert.equal(localization.getLocalizedString(\"Test:SecondTrivial.Test2\"), \"Second level string 2 (test)\");\n });\n\n it(\"first level with substitution\", () => {\n assert.equal(localization.getLocalizedString(\"Default:FirstSubstitution1\", { str: \"CUSTOM1\" }), \"First level CUSTOM1 (default)\");\n assert.equal(localization.getLocalizedString(\"Default:FirstSubstitution1\", { str: \"CUSTOM2\" }), \"First level CUSTOM2 (default)\");\n assert.equal(localization.getLocalizedString(\"Default:FirstSubstitution2\", { str1: \"CUSTOM1\", str2: \"CUSTOM2\" }), \"First level CUSTOM1 and CUSTOM2 (default)\");\n assert.equal(localization.getLocalizedString(\"Test:FirstSubstitution1\", { str: \"CUSTOM1\" }), \"First level CUSTOM1 (test)\");\n assert.equal(localization.getLocalizedString(\"Test:FirstSubstitution1\", { str: \"CUSTOM2\" }), \"First level CUSTOM2 (test)\");\n assert.equal(localization.getLocalizedString(\"Test:FirstSubstitution2\", { str1: \"CUSTOM1\", str2: \"CUSTOM2\" }), \"First level CUSTOM1 and CUSTOM2 (test)\");\n });\n\n it(\"second level with substitution\", () => {\n assert.equal(localization.getLocalizedString(\"Default:SecondSubstitution.Test1\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Substitute Variable1 and Variable2 (default)\");\n assert.equal(localization.getLocalizedString(\"Default:SecondSubstitution.Test2\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Reverse substitute Variable2 and Variable1 (default)\");\n assert.equal(localization.getLocalizedString(\"Test:SecondSubstitution.Test1\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Substitute Variable1 and Variable2 (test)\");\n assert.equal(localization.getLocalizedString(\"Test:SecondSubstitution.Test2\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Reverse substitute Variable2 and Variable1 (test)\");\n });\n\n it(\"first level missing key doesn't find a value\", () => {\n assert.equal(localization.getLocalizedString(\"Default:MissingKeyString\"), \"MissingKeyString\");\n assert.equal(localization.getLocalizedString(\"Test:MissingKeyString\"), \"MissingKeyString\");\n });\n\n it(\"second level missing key doesn't find a value\", () => {\n assert.equal(localization.getLocalizedString(\"Test:SecondTrivial.MissingString\"), \"SecondTrivial.MissingString\");\n assert.equal(localization.getLocalizedString(\"Test:MissingKeyObject.MissingString\"), \"MissingKeyObject.MissingString\");\n });\n });\n\n describe(\"Nonexisting Namespace\", () => {\n\n it(\"first level fails\", () => {\n assert.equal(localization.getLocalizedString(\"Nonexisting:FirstTrivial\"), \"FirstTrivial\");\n assert.equal(localization.getLocalizedString(\"Nonexisting:MissingKeyString\"), \"MissingKeyString\");\n });\n\n it(\"second level fails\", () => {\n assert.equal(localization.getLocalizedString(\"Nonexisting:SecondTrivial.Test1\"), \"SecondTrivial.Test1\");\n assert.equal(localization.getLocalizedString(\"Nonexisting:Missing.String\"), \"Missing.String\");\n });\n });\n });\n\n});\n"]}
1
+ {"version":3,"file":"ITwinLocalization.test.js","sourceRoot":"","sources":["../../../src/test/ITwinLocalization.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAEjC,IAAI,YAA0B,CAAC;IAE/B,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAE3B,QAAQ,CAAC,gDAAgD,EAAE,GAAG,EAAE;YAC9D,IAAI,iBAAoC,CAAC;YACzC,MAAM,CAAC,GAAG,EAAE;gBACV,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;YACvF,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;gBACvE,MAAM,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBACvC,MAAM,CAAC,KAAK,CAAC,iBAAiB,C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AAE,kBAAkB,CAAC,CAAC;YAC7F,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;gBACvD,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,kCAAkC,CAAC,EAAE,6BAA6B,CAAC,CAAC;gBACjH,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,qCAAqC,CAAC,EAAE,gCAAgC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;YAErC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;gBAC3B,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,0BAA0B,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC1F,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,EAAE,kBAAkB,CAAC,CAAC;YACpG,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;gBAC5B,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,iCAAiC,CAAC,EAAE,qBAAqB,CAAC,CAAC;gBACxG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,EAAE,gBAAgB,CAAC,CAAC;YAChG,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AAEL,CAAC,CAAC,CAAC","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\r\nimport { assert } from \"chai\";\r\nimport { Localization } from \"@itwin/core-common\";\r\nimport { ITwinLocalization } from \"../ITwinLocalization\";\r\n\r\ndescribe(\"ITwinLocalization\", () => {\r\n\r\n let localization: Localization;\r\n\r\n describe(\"#initialize\", () => {\r\n\r\n describe(\"with default namespace provided in constructor\", () => {\r\n let itwinLocalization: ITwinLocalization;\r\n before(() => {\r\n itwinLocalization = new ITwinLocalization({ initOptions: { defaultNS: \"Default\" } });\r\n });\r\n\r\n it(\"default namespace set when initialized with empty array\", async () => {\r\n await itwinLocalization.initialize([]);\r\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\r\n });\r\n\r\n it(\"default namespace not overridden by one namespace\", async () => {\r\n await itwinLocalization.initialize([\"Test\"]);\r\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\r\n });\r\n\r\n it(\"default namespace not overridden by two namespaces\", async () => {\r\n await itwinLocalization.initialize([\"NotExist\", \"Test\"]);\r\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\r\n });\r\n\r\n it(\"duplicate namespace value does not break default namespace\", async () => {\r\n await itwinLocalization.initialize([\"Default\"]);\r\n assert.equal(itwinLocalization.i18next.options.defaultNS, \"Default\");\r\n });\r\n\r\n it(\"default namespace is in list of all namespaces initalized with empty array\", async () => {\r\n await itwinLocalization.initialize([]);\r\n assert.isTrue(itwinLocalization.i18next.options.ns?.includes(\"Default\"));\r\n });\r\n\r\n it(\"default namespace is in list of all namespaces\", async () => {\r\n await itwinLocalization.initialize([\"Test\"]);\r\n assert.isTrue(itwinLocalization.i18next.options.ns?.includes(\"Default\"));\r\n });\r\n });\r\n });\r\n\r\n // The goal is not to test i18next's interpolation,\r\n // but just to have some simple tests to make sure the\r\n // basics work through the ITwinLocalization class.\r\n // For interpolation options, see: https://www.i18next.com/translation-function/interpolation\r\n describe(\"#getLocalizedString\", () => {\r\n\r\n before(async () => {\r\n localization = new ITwinLocalization();\r\n await localization.initialize([\"Default\", \"Test\"]);\r\n });\r\n\r\n describe(\"Default Namespace\", () => {\r\n\r\n it(\"first level with no substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"FirstTrivial\"), \"First level string (default)\");\r\n });\r\n\r\n it(\"second level with no substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"SecondTrivial.Test1\"), \"Second level string 1 (default)\");\r\n assert.equal(localization.getLocalizedString(\"SecondTrivial.Test2\"), \"Second level string 2 (default)\");\r\n });\r\n\r\n it(\"first level with substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"FirstSubstitution1\", { str: \"CUSTOM1\" }), \"First level CUSTOM1 (default)\");\r\n assert.equal(localization.getLocalizedString(\"FirstSubstitution1\", { str: \"CUSTOM2\" }), \"First level CUSTOM2 (default)\");\r\n assert.equal(localization.getLocalizedString(\"FirstSubstitution2\", { str1: \"CUSTOM1\", str2: \"CUSTOM2\" }), \"First level CUSTOM1 and CUSTOM2 (default)\");\r\n });\r\n\r\n it(\"second level with substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"SecondSubstitution.Test1\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Substitute Variable1 and Variable2 (default)\");\r\n assert.equal(localization.getLocalizedString(\"SecondSubstitution.Test2\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Reverse substitute Variable2 and Variable1 (default)\");\r\n });\r\n\r\n it(\"first level missing key doesn't find a value\", () => {\r\n assert.equal(localization.getLocalizedString(\"MissingKeyString\"), \"MissingKeyString\");\r\n });\r\n\r\n it(\"second level missing key doesn't find a value\", () => {\r\n assert.equal(localization.getLocalizedString(\"SecondTrivial.MissingString\"), \"SecondTrivial.MissingString\");\r\n assert.equal(localization.getLocalizedString(\"MissingKeyObject.MissingString\"), \"MissingKeyObject.MissingString\");\r\n });\r\n });\r\n\r\n describe(\"Given Namespace\", () => {\r\n\r\n it(\"first level with no substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"Default:FirstTrivial\"), \"First level string (default)\");\r\n assert.equal(localization.getLocalizedString(\"Test:FirstTrivial\"), \"First level string (test)\");\r\n });\r\n\r\n it(\"second level with no substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"Default:SecondTrivial.Test1\"), \"Second level string 1 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Default:SecondTrivial.Test2\"), \"Second level string 2 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Test:SecondTrivial.Test1\"), \"Second level string 1 (test)\");\r\n assert.equal(localization.getLocalizedString(\"Test:SecondTrivial.Test2\"), \"Second level string 2 (test)\");\r\n });\r\n\r\n it(\"first level with substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"Default:FirstSubstitution1\", { str: \"CUSTOM1\" }), \"First level CUSTOM1 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Default:FirstSubstitution1\", { str: \"CUSTOM2\" }), \"First level CUSTOM2 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Default:FirstSubstitution2\", { str1: \"CUSTOM1\", str2: \"CUSTOM2\" }), \"First level CUSTOM1 and CUSTOM2 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Test:FirstSubstitution1\", { str: \"CUSTOM1\" }), \"First level CUSTOM1 (test)\");\r\n assert.equal(localization.getLocalizedString(\"Test:FirstSubstitution1\", { str: \"CUSTOM2\" }), \"First level CUSTOM2 (test)\");\r\n assert.equal(localization.getLocalizedString(\"Test:FirstSubstitution2\", { str1: \"CUSTOM1\", str2: \"CUSTOM2\" }), \"First level CUSTOM1 and CUSTOM2 (test)\");\r\n });\r\n\r\n it(\"second level with substitution\", () => {\r\n assert.equal(localization.getLocalizedString(\"Default:SecondSubstitution.Test1\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Substitute Variable1 and Variable2 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Default:SecondSubstitution.Test2\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Reverse substitute Variable2 and Variable1 (default)\");\r\n assert.equal(localization.getLocalizedString(\"Test:SecondSubstitution.Test1\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Substitute Variable1 and Variable2 (test)\");\r\n assert.equal(localization.getLocalizedString(\"Test:SecondSubstitution.Test2\", { varA: \"Variable1\", varB: \"Variable2\" }), \"Reverse substitute Variable2 and Variable1 (test)\");\r\n });\r\n\r\n it(\"first level missing key doesn't find a value\", () => {\r\n assert.equal(localization.getLocalizedString(\"Default:MissingKeyString\"), \"MissingKeyString\");\r\n assert.equal(localization.getLocalizedString(\"Test:MissingKeyString\"), \"MissingKeyString\");\r\n });\r\n\r\n it(\"second level missing key doesn't find a value\", () => {\r\n assert.equal(localization.getLocalizedString(\"Test:SecondTrivial.MissingString\"), \"SecondTrivial.MissingString\");\r\n assert.equal(localization.getLocalizedString(\"Test:MissingKeyObject.MissingString\"), \"MissingKeyObject.MissingString\");\r\n });\r\n });\r\n\r\n describe(\"Nonexisting Namespace\", () => {\r\n\r\n it(\"first level fails\", () => {\r\n assert.equal(localization.getLocalizedString(\"Nonexisting:FirstTrivial\"), \"FirstTrivial\");\r\n assert.equal(localization.getLocalizedString(\"Nonexisting:MissingKeyString\"), \"MissingKeyString\");\r\n });\r\n\r\n it(\"second level fails\", () => {\r\n assert.equal(localization.getLocalizedString(\"Nonexisting:SecondTrivial.Test1\"), \"SecondTrivial.Test1\");\r\n assert.equal(localization.getLocalizedString(\"Nonexisting:Missing.String\"), \"Missing.String\");\r\n });\r\n });\r\n });\r\n\r\n});\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-i18n",
3
- "version": "3.5.0-dev.5",
3
+ "version": "3.5.0-dev.7",
4
4
  "description": "iTwin.js localization code",
5
5
  "main": "lib/cjs/core-i18n.js",
6
6
  "module": "lib/esm/core-i18n.js",
@@ -20,18 +20,18 @@
20
20
  "url": "http://www.bentley.com"
21
21
  },
22
22
  "peerDependencies": {
23
- "@itwin/core-bentley": "^3.5.0-dev.5"
23
+ "@itwin/core-bentley": "^3.5.0-dev.7"
24
24
  },
25
25
  "//devDependencies": [
26
26
  "NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
27
27
  "NOTE: All tools used by scripts in this package must be listed as devDependencies"
28
28
  ],
29
29
  "devDependencies": {
30
- "@itwin/build-tools": "3.5.0-dev.5",
31
- "@itwin/certa": "3.5.0-dev.5",
32
- "@itwin/core-bentley": "3.5.0-dev.5",
33
- "@itwin/core-common": "3.5.0-dev.5",
34
- "@itwin/eslint-plugin": "3.5.0-dev.5",
30
+ "@itwin/build-tools": "3.5.0-dev.7",
31
+ "@itwin/certa": "3.5.0-dev.7",
32
+ "@itwin/core-bentley": "3.5.0-dev.7",
33
+ "@itwin/core-common": "3.5.0-dev.7",
34
+ "@itwin/eslint-plugin": "3.5.0-dev.7",
35
35
  "@types/chai": "4.3.1",
36
36
  "@types/i18next": "^8.4.2",
37
37
  "@types/i18next-browser-languagedetector": "^2.0.1",