1 |
|
2 |
|
3 | import { assert } from "chai"
|
4 | import Localizer from "../src/Localizer"
|
5 |
|
6 | describe("Localizer", function () {
|
7 | before(function () {
|
8 | this.data = {
|
9 | locales: [
|
10 | { code: "en", name: "English" },
|
11 | { code: "es", name: "Espanol" }
|
12 | ],
|
13 | strings: [
|
14 | { en: "dog", es: "perro" },
|
15 | { en: "cat", es: "gato" },
|
16 | { en: "a {0} b {1} c", es: "x {1} y {0} z" }
|
17 | ]
|
18 | }
|
19 | return (this.loc = new Localizer(this.data, "es"))
|
20 | })
|
21 |
|
22 | it("localizes string", function () {
|
23 | return assert.equal(this.loc.localizeString("dog"), "perro")
|
24 | })
|
25 |
|
26 | it("falls back to english", function () {
|
27 | return assert.equal(this.loc.localizeString("fish"), "fish")
|
28 | })
|
29 |
|
30 | it("replaces parameters", function () {
|
31 | return assert.equal(this.loc.localizeString("a {0} b {1} c", "1", 2), "x 2 y 1 z")
|
32 | })
|
33 |
|
34 | it("T replaces parameters", function () {
|
35 | return assert.equal(this.loc.T("a {0} b {1} c", "1", 2), "x 2 y 1 z")
|
36 | })
|
37 |
|
38 | return describe("react-style localization", () =>
|
39 | it("returns array with objects", function () {
|
40 | return assert.deepEqual(this.loc.T("a {0} b {1} c", { x: 1 }, { y: 2 }), ["x ", { y: 2 }, " y ", { x: 1 }, " z"])
|
41 | }))
|
42 | })
|