@itwin/core-i18n 3.5.0-dev.53 → 3.5.0-dev.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/test/ITwinLocalization.test.js +80 -89
- package/lib/cjs/test/ITwinLocalization.test.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js +224 -233
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.js +80 -89
- package/lib/cjs/test/webpack/bundled-tests.js.map +1 -1
- package/lib/esm/test/ITwinLocalization.test.js +80 -89
- package/lib/esm/test/ITwinLocalization.test.js.map +1 -1
- package/package.json +7 -7
|
@@ -440,7 +440,7 @@ describe("ITwinLocalization", () => {
|
|
|
440
440
|
});
|
|
441
441
|
});
|
|
442
442
|
});
|
|
443
|
-
describe("#
|
|
443
|
+
describe("#getLocalizedString with namespace passed in as an option", () => {
|
|
444
444
|
before(async () => {
|
|
445
445
|
localization = new ITwinLocalization();
|
|
446
446
|
await localization.initialize(["Default", "Test"]);
|
|
@@ -449,168 +449,159 @@ describe("ITwinLocalization", () => {
|
|
|
449
449
|
});
|
|
450
450
|
describe("Keys Without Namespaces", () => {
|
|
451
451
|
it("first level with no substitution", () => {
|
|
452
|
-
assert.equal(localization.
|
|
453
|
-
assert.equal(localization.
|
|
452
|
+
assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
453
|
+
assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (test)");
|
|
454
454
|
});
|
|
455
455
|
it("first level with no substitution with fallback keys", () => {
|
|
456
|
-
assert.equal(localization.
|
|
457
|
-
assert.equal(localization.
|
|
456
|
+
assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Default" }), "First level string (default)");
|
|
457
|
+
assert.equal(localization.getLocalizedString(["NotExist", "FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
458
458
|
});
|
|
459
459
|
it("second level with no substitution", () => {
|
|
460
|
-
assert.equal(localization.
|
|
461
|
-
assert.equal(localization.
|
|
462
|
-
assert.equal(localization.
|
|
463
|
-
assert.equal(localization.
|
|
460
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default)");
|
|
461
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default)");
|
|
462
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
463
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (test)");
|
|
464
464
|
});
|
|
465
465
|
it("second level with no substitution with fallback keys", () => {
|
|
466
|
-
assert.equal(localization.
|
|
467
|
-
assert.equal(localization.
|
|
466
|
+
assert.equal(localization.getLocalizedString(["NotExist", "SecondTrivial.Test1"], { ns: "Default" }), "Second level string 1 (default)");
|
|
467
|
+
assert.equal(localization.getLocalizedString(["SecondTrivial.Test2", "NotExist"], { ns: "Test" }), "Second level string 2 (test)");
|
|
468
468
|
});
|
|
469
469
|
it("first level with substitution", () => {
|
|
470
|
-
assert.equal(localization.
|
|
471
|
-
assert.equal(localization.
|
|
472
|
-
assert.equal(localization.
|
|
473
|
-
assert.equal(localization.
|
|
474
|
-
assert.equal(localization.
|
|
475
|
-
assert.equal(localization.
|
|
470
|
+
assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
471
|
+
assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default)");
|
|
472
|
+
assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default)");
|
|
473
|
+
assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (test)");
|
|
474
|
+
assert.equal(localization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
475
|
+
assert.equal(localization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
476
476
|
});
|
|
477
477
|
it("first level with substitution with fallback keys", () => {
|
|
478
|
-
assert.equal(localization.
|
|
479
|
-
assert.equal(localization.
|
|
480
|
-
assert.equal(localization.
|
|
478
|
+
assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution1"], { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default)");
|
|
479
|
+
assert.equal(localization.getLocalizedString(["FirstSubstitution1", "NotExist"], { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (test)");
|
|
480
|
+
assert.equal(localization.getLocalizedString(["NotExist", "FirstSubstitution2"], { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (test)");
|
|
481
481
|
});
|
|
482
482
|
it("second level with substitution", () => {
|
|
483
|
-
assert.equal(localization.
|
|
484
|
-
assert.equal(localization.
|
|
485
|
-
assert.equal(localization.
|
|
486
|
-
assert.equal(localization.
|
|
483
|
+
assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
484
|
+
assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default)");
|
|
485
|
+
assert.equal(localization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (test)");
|
|
486
|
+
assert.equal(localization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
487
487
|
});
|
|
488
488
|
it("second level with substitution with fallback keys", () => {
|
|
489
|
-
assert.equal(localization.
|
|
490
|
-
assert.equal(localization.
|
|
489
|
+
assert.equal(localization.getLocalizedString(["NotExist", "SecondSubstitution.Test1"], { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default)");
|
|
490
|
+
assert.equal(localization.getLocalizedString(["SecondSubstitution.Test2", "NotExist"], { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (test)");
|
|
491
491
|
});
|
|
492
492
|
it("first level missing key doesn't find a value", () => {
|
|
493
|
-
assert.equal(localization.
|
|
494
|
-
assert.equal(localization.
|
|
493
|
+
assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
494
|
+
assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
495
495
|
});
|
|
496
496
|
it("second level missing key doesn't find a value", () => {
|
|
497
|
-
assert.equal(localization.
|
|
498
|
-
assert.equal(localization.
|
|
497
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
498
|
+
assert.equal(localization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
499
499
|
});
|
|
500
500
|
});
|
|
501
501
|
describe("Keys Without Namespaces (German)", () => {
|
|
502
502
|
it("first level with no substitution", () => {
|
|
503
|
-
assert.equal(germanLocalization.
|
|
504
|
-
assert.equal(germanLocalization.
|
|
503
|
+
assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Default" }), "First level string (default german)");
|
|
504
|
+
assert.equal(germanLocalization.getLocalizedString("FirstTrivial", { ns: "Test" }), "First level string (german)");
|
|
505
505
|
});
|
|
506
506
|
it("second level with no substitution", () => {
|
|
507
|
-
assert.equal(germanLocalization.
|
|
508
|
-
assert.equal(germanLocalization.
|
|
509
|
-
assert.equal(germanLocalization.
|
|
510
|
-
assert.equal(germanLocalization.
|
|
507
|
+
assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Default" }), "Second level string 1 (default german)");
|
|
508
|
+
assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Default" }), "Second level string 2 (default german)");
|
|
509
|
+
assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (german)");
|
|
510
|
+
assert.equal(germanLocalization.getLocalizedString("SecondTrivial.Test2", { ns: "Test" }), "Second level string 2 (german)");
|
|
511
511
|
});
|
|
512
512
|
it("first level with substitution", () => {
|
|
513
|
-
assert.equal(germanLocalization.
|
|
514
|
-
assert.equal(germanLocalization.
|
|
515
|
-
assert.equal(germanLocalization.
|
|
516
|
-
assert.equal(germanLocalization.
|
|
517
|
-
assert.equal(germanLocalization.
|
|
518
|
-
assert.equal(germanLocalization.
|
|
513
|
+
assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM1" }), "First level CUSTOM1 (default german)");
|
|
514
|
+
assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Default", str: "CUSTOM2" }), "First level CUSTOM2 (default german)");
|
|
515
|
+
assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Default", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (default german)");
|
|
516
|
+
assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM1" }), "First level CUSTOM1 (german)");
|
|
517
|
+
assert.equal(germanLocalization.getLocalizedString("FirstSubstitution1", { ns: "Test", str: "CUSTOM2" }), "First level CUSTOM2 (german)");
|
|
518
|
+
assert.equal(germanLocalization.getLocalizedString("FirstSubstitution2", { ns: "Test", str1: "CUSTOM1", str2: "CUSTOM2" }), "First level CUSTOM1 and CUSTOM2 (german)");
|
|
519
519
|
});
|
|
520
520
|
it("second level with substitution", () => {
|
|
521
|
-
assert.equal(germanLocalization.
|
|
522
|
-
assert.equal(germanLocalization.
|
|
523
|
-
assert.equal(germanLocalization.
|
|
524
|
-
assert.equal(germanLocalization.
|
|
521
|
+
assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (default german)");
|
|
522
|
+
assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Default", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (default german)");
|
|
523
|
+
assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test1", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Substitute Variable1 and Variable2 (german)");
|
|
524
|
+
assert.equal(germanLocalization.getLocalizedString("SecondSubstitution.Test2", { ns: "Test", varA: "Variable1", varB: "Variable2" }), "Reverse substitute Variable2 and Variable1 (german)");
|
|
525
525
|
});
|
|
526
526
|
it("first level missing key doesn't find a value", () => {
|
|
527
|
-
assert.equal(germanLocalization.
|
|
528
|
-
assert.equal(germanLocalization.
|
|
527
|
+
assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
528
|
+
assert.equal(germanLocalization.getLocalizedString("MissingKeyString", { ns: "Test" }), "MissingKeyString");
|
|
529
529
|
});
|
|
530
530
|
it("second level missing key doesn't find a value", () => {
|
|
531
|
-
assert.equal(germanLocalization.
|
|
532
|
-
assert.equal(germanLocalization.
|
|
531
|
+
assert.equal(germanLocalization.getLocalizedString("SecondTrivial.MissingString", { ns: "Test" }), "SecondTrivial.MissingString");
|
|
532
|
+
assert.equal(germanLocalization.getLocalizedString("MissingKeyObject.MissingString", { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
533
533
|
});
|
|
534
534
|
});
|
|
535
|
-
|
|
536
|
-
describe.skip("Keys With Namespaces", () => {
|
|
535
|
+
describe("Keys With Namespaces", () => {
|
|
537
536
|
it("key with same namespace works", () => {
|
|
538
|
-
assert.equal(localization.
|
|
539
|
-
assert.equal(localization.
|
|
537
|
+
assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Default" }), "First level string (default)");
|
|
538
|
+
assert.equal(localization.getLocalizedString("Test:SecondTrivial.Test1", { ns: "Test" }), "Second level string 1 (test)");
|
|
540
539
|
});
|
|
541
540
|
it("key with different namespace overrides given namespace", () => {
|
|
542
|
-
assert.equal(localization.
|
|
543
|
-
assert.equal(localization.
|
|
541
|
+
assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Default" }), "First level string (test)");
|
|
542
|
+
assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
544
543
|
});
|
|
545
544
|
it("key with same namespace works with fallback keys", () => {
|
|
546
|
-
assert.equal(localization.
|
|
547
|
-
assert.equal(localization.
|
|
545
|
+
assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Default" }), "First level string (default)");
|
|
546
|
+
assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Test" }), "First level string (test)");
|
|
548
547
|
});
|
|
549
548
|
it("key with different namespace overrides given namespace with fallback keys", () => {
|
|
550
|
-
assert.equal(localization.
|
|
551
|
-
assert.equal(localization.
|
|
549
|
+
assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Test:FirstTrivial"], { ns: "Default" }), "First level string (test)");
|
|
550
|
+
assert.equal(localization.getLocalizedString(["NotExist:FirstTrivial", "Default:FirstTrivial"], { ns: "Test" }), "First level string (default)");
|
|
552
551
|
});
|
|
553
552
|
it("missing key does not find a value", () => {
|
|
554
|
-
assert.equal(germanLocalization.
|
|
555
|
-
assert.equal(germanLocalization.
|
|
553
|
+
assert.equal(germanLocalization.getLocalizedString("Default:MissingKeyString", { ns: "Default" }), "MissingKeyString");
|
|
554
|
+
assert.equal(germanLocalization.getLocalizedString(["Missing1", "MissingKeyObject.MissingString"], { ns: "Test" }), "MissingKeyObject.MissingString");
|
|
556
555
|
});
|
|
557
556
|
});
|
|
558
557
|
describe("Nonexisting Namespace", () => {
|
|
559
558
|
it("first level fails", () => {
|
|
560
|
-
assert.equal(localization.
|
|
561
|
-
assert.equal(localization.
|
|
559
|
+
assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "Nonexisting" }), "FirstTrivial");
|
|
560
|
+
assert.equal(localization.getLocalizedString("MissingKeyString", { ns: "Nonexisting" }), "MissingKeyString");
|
|
562
561
|
});
|
|
563
562
|
it("second level fails", () => {
|
|
564
|
-
assert.equal(localization.
|
|
565
|
-
assert.equal(localization.
|
|
563
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "Nonexisting" }), "SecondTrivial.Test1");
|
|
564
|
+
assert.equal(localization.getLocalizedString("Missing.String", { ns: "Nonexisting" }), "Missing.String");
|
|
566
565
|
});
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
assert.equal(localization.
|
|
570
|
-
assert.equal(localization.getLocalizedStringWithNamespace("", "SecondTrivial.Test1"), "Second level string 1 (default)");
|
|
566
|
+
it("empty string namespace falls back to default namespace", () => {
|
|
567
|
+
assert.equal(localization.getLocalizedString("FirstTrivial", { ns: "" }), "First level string (default)");
|
|
568
|
+
assert.equal(localization.getLocalizedString("SecondTrivial.Test1", { ns: "" }), "Second level string 1 (default)");
|
|
571
569
|
});
|
|
572
570
|
it("fallback key fails", () => {
|
|
573
|
-
assert.equal(localization.
|
|
574
|
-
assert.equal(localization.
|
|
571
|
+
assert.equal(localization.getLocalizedString(["FirstTrivial", "NotExist"], { ns: "Nonexisting" }), "NotExist");
|
|
572
|
+
assert.equal(localization.getLocalizedString(["NotExist", "Missing.String"], { ns: "Nonexisting" }), "Missing.String");
|
|
575
573
|
});
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
assert.equal(localization.
|
|
579
|
-
assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting", "Test:FirstTrivial"), "First level string (test)");
|
|
574
|
+
it("use key with valid namespace instead", () => {
|
|
575
|
+
assert.equal(localization.getLocalizedString("Default:FirstTrivial", { ns: "Nonexisting" }), "First level string (default)");
|
|
576
|
+
assert.equal(localization.getLocalizedString("Test:FirstTrivial", { ns: "Nonexisting" }), "First level string (test)");
|
|
580
577
|
});
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
assert.equal(localization.getLocalizedStringWithNamespace("Nonexisting1", "Nonexisting2:FirstTrivial"), "FirstTrivial");
|
|
578
|
+
it("providing key with invalid namespace fails", () => {
|
|
579
|
+
assert.equal(localization.getLocalizedString("Nonexisting2:FirstTrivial", { ns: "Nonexisting1" }), "FirstTrivial");
|
|
584
580
|
});
|
|
585
581
|
});
|
|
586
582
|
// Test a few options to make sure they get passed through correctly
|
|
587
583
|
describe("With Options", () => {
|
|
588
584
|
it("returnDetails throws error", () => {
|
|
589
585
|
assert.throws(() => {
|
|
590
|
-
localization.
|
|
586
|
+
localization.getLocalizedString("X", { ns: "Default", returnDetails: true });
|
|
591
587
|
}, "Translation key must map to a string, but the given options will result in an object");
|
|
592
588
|
});
|
|
593
589
|
it("returnObjects throws error", () => {
|
|
594
590
|
assert.throws(() => {
|
|
595
|
-
localization.
|
|
591
|
+
localization.getLocalizedString("X", { ns: "Default", returnObjects: true });
|
|
596
592
|
}, "Translation key must map to a string, but the given options will result in an object");
|
|
597
593
|
});
|
|
598
594
|
it("returnDetails and returnObjects throws error", () => {
|
|
599
595
|
assert.throws(() => {
|
|
600
|
-
localization.
|
|
596
|
+
localization.getLocalizedString("X", { ns: "Default", returnDetails: true, returnObjects: true });
|
|
601
597
|
}, "Translation key must map to a string, but the given options will result in an object");
|
|
602
598
|
});
|
|
603
599
|
it("default value", () => {
|
|
604
|
-
assert.equal(localization.
|
|
600
|
+
assert.equal(localization.getLocalizedString("Missing", { ns: "Default", defaultValue: "default" }), "default");
|
|
605
601
|
});
|
|
606
602
|
it("override fallback language", () => {
|
|
607
603
|
// Doesn't fallback to English
|
|
608
|
-
assert.equal(germanLocalization.
|
|
609
|
-
});
|
|
610
|
-
// White box test
|
|
611
|
-
it("given namespace overrides namespace translation option", () => {
|
|
612
|
-
assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstTrivial", { ns: "Test" }), "First level string (default)");
|
|
613
|
-
assert.equal(localization.getLocalizedStringWithNamespace("Default", "FirstSubstitution1", { str: "CUSTOM1", ns: "Test" }), "First level CUSTOM1 (default)");
|
|
604
|
+
assert.equal(germanLocalization.getLocalizedString("OnlyEnglish", { ns: "Default", fallbackLng: "de" }), "OnlyEnglish");
|
|
614
605
|
});
|
|
615
606
|
});
|
|
616
607
|
});
|