You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Localization file naming convention: messages_{lang}.json, where {lang} is two-letters (ISO 639-1) language code.
8
+
9
+
List of supported localizations is presented in locales.json file in the same directory:
10
+
```
11
+
[
12
+
{
13
+
"code": "en",
14
+
"name": "English",
15
+
"default": true
16
+
},
17
+
{
18
+
"code": "ru",
19
+
"name": "Русский"
20
+
},
21
+
{
22
+
"code": "ko",
23
+
"name": "한국어"
24
+
},
25
+
{
26
+
"code": "zh",
27
+
"name": "中文"
28
+
}
29
+
]
30
+
```
31
+
32
+
Messages file is in JSON format and contains localized messages organized as a tree:
33
+
```
34
+
{
35
+
"section1": {
36
+
"subsection1": {
37
+
"message": "Localized message1"
38
+
},
39
+
"subsection2": {
40
+
"message": "Localized message2"
41
+
},
42
+
},
43
+
"section2": {
44
+
"subsection1": {
45
+
"message": "Localized message3 <%=param%>"
46
+
}
47
+
}
48
+
}
49
+
```
50
+
51
+
so each localized message has a unique path. For example: ``section1.subsection2.message`` points to "Localized message1".
52
+
53
+
## Frontend
54
+
55
+
Languages listed in locales.json are shown in the selector on the upper part of the page.
56
+
57
+
When choosing a language, all text on the page changes dynamically without the need to reload the page.
58
+
59
+
Reference to localized message can be placed whereever ko object is available.
60
+
61
+
There are two methods in ko for localized messages (see js/extensions/bindings/i18nBinding.js):
62
+
63
+
-`ko.i18n(path, defaultMessage)` where path is a path to the message in the localization file `messages_{lang}.json` and `defaultMessage` is a text, that will be used if there is no such path in localization file.
64
+
65
+
-`ko.i18nformat(path, defaultMessage, parameters)` - same as above, but with parameters.
66
+
For example:
67
+
message (in localization file and/or default): `Localized message3 <%=param%>`
68
+
parameters object: `{"param": "some text"}`
69
+
result: `Localized message3 some text`
70
+
Parameter values can be localized as well with any nesting level.
71
+
72
+
Both methods return ko.pureComputed() function, that can be unwrapped or called to receive a localized message (see examples below).
0 commit comments