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
Documented the new customizable locale detection feature:
- Updated description of the locale detection procedure at the top of page `i18n/create-i18n.md`;
- Added section `detectLocale(callback)` to pages `extending-components/with-i18n.md` and `extending-components/with-18n-reactive.md`;
- Added sections `setLocaleDetectionRule(rule)` and `detectLocale(callback)` to page `i18n/create-i18n.md`.
Copy file name to clipboardExpand all lines: src/extending-components/with-i18n-reactive.md
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ The following methods are available within the component on `this..i18n`.
51
51
The `t()` method retrieves the translation message for the current locale.
52
52
The following arguments can be passed to the `t()` method.
53
53
54
-
| Argument | Type | Required | Description |
54
+
| Argument | Type | Required | Description |
55
55
| --- | --- | --- | --- |
56
56
|`key`|`string`| Yes | The key for the specific message. This can be a nested key like `buttons.increment`|
57
57
|`templateData`|`object`|| The optional data for message interpolation. The keys must match the message value. For example; the message `Greeting {{ name }}` requires a `templateData` object containing `{ name: 'FicuJS' }`|
@@ -67,9 +67,17 @@ The `setLocale()` method sets the current locale of the i18n instance.
67
67
68
68
The following arguments can be passed to the `setLocale()` method.
|`locale`|`string`| Yes | The locale string. The default is `en`|
70
+
| Argument | Type | Required | Description |
71
+
| --- | --- | --- | --- |
72
+
|`locale`|`string`| Yes | The locale string. The default is `en`|
73
+
74
+
## detectLocale(callback)
75
+
76
+
The `detectLocale(callback)` method triggers the automated locale detection procedure and updates the current locale accordingly.
77
+
78
+
| Argument | Type | Required | Description |
79
+
| --- | --- | --- | --- |
80
+
|`callback`|`function`|| A function that is called after locale detection has completed. It is invoked with two arguments: `oldLocale` and `newLocale`|
Copy file name to clipboardExpand all lines: src/extending-components/with-i18n.md
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ The following methods are available within the component on `this..i18n`.
41
41
The `t()` method retrieves the translation message for the current locale.
42
42
The following arguments can be passed to the `t()` method.
43
43
44
-
| Argument | Type | Required | Description |
44
+
| Argument | Type | Required | Description |
45
45
| --- | --- | --- | --- |
46
46
|`key`|`string`| Yes | The key for the specific message. This can be a nested key like `buttons.increment`|
47
47
|`templateData`|`object`|| The optional data for message interpolation. The keys must match the message value. For example; the message `Greeting {{ name }}` requires a `templateData` object containing `{ name: 'FicuJS' }`|
@@ -57,10 +57,18 @@ The `setLocale()` method sets the current locale of the i18n instance.
57
57
58
58
The following arguments can be passed to the `setLocale()` method.
59
59
60
-
| Argument | Type | Required | Description |
60
+
| Argument | Type | Required | Description |
61
61
| --- | --- | --- | --- |
62
62
|`locale`|`string`| Yes | The locale string. The default is `en`|
63
63
64
+
## detectLocale(callback)
65
+
66
+
The `detectLocale(callback)` method triggers the automated locale detection procedure and updates the current locale accordingly.
67
+
68
+
| Argument | Type | Required | Description |
69
+
| --- | --- | --- | --- |
70
+
|`callback`|`function`|| A function that is called after locale detection has completed. It is invoked with two arguments: `oldLocale` and `newLocale`|
71
+
64
72
## setI18n method
65
73
66
74
The `setI18n()` method can be called when an instance needs to be set after the component has initialised.
The following arguments can be passed to the `t()` method.
91
91
92
-
| Argument | Type | Required | Description |
92
+
| Argument | Type | Required | Description |
93
93
| --- | --- | --- | --- |
94
94
|`key`|`string`| Yes | The key for the specific message. This can be a nested key like `navbar.buttons.home`|
95
95
|`templateData`|`object`|| The optional data for message interpolation. The keys must match the message value. For example; the message <code>Greeting {\{ name }}</code> requires a `templateData` object containing `{ name: 'FicusJS' }`|
The `detectLocale()` method triggers the automated locale detection procedure and updates the current locale accordingly. If no detection methods provide a value, the current locale stays unchanged.
136
+
137
+
| Argument | Type | Required | Description |
138
+
| --- | --- | --- | --- |
139
+
|`callback`|`function`|| A function that is called after locale detection has completed. It is invoked with two arguments: `newLocale` and `oldLocale`|
the `setLocaleDetectionRule()` method updates the user-defined locale detection rule.
176
+
177
+
| Argument | Type | Required | Description |
178
+
|---|---|---|---|
179
+
|`rule`| any || Either a static value, a promise that resolves to a static value, or a function that returns either a static value or a promise that resolves to a static value |
180
+
181
+
- If `rule` is a function, it is re-evaluated every time that the locale detection procedure is triggered, and its result is treated according to the following two rules;
182
+
- If `rule` or the result of a `rule` function is a string or a promise that resolves to a string, the current locale is set to that value;
183
+
- If `rule` or the result of a `rule` function is a non-string value or a promise that resolves to a non-string value, the locale detection procedure skips the user-defined detection rule.
184
+
185
+
```js
186
+
// Disable user-defined locale detection and instead rely on the fallback detection methods
187
+
I18n.setLocaleDetectionRule(null)
188
+
189
+
// Force user-defined locale detection to 'fr'
190
+
I18n.setLocaleDetectionRule('fr')
191
+
192
+
// Get locale from subdomain, if present in the URL, relying on the fallback detection methods if undefined
193
+
I18n.setLocaleDetectionRule(() =>
194
+
new URL(window.location).host.split('.').reverse()[2]
195
+
)
196
+
197
+
// Asynchronously query a back-end API, relying on the fallback detection methods in case of HTTP error or undefined result
The `setPluralizationRule()` method sets a locale-specific pluralization rule function to determine plural form variation index.
157
207
158
208
| Argument | Type | Required | Description |
159
209
| --- | --- | --- | --- |
160
210
|`locale`|`string`| Yes | The locale that the `rule` function is defined for |
161
-
|`rule`|`function`| Yes | A locale-specific function that receive a count as parameter and returns an index into the array of pluralized translated messages |
211
+
|`rule`|`function`| Yes | A locale-specific function that receives a count as parameter and returns an index into the array of pluralized translated messages |
162
212
|`options`|`object`|| An optional set of locale-specific options for the pluralization rule |
0 commit comments