@itwin/core-i18n 3.5.0-dev.43 → 3.5.0-dev.47

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.
@@ -10785,8 +10785,8 @@ module.exports = getFuncName;
10785
10785
  "use strict";
10786
10786
 
10787
10787
 
10788
- var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/classCallCheck.js");
10789
- var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/createClass.js");
10788
+ var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/classCallCheck.js");
10789
+ var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/createClass.js");
10790
10790
 
10791
10791
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10792
10792
 
@@ -11218,15 +11218,15 @@ module.exports = Browser;
11218
11218
  "use strict";
11219
11219
 
11220
11220
 
11221
- var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/typeof.js");
11222
- var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/classCallCheck.js");
11223
- var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/createClass.js");
11224
- var _assertThisInitialized = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
11225
- var _inherits = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/inherits.js");
11226
- var _possibleConstructorReturn = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js");
11227
- var _getPrototypeOf = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js");
11228
- var _defineProperty = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/defineProperty.js");
11229
- var _toArray = __webpack_require__(/*! @babel/runtime/helpers/toArray */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/toArray.js");
11221
+ var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/typeof.js");
11222
+ var _classCallCheck = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/classCallCheck.js");
11223
+ var _createClass = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/createClass.js");
11224
+ var _assertThisInitialized = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
11225
+ var _inherits = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/inherits.js");
11226
+ var _possibleConstructorReturn = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js");
11227
+ var _getPrototypeOf = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/getPrototypeOf.js");
11228
+ var _defineProperty = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/defineProperty.js");
11229
+ var _toArray = __webpack_require__(/*! @babel/runtime/helpers/toArray */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/toArray.js");
11230
11230
 
11231
11231
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11232
11232
 
@@ -22308,7 +22308,8 @@ class ITwinLocalization {
22308
22308
  }
22309
22309
  return value;
22310
22310
  }
22311
- /** Similar to `getLocalizedString` but the namespace is a separate param and the key does not include the namespace.
22311
+ /** Similar to `getLocalizedString` but the default namespace is a separate parameter and the key does not need
22312
+ * to include a namespace. If a key includes a namespace, that namespace will be used for interpolating that key.
22312
22313
  * @param namespace - the namespace that identifies the particular localization file that contains the property.
22313
22314
  * @param key - the key that matches a property in the JSON localization file.
22314
22315
  * @returns The string corresponding to the first key that resolves.
@@ -22338,6 +22339,10 @@ class ITwinLocalization {
22338
22339
  if ((options === null || options === void 0 ? void 0 : options.returnDetails) || (options === null || options === void 0 ? void 0 : options.returnObjects)) {
22339
22340
  throw new Error("Translation key must map to a string, but the given options will result in an object");
22340
22341
  }
22342
+ options = {
22343
+ ...options,
22344
+ ns: namespace, // ensure namespace argument is used
22345
+ };
22341
22346
  const en = this.i18next.getFixedT("en", namespace);
22342
22347
  const str = en(key, options);
22343
22348
  if (typeof str !== "string")
@@ -22434,9 +22439,9 @@ TranslationLogger.type = "logger";
22434
22439
 
22435
22440
  /***/ }),
22436
22441
 
22437
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js":
22442
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/arrayLikeToArray.js":
22438
22443
  /*!**************************************************************************************************************************!*\
22439
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***!
22444
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***!
22440
22445
  \**************************************************************************************************************************/
22441
22446
  /***/ ((module) => {
22442
22447
 
@@ -22451,9 +22456,9 @@ module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exp
22451
22456
 
22452
22457
  /***/ }),
22453
22458
 
22454
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js":
22459
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/arrayWithHoles.js":
22455
22460
  /*!************************************************************************************************************************!*\
22456
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js ***!
22461
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/arrayWithHoles.js ***!
22457
22462
  \************************************************************************************************************************/
22458
22463
  /***/ ((module) => {
22459
22464
 
@@ -22464,9 +22469,9 @@ module.exports = _arrayWithHoles, module.exports.__esModule = true, module.expor
22464
22469
 
22465
22470
  /***/ }),
22466
22471
 
22467
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js":
22472
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/assertThisInitialized.js":
22468
22473
  /*!*******************************************************************************************************************************!*\
22469
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js ***!
22474
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/assertThisInitialized.js ***!
22470
22475
  \*******************************************************************************************************************************/
22471
22476
  /***/ ((module) => {
22472
22477
 
@@ -22480,9 +22485,9 @@ module.exports = _assertThisInitialized, module.exports.__esModule = true, modul
22480
22485
 
22481
22486
  /***/ }),
22482
22487
 
22483
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/classCallCheck.js":
22488
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/classCallCheck.js":
22484
22489
  /*!************************************************************************************************************************!*\
22485
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/classCallCheck.js ***!
22490
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/classCallCheck.js ***!
22486
22491
  \************************************************************************************************************************/
22487
22492
  /***/ ((module) => {
22488
22493
 
@@ -22495,9 +22500,9 @@ module.exports = _classCallCheck, module.exports.__esModule = true, module.expor
22495
22500
 
22496
22501
  /***/ }),
22497
22502
 
22498
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/createClass.js":
22503
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/createClass.js":
22499
22504
  /*!*********************************************************************************************************************!*\
22500
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/createClass.js ***!
22505
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/createClass.js ***!
22501
22506
  \*********************************************************************************************************************/
22502
22507
  /***/ ((module) => {
22503
22508
 
@@ -22522,9 +22527,9 @@ module.exports = _createClass, module.exports.__esModule = true, module.exports[
22522
22527
 
22523
22528
  /***/ }),
22524
22529
 
22525
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/defineProperty.js":
22530
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/defineProperty.js":
22526
22531
  /*!************************************************************************************************************************!*\
22527
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/defineProperty.js ***!
22532
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/defineProperty.js ***!
22528
22533
  \************************************************************************************************************************/
22529
22534
  /***/ ((module) => {
22530
22535
 
@@ -22545,9 +22550,9 @@ module.exports = _defineProperty, module.exports.__esModule = true, module.expor
22545
22550
 
22546
22551
  /***/ }),
22547
22552
 
22548
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js":
22553
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/getPrototypeOf.js":
22549
22554
  /*!************************************************************************************************************************!*\
22550
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/getPrototypeOf.js ***!
22555
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/getPrototypeOf.js ***!
22551
22556
  \************************************************************************************************************************/
22552
22557
  /***/ ((module) => {
22553
22558
 
@@ -22561,13 +22566,13 @@ module.exports = _getPrototypeOf, module.exports.__esModule = true, module.expor
22561
22566
 
22562
22567
  /***/ }),
22563
22568
 
22564
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/inherits.js":
22569
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/inherits.js":
22565
22570
  /*!******************************************************************************************************************!*\
22566
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/inherits.js ***!
22571
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/inherits.js ***!
22567
22572
  \******************************************************************************************************************/
22568
22573
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
22569
22574
 
22570
- var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js");
22575
+ var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/setPrototypeOf.js");
22571
22576
  function _inherits(subClass, superClass) {
22572
22577
  if (typeof superClass !== "function" && superClass !== null) {
22573
22578
  throw new TypeError("Super expression must either be null or a function");
@@ -22588,9 +22593,9 @@ module.exports = _inherits, module.exports.__esModule = true, module.exports["de
22588
22593
 
22589
22594
  /***/ }),
22590
22595
 
22591
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/iterableToArray.js":
22596
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/iterableToArray.js":
22592
22597
  /*!*************************************************************************************************************************!*\
22593
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/iterableToArray.js ***!
22598
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/iterableToArray.js ***!
22594
22599
  \*************************************************************************************************************************/
22595
22600
  /***/ ((module) => {
22596
22601
 
@@ -22601,9 +22606,9 @@ module.exports = _iterableToArray, module.exports.__esModule = true, module.expo
22601
22606
 
22602
22607
  /***/ }),
22603
22608
 
22604
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/nonIterableRest.js":
22609
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/nonIterableRest.js":
22605
22610
  /*!*************************************************************************************************************************!*\
22606
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/nonIterableRest.js ***!
22611
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/nonIterableRest.js ***!
22607
22612
  \*************************************************************************************************************************/
22608
22613
  /***/ ((module) => {
22609
22614
 
@@ -22614,14 +22619,14 @@ module.exports = _nonIterableRest, module.exports.__esModule = true, module.expo
22614
22619
 
22615
22620
  /***/ }),
22616
22621
 
22617
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js":
22622
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js":
22618
22623
  /*!***********************************************************************************************************************************!*\
22619
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***!
22624
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***!
22620
22625
  \***********************************************************************************************************************************/
22621
22626
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
22622
22627
 
22623
- var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
22624
- var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
22628
+ var _typeof = (__webpack_require__(/*! ./typeof.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/typeof.js")["default"]);
22629
+ var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/assertThisInitialized.js");
22625
22630
  function _possibleConstructorReturn(self, call) {
22626
22631
  if (call && (_typeof(call) === "object" || typeof call === "function")) {
22627
22632
  return call;
@@ -22634,9 +22639,9 @@ module.exports = _possibleConstructorReturn, module.exports.__esModule = true, m
22634
22639
 
22635
22640
  /***/ }),
22636
22641
 
22637
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js":
22642
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/setPrototypeOf.js":
22638
22643
  /*!************************************************************************************************************************!*\
22639
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/setPrototypeOf.js ***!
22644
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/setPrototypeOf.js ***!
22640
22645
  \************************************************************************************************************************/
22641
22646
  /***/ ((module) => {
22642
22647
 
@@ -22651,16 +22656,16 @@ module.exports = _setPrototypeOf, module.exports.__esModule = true, module.expor
22651
22656
 
22652
22657
  /***/ }),
22653
22658
 
22654
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/toArray.js":
22659
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/toArray.js":
22655
22660
  /*!*****************************************************************************************************************!*\
22656
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/toArray.js ***!
22661
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/toArray.js ***!
22657
22662
  \*****************************************************************************************************************/
22658
22663
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
22659
22664
 
22660
- var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/arrayWithHoles.js");
22661
- var iterableToArray = __webpack_require__(/*! ./iterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/iterableToArray.js");
22662
- var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js");
22663
- var nonIterableRest = __webpack_require__(/*! ./nonIterableRest.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/nonIterableRest.js");
22665
+ var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/arrayWithHoles.js");
22666
+ var iterableToArray = __webpack_require__(/*! ./iterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/iterableToArray.js");
22667
+ var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js");
22668
+ var nonIterableRest = __webpack_require__(/*! ./nonIterableRest.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/nonIterableRest.js");
22664
22669
  function _toArray(arr) {
22665
22670
  return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest();
22666
22671
  }
@@ -22668,9 +22673,9 @@ module.exports = _toArray, module.exports.__esModule = true, module.exports["def
22668
22673
 
22669
22674
  /***/ }),
22670
22675
 
22671
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/typeof.js":
22676
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/typeof.js":
22672
22677
  /*!****************************************************************************************************************!*\
22673
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/typeof.js ***!
22678
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/typeof.js ***!
22674
22679
  \****************************************************************************************************************/
22675
22680
  /***/ ((module) => {
22676
22681
 
@@ -22687,13 +22692,13 @@ module.exports = _typeof, module.exports.__esModule = true, module.exports["defa
22687
22692
 
22688
22693
  /***/ }),
22689
22694
 
22690
- /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js":
22695
+ /***/ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js":
22691
22696
  /*!************************************************************************************************************************************!*\
22692
- !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***!
22697
+ !*** ../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***!
22693
22698
  \************************************************************************************************************************************/
22694
22699
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
22695
22700
 
22696
- var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.20.0/node_modules/@babel/runtime/helpers/arrayLikeToArray.js");
22701
+ var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray.js */ "../../common/temp/node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/arrayLikeToArray.js");
22697
22702
  function _unsupportedIterableToArray(o, minLen) {
22698
22703
  if (!o) return;
22699
22704
  if (typeof o === "string") return arrayLikeToArray(o, minLen);
@@ -23224,9 +23229,80 @@ const chai_1 = __webpack_require__(/*! chai */ "../../common/temp/node_modules/.
23224
23229
  const ITwinLocalization_1 = __webpack_require__(/*! ../ITwinLocalization */ "./lib/cjs/ITwinLocalization.js");
23225
23230
  describe("ITwinLocalization", () => {
23226
23231
  let localization;
23232
+ let germanLocalization;
23233
+ describe("#constructor", () => {
23234
+ let itwinLocalization;
23235
+ it("set default namespace", async () => {
23236
+ itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
23237
+ await itwinLocalization.initialize([]);
23238
+ chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
23239
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
23240
+ });
23241
+ it("set default language as english", async () => {
23242
+ itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "en" } });
23243
+ await itwinLocalization.initialize([]);
23244
+ chai_1.assert.equal(itwinLocalization.i18next.options.lng, "en");
23245
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
23246
+ });
23247
+ it("set default language as NOT english", async () => {
23248
+ itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", lng: "de" } });
23249
+ await itwinLocalization.initialize([]);
23250
+ chai_1.assert.equal(itwinLocalization.i18next.options.lng, "de");
23251
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
23252
+ });
23253
+ it("set fallback language as NOT english", async () => {
23254
+ itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default", fallbackLng: "de" } });
23255
+ await itwinLocalization.initialize([]);
23256
+ chai_1.assert.equal(itwinLocalization.i18next.options.fallbackLng, "de");
23257
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("OnlyGerman"), "Hallo");
23258
+ });
23259
+ });
23227
23260
  describe("#initialize", () => {
23228
- describe("with default namespace provided in constructor", () => {
23229
- let itwinLocalization;
23261
+ let itwinLocalization;
23262
+ it("cannot fetch from unregistered namespaces", async () => {
23263
+ localization = new ITwinLocalization_1.ITwinLocalization();
23264
+ await localization.initialize([]);
23265
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "FirstTrivial");
23266
+ chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "FirstTrivial");
23267
+ });
23268
+ describe("with no default namespace predefined", () => {
23269
+ before(() => {
23270
+ itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
23271
+ });
23272
+ it("no default namespace set when initialized with empty array", async () => {
23273
+ await itwinLocalization.initialize([]);
23274
+ chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, undefined);
23275
+ });
23276
+ it("initialize with single namespace", async () => {
23277
+ var _a;
23278
+ await itwinLocalization.initialize(["Test"]);
23279
+ chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Test");
23280
+ chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Test"));
23281
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
23282
+ });
23283
+ it("initialize with two namespaces recognizes both namespaces", async () => {
23284
+ var _a, _b;
23285
+ await itwinLocalization.initialize(["Default", "Test"]);
23286
+ chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
23287
+ chai_1.assert.isTrue((_b = itwinLocalization.i18next.options.ns) === null || _b === void 0 ? void 0 : _b.includes("Test"));
23288
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
23289
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
23290
+ });
23291
+ it("initialize with two namespaces sets first as default", async () => {
23292
+ await itwinLocalization.initialize(["Default", "Test"]);
23293
+ chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
23294
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
23295
+ });
23296
+ it("initialize with duplicate namespace values does not break anything", async () => {
23297
+ var _a;
23298
+ await itwinLocalization.initialize(["Default", "Default"]);
23299
+ chai_1.assert.equal(itwinLocalization.i18next.options.defaultNS, "Default");
23300
+ chai_1.assert.isTrue((_a = itwinLocalization.i18next.options.ns) === null || _a === void 0 ? void 0 : _a.includes("Default"));
23301
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("FirstTrivial"), "First level string (default)");
23302
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
23303
+ });
23304
+ });
23305
+ describe("with default namespace", () => {
23230
23306
  before(() => {
23231
23307
  itwinLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { defaultNS: "Default" } });
23232
23308
  });
@@ -23258,6 +23334,93 @@ describe("ITwinLocalization", () => {
23258
23334
  });
23259
23335
  });
23260
23336
  });
23337
+ describe("#getLocalizedKeys", () => {
23338
+ before(async () => {
23339
+ localization = new ITwinLocalization_1.ITwinLocalization();
23340
+ await localization.initialize(["Default", "Test"]);
23341
+ germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
23342
+ await germanLocalization.initialize(["Default", "Test"]);
23343
+ });
23344
+ it("no substitution", () => {
23345
+ chai_1.assert.equal(localization.getLocalizedKeys("MyString"), "MyString");
23346
+ });
23347
+ describe("Default Namespace", () => {
23348
+ it("first level string", () => {
23349
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default)");
23350
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{FirstTrivial}"), "hi First level string (default german)");
23351
+ });
23352
+ it("second level string", () => {
23353
+ chai_1.assert.equal(localization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default)");
23354
+ chai_1.assert.equal(localization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default)");
23355
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondTrivial.Test1}"), "Second level string 1 (default german)");
23356
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{SecondTrivial.Test2}"), "bye Second level string 2 (default german)");
23357
+ });
23358
+ it("first level string with keys", () => {
23359
+ chai_1.assert.equal(localization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default)");
23360
+ chai_1.assert.equal(localization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
23361
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{FirstSubstitution1}"), "First level {{str}} (default german)");
23362
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("bye %{FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default german)");
23363
+ });
23364
+ it("second level string with keys", () => {
23365
+ chai_1.assert.equal(localization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
23366
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
23367
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("%{SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default german)");
23368
+ chai_1.assert.equal(germanLocalization.getLocalizedKeys("hi %{SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default german)");
23369
+ });
23370
+ it("first level missing key doesn't find a value", () => {
23371
+ chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
23372
+ chai_1.assert.equal(localization.getLocalizedKeys("no %{MissingKeyString}"), "no MissingKeyString");
23373
+ });
23374
+ it("second level missing key doesn't find a value", () => {
23375
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
23376
+ chai_1.assert.equal(localization.getLocalizedKeys("%{MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
23377
+ });
23378
+ });
23379
+ describe("Given Namespace", () => {
23380
+ it("first level string", () => {
23381
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:FirstTrivial}"), "hi First level string (default)");
23382
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:FirstTrivial}"), "hi First level string (test)");
23383
+ });
23384
+ it("second level string", () => {
23385
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondTrivial.Test1}"), "Second level string 1 (default)");
23386
+ chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:SecondTrivial.Test2}"), "bye Second level string 2 (default)");
23387
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondTrivial.Test1}"), "Second level string 1 (test)");
23388
+ chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:SecondTrivial.Test2}"), "bye Second level string 2 (test)");
23389
+ });
23390
+ it("first level string with keys", () => {
23391
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Default:FirstSubstitution1}"), "First level {{str}} (default)");
23392
+ chai_1.assert.equal(localization.getLocalizedKeys("bye %{Default:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (default)");
23393
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Test:FirstSubstitution1}"), "First level {{str}} (test)");
23394
+ chai_1.assert.equal(localization.getLocalizedKeys("bye %{Test:FirstSubstitution2}"), "bye First level {{str1}} and {{str2}} (test)");
23395
+ });
23396
+ it("second level string with keys", () => {
23397
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Default:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (default)");
23398
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (default)");
23399
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Test:SecondSubstitution.Test1}"), "Substitute {{varA}} and {{varB}} (test)");
23400
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondSubstitution.Test2}"), "hi Reverse substitute {{varB}} and {{varA}} (test)");
23401
+ });
23402
+ it("first level missing key doesn't find a value", () => {
23403
+ chai_1.assert.equal(localization.getLocalizedKeys("no %{Default:MissingKeyString}"), "no MissingKeyString");
23404
+ chai_1.assert.equal(localization.getLocalizedKeys("no %{Test:MissingKeyString}"), "no MissingKeyString");
23405
+ });
23406
+ it("second level missing key doesn't find a value", () => {
23407
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{Default:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
23408
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Default:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
23409
+ chai_1.assert.equal(localization.getLocalizedKeys("hi %{Test:SecondTrivial.MissingString}"), "hi SecondTrivial.MissingString");
23410
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Test:MissingKeyObject.MissingString}"), "MissingKeyObject.MissingString");
23411
+ });
23412
+ });
23413
+ describe("Nonexisting Namespace", () => {
23414
+ it("first level fails", () => {
23415
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:FirstTrivial}"), "FirstTrivial");
23416
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:MissingKeyString}"), "MissingKeyString");
23417
+ });
23418
+ it("second level fails", () => {
23419
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:SecondTrivial.Test1}"), "SecondTrivial.Test1");
23420
+ chai_1.assert.equal(localization.getLocalizedKeys("%{Nonexisting:Missing.String}"), "Missing.String");
23421
+ });
23422
+ });
23423
+ });
23261
23424
  // The goal is not to test i18next's interpolation,
23262
23425
  // but just to have some simple tests to make sure the
23263
23426
  // basics work through the ITwinLocalization class.
@@ -23266,30 +23429,106 @@ describe("ITwinLocalization", () => {
23266
23429
  before(async () => {
23267
23430
  localization = new ITwinLocalization_1.ITwinLocalization();
23268
23431
  await localization.initialize(["Default", "Test"]);
23432
+ germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
23433
+ await germanLocalization.initialize(["Default", "Test"]);
23269
23434
  });
23270
23435
  describe("Default Namespace", () => {
23271
23436
  it("first level with no substitution", () => {
23272
23437
  chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)");
23273
23438
  });
23439
+ it("first level with no substitution with fallback keys", () => {
23440
+ chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default)");
23441
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default)");
23442
+ });
23443
+ it("more than two fallback keys succeeds", () => {
23444
+ chai_1.assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist1", "NotExist2"]), "First level string (default)");
23445
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "FirstTrivial", "NotExist2"]), "First level string (default)");
23446
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist1", "NotExist2", "FirstTrivial"]), "First level string (default)");
23447
+ chai_1.assert.equal(localization.getLocalizedString(["1", "2", "3", "4", "5", "FirstTrivial"]), "First level string (default)");
23448
+ });
23274
23449
  it("second level with no substitution", () => {
23275
23450
  chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default)");
23276
23451
  chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default)");
23277
23452
  });
23453
+ it("second level with no substitution with fallback keys", () => {
23454
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
23455
+ chai_1.assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default)");
23456
+ });
23278
23457
  it("first level with substitution", () => {
23279
23458
  chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23280
23459
  chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
23281
23460
  chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
23282
23461
  });
23462
+ it("first level with substitution with fallback keys", () => {
23463
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23464
+ chai_1.assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
23465
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
23466
+ });
23283
23467
  it("second level with substitution", () => {
23284
23468
  chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23285
23469
  chai_1.assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
23286
23470
  });
23471
+ it("second level with substitution with fallback keys", () => {
23472
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23473
+ chai_1.assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
23474
+ });
23287
23475
  it("first level missing key doesn't find a value", () => {
23288
23476
  chai_1.assert.equal(localization.getLocalizedString("MissingKeyString"), "MissingKeyString");
23289
23477
  });
23478
+ it("first level missing all keys doesn't find a value", () => {
23479
+ chai_1.assert.equal(localization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
23480
+ });
23290
23481
  it("second level missing key doesn't find a value", () => {
23291
23482
  chai_1.assert.equal(localization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23292
- chai_1.assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23483
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "MissingKeyObject.MissingString"]), "MissingKeyObject.MissingString");
23484
+ });
23485
+ it("read from en-US fallback", () => {
23486
+ chai_1.assert.equal(localization.getLocalizedString("OnlyEnglishUS"), "HelloUS");
23487
+ });
23488
+ });
23489
+ describe("Default Namespace (German)", () => {
23490
+ it("first level with no substitution", () => {
23491
+ chai_1.assert.equal(germanLocalization.getLocalizedString("FirstTrivial"), "First level string (default german)");
23492
+ });
23493
+ it("first level with no substitution with fallback keys", () => {
23494
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstTrivial", "NotExist"]), "First level string (default german)");
23495
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstTrivial"]), "First level string (default german)");
23496
+ });
23497
+ it("second level with no substitution", () => {
23498
+ chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1"), "Second level string 1 (default german)");
23499
+ chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2"), "Second level string 2 (default german)");
23500
+ });
23501
+ it("second level with no substitution with fallback keys", () => {
23502
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default german)");
23503
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (default german)");
23504
+ });
23505
+ it("first level with substitution", () => {
23506
+ chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
23507
+ chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
23508
+ chai_1.assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
23509
+ });
23510
+ it("first level with substitution with fallback keys", () => {
23511
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
23512
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
23513
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
23514
+ });
23515
+ it("second level with substitution", () => {
23516
+ chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
23517
+ chai_1.assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
23518
+ });
23519
+ it("second level with substitution with fallback keys", () => {
23520
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
23521
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
23522
+ });
23523
+ it("first level missing key doesn't find a value", () => {
23524
+ chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyString"), "MissingKeyString");
23525
+ });
23526
+ it("first level missing all keys doesn't find a value", () => {
23527
+ chai_1.assert.equal(germanLocalization.getLocalizedString(["MissingKeyString", "MissingString2"]), "MissingString2");
23528
+ });
23529
+ it("second level missing key doesn't find a value", () => {
23530
+ chai_1.assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23531
+ chai_1.assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23293
23532
  });
23294
23533
  });
23295
23534
  describe("Given Namespace", () => {
@@ -23297,12 +23536,20 @@ describe("ITwinLocalization", () => {
23297
23536
  chai_1.assert.equal(localization.getLocalizedString("Default:FirstTrivial"), "First level string (default)");
23298
23537
  chai_1.assert.equal(localization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
23299
23538
  });
23539
+ it("first level with no substitution with fallback keys", () => {
23540
+ chai_1.assert.equal(localization.getLocalizedString(["Default:FirstTrivial", "Not:NotExist"]), "First level string (default)");
23541
+ chai_1.assert.equal(localization.getLocalizedString(["Default:NotExist", "Test:FirstTrivial"]), "First level string (test)");
23542
+ });
23300
23543
  it("second level with no substitution", () => {
23301
23544
  chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default)");
23302
23545
  chai_1.assert.equal(localization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default)");
23303
23546
  chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (test)");
23304
23547
  chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (test)");
23305
23548
  });
23549
+ it("second level with no substitution with fallback keys", () => {
23550
+ chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondTrivial.Test1"]), "Second level string 1 (default)");
23551
+ chai_1.assert.equal(localization.getLocalizedString(["Test:SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
23552
+ });
23306
23553
  it("first level with substitution", () => {
23307
23554
  chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23308
23555
  chai_1.assert.equal(localization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
@@ -23311,12 +23558,21 @@ describe("ITwinLocalization", () => {
23311
23558
  chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23312
23559
  chai_1.assert.equal(localization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23313
23560
  });
23561
+ it("first level with substitution with fallback keys", () => {
23562
+ chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23563
+ chai_1.assert.equal(localization.getLocalizedString(["Test:FirstSubstitution1", "Default:NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23564
+ chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
23565
+ });
23314
23566
  it("second level with substitution", () => {
23315
23567
  chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23316
23568
  chai_1.assert.equal(localization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
23317
23569
  chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
23318
23570
  chai_1.assert.equal(localization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23319
23571
  });
23572
+ it("second level with substitution with fallback keys", () => {
23573
+ chai_1.assert.equal(localization.getLocalizedString(["Test:NotExist", "Default:SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23574
+ chai_1.assert.equal(localization.getLocalizedString(["Test:SecondSubstitution.Test2", "Default:NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23575
+ });
23320
23576
  it("first level missing key doesn't find a value", () => {
23321
23577
  chai_1.assert.equal(localization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
23322
23578
  chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
@@ -23325,6 +23581,43 @@ describe("ITwinLocalization", () => {
23325
23581
  chai_1.assert.equal(localization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23326
23582
  chai_1.assert.equal(localization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23327
23583
  });
23584
+ it("read from en-US fallback", () => {
23585
+ chai_1.assert.equal(localization.getLocalizedString("Default:OnlyEnglishUS"), "HelloUS");
23586
+ });
23587
+ });
23588
+ describe("Given Namespace (German)", () => {
23589
+ it("first level with no substitution", () => {
23590
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstTrivial"), "First level string (default german)");
23591
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (german)");
23592
+ });
23593
+ it("second level with no substitution", () => {
23594
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test1"), "Second level string 1 (default german)");
23595
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondTrivial.Test2"), "Second level string 2 (default german)");
23596
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test1"), "Second level string 1 (german)");
23597
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.Test2"), "Second level string 2 (german)");
23598
+ });
23599
+ it("first level with substitution", () => {
23600
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
23601
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
23602
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
23603
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (german)");
23604
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (german)");
23605
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
23606
+ });
23607
+ it("second level with substitution", () => {
23608
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
23609
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
23610
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
23611
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
23612
+ });
23613
+ it("first level missing key doesn't find a value", () => {
23614
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString"), "MissingKeyString");
23615
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyString"), "MissingKeyString");
23616
+ });
23617
+ it("second level missing key doesn't find a value", () => {
23618
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23619
+ chai_1.assert.equal(germanLocalization.getLocalizedString("Test:MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23620
+ });
23328
23621
  });
23329
23622
  describe("Nonexisting Namespace", () => {
23330
23623
  it("first level fails", () => {
@@ -23335,8 +23628,473 @@ describe("ITwinLocalization", () => {
23335
23628
  chai_1.assert.equal(localization.getLocalizedString("Nonexisting:SecondTrivial.Test1"), "SecondTrivial.Test1");
23336
23629
  chai_1.assert.equal(localization.getLocalizedString("Nonexisting:Missing.String"), "Missing.String");
23337
23630
  });
23631
+ it("fallback key fails", () => {
23632
+ chai_1.assert.equal(localization.getLocalizedString(["Nonexisting:FirstTrivial", "NotExist"]), "NotExist");
23633
+ chai_1.assert.equal(localization.getLocalizedString(["NotExist", "Nonexisting:Missing.String"]), "Missing.String");
23634
+ });
23635
+ });
23636
+ // Test a few options to make sure they get passed through correctly
23637
+ describe("With Options", () => {
23638
+ it("returnDetails throws error", () => {
23639
+ chai_1.assert.throws(() => {
23640
+ localization.getLocalizedString("X", { returnDetails: true });
23641
+ }, "Translation key must map to a string, but the given options will result in an object");
23642
+ });
23643
+ it("returnObjects throws error", () => {
23644
+ chai_1.assert.throws(() => {
23645
+ localization.getLocalizedString("X", { returnObjects: true });
23646
+ }, "Translation key must map to a string, but the given options will result in an object");
23647
+ });
23648
+ it("returnDetails and returnObjects throws error", () => {
23649
+ chai_1.assert.throws(() => {
23650
+ localization.getLocalizedString("X", { returnDetails: true, returnObjects: true });
23651
+ }, "Translation key must map to a string, but the given options will result in an object");
23652
+ });
23653
+ it("default value", () => {
23654
+ chai_1.assert.equal(localization.getLocalizedString("Missing", { defaultValue: "default" }), "default");
23655
+ });
23656
+ it("override fallback language", () => {
23657
+ // Doesn't fallback to English
23658
+ chai_1.assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { fallbackLng: "de" }), "OnlyEnglish");
23659
+ });
23660
+ it("set namespace", () => {
23661
+ chai_1.assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
23662
+ chai_1.assert.equal(localization.getLocalizedString("FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (test)");
23663
+ });
23664
+ });
23665
+ });
23666
+ describe("#getLocalizedStringWithNamespace", () => {
23667
+ before(async () => {
23668
+ localization = new ITwinLocalization_1.ITwinLocalization();
23669
+ await localization.initialize(["Default", "Test"]);
23670
+ germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
23671
+ await germanLocalization.initialize(["Default", "Test"]);
23672
+ });
23673
+ describe("Keys Without Namespaces", () => {
23674
+ it("first level with no substitution", () => {
23675
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstTrivial"), "First level string (default)");
23676
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "FirstTrivial"), "First level string (test)");
23677
+ });
23678
+ it("first level with no substitution with fallback keys", () => {
23679
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
23680
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
23681
+ });
23682
+ it("second level with no substitution", () => {
23683
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
23684
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
23685
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
23686
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
23687
+ });
23688
+ it("second level with no substitution with fallback keys", () => {
23689
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
23690
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
23691
+ });
23692
+ it("first level with substitution", () => {
23693
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23694
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
23695
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
23696
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
23697
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23698
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23699
+ });
23700
+ it("first level with substitution with fallback keys", () => {
23701
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23702
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23703
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23704
+ });
23705
+ it("second level with substitution", () => {
23706
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23707
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
23708
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
23709
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23710
+ });
23711
+ it("second level with substitution with fallback keys", () => {
23712
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23713
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23714
+ });
23715
+ it("first level missing key doesn't find a value", () => {
23716
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "MissingKeyString"), "MissingKeyString");
23717
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "MissingKeyString"), "MissingKeyString");
23718
+ });
23719
+ it("second level missing key doesn't find a value", () => {
23720
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23721
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23722
+ });
23723
+ });
23724
+ describe("Keys Without Namespaces (German)", () => {
23725
+ it("first level with no substitution", () => {
23726
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "FirstTrivial"), "First level string (default german)");
23727
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "FirstTrivial"), "First level string (german)");
23728
+ });
23729
+ it("second level with no substitution", () => {
23730
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "SecondTrivial.Test1"), "Second level string 1 (default german)");
23731
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "SecondTrivial.Test2"), "Second level string 2 (default german)");
23732
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "SecondTrivial.Test1"), "Second level string 1 (german)");
23733
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "SecondTrivial.Test2"), "Second level string 2 (german)");
23734
+ });
23735
+ it("first level with substitution", () => {
23736
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
23737
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
23738
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
23739
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (german)");
23740
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (german)");
23741
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
23742
+ });
23743
+ it("second level with substitution", () => {
23744
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
23745
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
23746
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
23747
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
23748
+ });
23749
+ it("first level missing key doesn't find a value", () => {
23750
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "MissingKeyString"), "MissingKeyString");
23751
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "MissingKeyString"), "MissingKeyString");
23752
+ });
23753
+ it("second level missing key doesn't find a value", () => {
23754
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23755
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23756
+ });
23757
+ });
23758
+ // Currently broken
23759
+ describe.skip("Keys With Namespaces", () => {
23760
+ it("key with same namespace works", () => {
23761
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "Default:FirstTrivial"), "First level string (default)");
23762
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "Test:SecondTrivial.Test1"), "Second level string 1 (test)");
23763
+ });
23764
+ it("key with different namespace overrides given namespace", () => {
23765
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "Test:FirstTrivial"), "First level string (test)");
23766
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", "Default:FirstTrivial"), "First level string (default)");
23767
+ });
23768
+ it("key with same namespace works with fallback keys", () => {
23769
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", ["NotExist:FirstTrivial", "Default:FirstTrivial"]), "First level string (default)");
23770
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["NotExist:FirstTrivial", "Test:FirstTrivial"]), "First level string (test)");
23771
+ });
23772
+ it("key with different namespace overrides given namespace with fallback keys", () => {
23773
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", ["NotExist:FirstTrivial", "Test:FirstTrivial"]), "First level string (test)");
23774
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Test", ["NotExist:FirstTrivial", "Default:FirstTrivial"]), "First level string (default)");
23775
+ });
23776
+ it("missing key does not find a value", () => {
23777
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "Default:MissingKeyString"), "MissingKeyString");
23778
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Test", ["Missing1", "MissingKeyObject.MissingString"]), "MissingKeyObject.MissingString");
23779
+ });
23780
+ });
23781
+ describe("Nonexisting Namespace", () => {
23782
+ it("first level fails", () => {
23783
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "FirstTrivial"), "FirstTrivial");
23784
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "MissingKeyString"), "MissingKeyString");
23785
+ });
23786
+ it("second level fails", () => {
23787
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "SecondTrivial.Test1"), "SecondTrivial.Test1");
23788
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "Missing.String"), "Missing.String");
23789
+ });
23790
+ // Currently broken
23791
+ it.skip("empty string namespace falls back to default namespace", () => {
23792
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("", "FirstTrivial"), "First level string (default)");
23793
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("", "SecondTrivial.Test1"), "Second level string 1 (default)");
23794
+ });
23795
+ it("fallback key fails", () => {
23796
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", ["FirstTrivial", "NotExist"]), "NotExist");
23797
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", ["NotExist", "Missing.String"]), "Missing.String");
23798
+ });
23799
+ // Currently broken
23800
+ it.skip("use key with valid namespace instead", () => {
23801
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "Default:FirstTrivial"), "First level string (default)");
23802
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "Test:FirstTrivial"), "First level string (test)");
23803
+ });
23804
+ // Currently broken
23805
+ it.skip("providing key with invalid namespace fails", () => {
23806
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting1", "Nonexisting2:FirstTrivial"), "FirstTrivial");
23807
+ });
23808
+ });
23809
+ // Test a few options to make sure they get passed through correctly
23810
+ describe("With Options", () => {
23811
+ it("returnDetails throws error", () => {
23812
+ chai_1.assert.throws(() => {
23813
+ localization.getLocalizedStringWithNamespace("Default", "X", { returnDetails: true });
23814
+ }, "Translation key must map to a string, but the given options will result in an object");
23815
+ });
23816
+ it("returnObjects throws error", () => {
23817
+ chai_1.assert.throws(() => {
23818
+ localization.getLocalizedStringWithNamespace("Default", "X", { returnObjects: true });
23819
+ }, "Translation key must map to a string, but the given options will result in an object");
23820
+ });
23821
+ it("returnDetails and returnObjects throws error", () => {
23822
+ chai_1.assert.throws(() => {
23823
+ localization.getLocalizedStringWithNamespace("Default", "X", { returnDetails: true, returnObjects: true });
23824
+ }, "Translation key must map to a string, but the given options will result in an object");
23825
+ });
23826
+ it("default value", () => {
23827
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "Missing", { defaultValue: "default" }), "default");
23828
+ });
23829
+ it("override fallback language", () => {
23830
+ // Doesn't fallback to English
23831
+ chai_1.assert.equal(germanLocalization.getLocalizedStringWithNamespace("Default", "OnlyEnglish", { fallbackLng: "de" }), "OnlyEnglish");
23832
+ });
23833
+ // White box test
23834
+ it("given namespace overrides namespace translation option", () => {
23835
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
23836
+ chai_1.assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
23837
+ });
23838
+ });
23839
+ });
23840
+ describe("#getEnglishString", () => {
23841
+ before(async () => {
23842
+ localization = new ITwinLocalization_1.ITwinLocalization();
23843
+ await localization.initialize(["Default", "Test"]);
23844
+ germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
23845
+ await germanLocalization.initialize(["Default", "Test"]);
23846
+ });
23847
+ describe("Given Namespace", () => {
23848
+ it("first level with no substitution", () => {
23849
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
23850
+ chai_1.assert.equal(localization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
23851
+ });
23852
+ it("first level with no substitution with fallback keys", () => {
23853
+ chai_1.assert.equal(localization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
23854
+ chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
23855
+ });
23856
+ it("second level with no substitution", () => {
23857
+ chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
23858
+ chai_1.assert.equal(localization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
23859
+ chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
23860
+ chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
23861
+ });
23862
+ it("second level with no substitution with fallback keys", () => {
23863
+ chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
23864
+ chai_1.assert.equal(localization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
23865
+ });
23866
+ it("first level with substitution", () => {
23867
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23868
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
23869
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
23870
+ chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
23871
+ chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23872
+ chai_1.assert.equal(localization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23873
+ });
23874
+ it("first level with substitution with fallback keys", () => {
23875
+ chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23876
+ chai_1.assert.equal(localization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23877
+ chai_1.assert.equal(localization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23878
+ });
23879
+ it("second level with substitution", () => {
23880
+ chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23881
+ chai_1.assert.equal(localization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
23882
+ chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
23883
+ chai_1.assert.equal(localization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23884
+ });
23885
+ it("second level with substitution with fallback keys", () => {
23886
+ chai_1.assert.equal(localization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23887
+ chai_1.assert.equal(localization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23888
+ });
23889
+ it("first level missing key doesn't find a value", () => {
23890
+ chai_1.assert.equal(localization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
23891
+ chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
23892
+ });
23893
+ it("second level missing key doesn't find a value", () => {
23894
+ chai_1.assert.equal(localization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23895
+ chai_1.assert.equal(localization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23896
+ });
23897
+ });
23898
+ describe("Given Namespace with German default language returns English strings", () => {
23899
+ it("first level with no substitution", () => {
23900
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstTrivial"), "First level string (default)");
23901
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstTrivial"), "First level string (test)");
23902
+ });
23903
+ it("first level with no substitution with fallback keys", () => {
23904
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["FirstTrivial", "NotExist"]), "First level string (default)");
23905
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstTrivial"]), "First level string (test)");
23906
+ });
23907
+ it("second level with no substitution", () => {
23908
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test1"), "Second level string 1 (default)");
23909
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondTrivial.Test2"), "Second level string 2 (default)");
23910
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test1"), "Second level string 1 (test)");
23911
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.Test2"), "Second level string 2 (test)");
23912
+ });
23913
+ it("second level with no substitution with fallback keys", () => {
23914
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondTrivial.Test1"]), "Second level string 1 (default)");
23915
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondTrivial.Test2", "NotExist"]), "Second level string 2 (test)");
23916
+ });
23917
+ it("first level with substitution", () => {
23918
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23919
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (default)");
23920
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
23921
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM1" }), "First level CUSTOM1 (test)");
23922
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution1", { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23923
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "FirstSubstitution2", { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23924
+ });
23925
+ it("first level with substitution with fallback keys", () => {
23926
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "FirstSubstitution1"], { str: "CUSTOM1" }), "First level CUSTOM1 (default)");
23927
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["FirstSubstitution1", "NotExist"], { str: "CUSTOM2" }), "First level CUSTOM2 (test)");
23928
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["NotExist", "FirstSubstitution2"], { str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
23929
+ });
23930
+ it("second level with substitution", () => {
23931
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23932
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
23933
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test1", { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
23934
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondSubstitution.Test2", { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23935
+ });
23936
+ it("second level with substitution with fallback keys", () => {
23937
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", ["NotExist", "SecondSubstitution.Test1"], { varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
23938
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", ["SecondSubstitution.Test2", "NotExist"], { varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
23939
+ });
23940
+ it("first level missing key doesn't find a value", () => {
23941
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "MissingKeyString"), "MissingKeyString");
23942
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyString"), "MissingKeyString");
23943
+ });
23944
+ it("second level missing key doesn't find a value", () => {
23945
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "SecondTrivial.MissingString"), "SecondTrivial.MissingString");
23946
+ chai_1.assert.equal(germanLocalization.getEnglishString("Test", "MissingKeyObject.MissingString"), "MissingKeyObject.MissingString");
23947
+ });
23948
+ });
23949
+ describe("Nonexisting Namespace", () => {
23950
+ it("first level fails", () => {
23951
+ chai_1.assert.equal(localization.getEnglishString("Nonexisting", "FirstTrivial"), "FirstTrivial");
23952
+ chai_1.assert.equal(localization.getEnglishString("Nonexisting", "MissingKeyString"), "MissingKeyString");
23953
+ });
23954
+ it("second level fails", () => {
23955
+ chai_1.assert.equal(localization.getEnglishString("Nonexisting", "SecondTrivial.Test1"), "SecondTrivial.Test1");
23956
+ chai_1.assert.equal(localization.getEnglishString("Nonexisting", "Missing.String"), "Missing.String");
23957
+ });
23958
+ it("empty string namespace is treated as default namespace", () => {
23959
+ chai_1.assert.equal(localization.getEnglishString("", "FirstTrivial"), "First level string (default)");
23960
+ chai_1.assert.equal(localization.getEnglishString("", "SecondTrivial.Test1"), "Second level string 1 (default)");
23961
+ });
23962
+ });
23963
+ // Test a few options to make sure they get passed through correctly
23964
+ describe("With Options", () => {
23965
+ it("returnDetails throws error", () => {
23966
+ chai_1.assert.throws(() => {
23967
+ localization.getEnglishString("Default", "X", { returnDetails: true });
23968
+ }, "Translation key must map to a string, but the given options will result in an object");
23969
+ });
23970
+ it("returnObjects throws error", () => {
23971
+ chai_1.assert.throws(() => {
23972
+ localization.getEnglishString("Default", "X", { returnObjects: true });
23973
+ }, "Translation key must map to a string, but the given options will result in an object");
23974
+ });
23975
+ it("returnDetails and returnObjects throws error", () => {
23976
+ chai_1.assert.throws(() => {
23977
+ localization.getEnglishString("Default", "X", { returnDetails: true, returnObjects: true });
23978
+ }, "Translation key must map to a string, but the given options will result in an object");
23979
+ });
23980
+ it("default value", () => {
23981
+ chai_1.assert.equal(localization.getEnglishString("Default", "Missing", { defaultValue: "default" }), "default");
23982
+ });
23983
+ it("english takes priority over fallback language", () => {
23984
+ chai_1.assert.equal(germanLocalization.getEnglishString("Default", "OnlyEnglish", { fallbackLng: "de" }), "Hello");
23985
+ });
23986
+ // White box test
23987
+ it("given namespace overrides namespace translation option", () => {
23988
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
23989
+ chai_1.assert.equal(localization.getEnglishString("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
23990
+ });
23991
+ });
23992
+ });
23993
+ // Returned promises never have anything of substance, being only empty or resolving to null...
23994
+ // describe("#getNamespacePromise", () => {
23995
+ // });
23996
+ describe("#getLanguageList", () => {
23997
+ let languages;
23998
+ it("english language list includes en and en-US", async () => {
23999
+ localization = new ITwinLocalization_1.ITwinLocalization();
24000
+ await localization.initialize([]);
24001
+ languages = localization.getLanguageList();
24002
+ chai_1.assert.isTrue(languages.includes("en-US"));
24003
+ chai_1.assert.isTrue(languages.includes("en"));
24004
+ });
24005
+ it("when non-english language is set as default, that language and english are included in langauge list", async () => {
24006
+ germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
24007
+ await germanLocalization.initialize([]);
24008
+ languages = germanLocalization.getLanguageList();
24009
+ chai_1.assert.isTrue(languages.includes("en"));
24010
+ chai_1.assert.isTrue(languages.includes("de"));
24011
+ });
24012
+ });
24013
+ describe("#changeLanguage", () => {
24014
+ it("change from english to another language", async () => {
24015
+ localization = new ITwinLocalization_1.ITwinLocalization();
24016
+ await localization.initialize(["Default"]);
24017
+ chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
24018
+ await localization.changeLanguage("de");
24019
+ chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
24020
+ });
24021
+ it("change from another language to english", async () => {
24022
+ localization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
24023
+ await localization.initialize(["Default"]);
24024
+ chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default german)"); // german
24025
+ await localization.changeLanguage("en");
24026
+ chai_1.assert.equal(localization.getLocalizedString("FirstTrivial"), "First level string (default)"); // english
24027
+ });
24028
+ });
24029
+ describe("#registerNamespace", () => {
24030
+ let itwinLocalization;
24031
+ beforeEach(async () => {
24032
+ itwinLocalization = new ITwinLocalization_1.ITwinLocalization();
24033
+ });
24034
+ it("can read from namespace after it is registered", async () => {
24035
+ await itwinLocalization.initialize([]);
24036
+ await itwinLocalization.registerNamespace("Test");
24037
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
24038
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
24039
+ });
24040
+ it("zero initial, register one", async () => {
24041
+ await itwinLocalization.initialize([]);
24042
+ await itwinLocalization.registerNamespace("test1");
24043
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
24044
+ });
24045
+ it("zero initial, register two", async () => {
24046
+ await itwinLocalization.initialize([]);
24047
+ await itwinLocalization.registerNamespace("test1");
24048
+ await itwinLocalization.registerNamespace("test2");
24049
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
24050
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
24051
+ });
24052
+ it("one initial, register one", async () => {
24053
+ await itwinLocalization.initialize(["initial1"]);
24054
+ await itwinLocalization.registerNamespace("test1");
24055
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
24056
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
24057
+ });
24058
+ it("one initial, register two", async () => {
24059
+ await itwinLocalization.initialize(["initial1"]);
24060
+ await itwinLocalization.registerNamespace("test1");
24061
+ await itwinLocalization.registerNamespace("test2");
24062
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
24063
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test2"));
24064
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
24065
+ });
24066
+ it("two initial, register one", async () => {
24067
+ await itwinLocalization.initialize(["initial1", "initial2"]);
24068
+ await itwinLocalization.registerNamespace("test1");
24069
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
24070
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
24071
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
24072
+ });
24073
+ it("two initial, register two", async () => {
24074
+ await itwinLocalization.initialize(["initial1", "initial2"]);
24075
+ await itwinLocalization.registerNamespace("test1");
24076
+ await itwinLocalization.registerNamespace("test2");
24077
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("test1"));
24078
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial1"));
24079
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("initial2"));
24080
+ });
24081
+ it("register duplicate namespaces", async () => {
24082
+ await itwinLocalization.initialize([]);
24083
+ await itwinLocalization.registerNamespace("Test");
24084
+ await itwinLocalization.registerNamespace("Test");
24085
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
24086
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
24087
+ });
24088
+ it("register duplicate namespace of initial namespace doesn't break anything", async () => {
24089
+ await itwinLocalization.initialize(["Test"]);
24090
+ await itwinLocalization.registerNamespace("Test");
24091
+ chai_1.assert.isTrue(itwinLocalization.i18next.hasLoadedNamespace("Test"));
24092
+ chai_1.assert.equal(itwinLocalization.getLocalizedString("Test:FirstTrivial"), "First level string (test)");
23338
24093
  });
23339
24094
  });
24095
+ // unregisterNamespace() isn't used and basically does nothing
24096
+ // describe("#unregisterNamespace", () => {
24097
+ // });
23340
24098
  });
23341
24099
 
23342
24100
  })();