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
Copy file name to clipboardExpand all lines: current/en-us/7. plugins/4. i18n.md
+24-55Lines changed: 24 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Aurelia-I18N is tested and optimized to support both JS and TS, as well as the f
26
26
* Webpack
27
27
28
28
Please continue with the section which suites your setup. In addition to this, you must
29
-
pick your own backend service. For this guide we're going to leverage the [XHR backend plugin](https://github.com/i18next/i18next-xhr-backend),
29
+
pick your own backend service. For this guide we're going to leverage the [HTTP backend plugin](https://github.com/i18next/i18next-http-backend),
30
30
or a variation of this plugin — `aurelia-i18n-loader` — that uses the aurelia loader, which is bundled with the aurelia-i18n plugin.
31
31
We'll discuss TypeScript specifics in a later section.
32
32
@@ -38,11 +38,11 @@ In order to install the Plugin with a CLI Project, first install the plugin via
38
38
npm install aurelia-i18n
39
39
```
40
40
41
-
Since Aurelia-I18N is backed by i18next, you should install it and a backend plugin of your choice. You can use the built-in backend that uses aurelia's loader or any of your choice.
42
-
As an example we're going to leverage the i18next-xhr-backend:
41
+
Since Aurelia-I18N is backed by i18next, you should install it and a backend plugin of your choice.
42
+
As an example we're going to leverage the i18next-http-backend:
43
43
44
44
```Shell
45
-
npm install i18next i18next-xhr-backend
45
+
npm install i18next i18next-http-backend
46
46
```
47
47
48
48
### JSPM
@@ -56,7 +56,7 @@ jspm install aurelia-i18n
56
56
And optionally install the backend service using:
57
57
58
58
```Shell
59
-
jspm install npm:i18next-xhr-backend
59
+
jspm install npm:i18next-http-backend
60
60
```
61
61
62
62
> Info
@@ -76,16 +76,16 @@ or if you prefer yarn
76
76
yarn add aurelia-i18n
77
77
```
78
78
79
-
Also optionally install the `i18next-xhr-backend` plugin:
79
+
Also optionally install the `i18next-http-backend` plugin:
80
80
81
81
```Shell
82
-
npm install i18next-xhr-backend
82
+
npm install i18next-http-backend
83
83
```
84
84
85
85
or using yarn
86
86
87
87
```Shell
88
-
yarn add i18next-xhr-backend
88
+
yarn add i18next-http-backend
89
89
```
90
90
91
91
> Info
@@ -137,50 +137,19 @@ Fourth, in those subfolders create a file named `translation.json` which contain
137
137
}
138
138
```
139
139
140
-
Fifth, create (if you haven't already) a file `main.js` in your `src` folder to configure the plugin. Depending on which backend you've chosen there might
141
-
be slight differences. The following listings show the configuration for first the built-in aurelia loader, the second using i18next-xhr-backend.
140
+
Fifth, create (if you haven't already) a file `main.js` in your `src` folder to configure the plugin.
141
+
We use i18next-http-backend here. Note that, since i18next-xhr-backend is deprecated, Backend in aurelia-i18n and Backend in i18next--backend are not valid options.
142
+
142
143
143
144
> Info
144
145
> Notice that Aurelia I18N makes use of a non-standard attributes option, which is used to define custom aliases besides the default ones, being `t` and `i18n`. Calling `TCustomAttribute.configureAliases` is currently necessary in order make sure that the aliases are defined before view templates are fully processed.
145
146
146
-
```JavaScript Registering the Plugin - using the built-in aurelia loader backed
importBackendfrom'i18next-xhr-backend'; // <-- your previously installed backend plugin
149
+
importBackendfrom'i18next-http-backend'; // <-- your previously installed backend plugin
181
150
182
151
// if you use TypeScript and target ES5 you might need to import it like this instead
183
-
// import * as Backend from 'i18next-xhr-backend';
152
+
// import * as Backend from 'i18next-http-backend';
184
153
// otherwise add "allowSyntheticDefaultImports": true, to your tsconfig
185
154
186
155
exportfunctionconfigure(aurelia) {
@@ -199,7 +168,7 @@ export function configure(aurelia) {
199
168
// make sure to return the promise of the setup method, in order to guarantee proper loading
200
169
returninstance.setup({
201
170
backend: { // <-- configure backend settings
202
-
loadPath:'./locales/{{lng}}/{{ns}}.json', // <-- XHR settings for where to get the files from
171
+
loadPath:'./locales/{{lng}}/{{ns}}.json', // <-- HTTP settings for where to get the files from
203
172
},
204
173
attributes: aliases,
205
174
lng :'de',
@@ -212,9 +181,9 @@ export function configure(aurelia) {
212
181
}
213
182
```
214
183
215
-
To have `webpack` serving your translation files for `i18next-xhr-backend`, they need to be copied into the virtual (development) or actual (production) output directory. To copy them from `src/locales/` to `$outputDir$/locales/`, add the following entry under the plugins section of your `webpack.config.js`.
184
+
To have `webpack` serving your translation files for `i18next-http-backend`, they need to be copied into the virtual (development) or actual (production) output directory. To copy them from `src/locales/` to `$outputDir$/locales/`, add the following entry under the plugins section of your `webpack.config.js`.
216
185
217
-
```JavaScript Copy translation files for webpack and i18next-xhr-backend
186
+
```JavaScript Copy translation files for webpack and i18next-http-backend
218
187
plugins: [
219
188
// ...
220
189
newCopyWebpackPlugin([
@@ -252,7 +221,7 @@ If you are using [`reflect-metadata`](https://www.npmjs.com/package/reflect-meta
252
221
253
222
In order to get proper support for autocompletion and typesafety you should install
254
223
the necessary type definitions (d.ts) for the plugins dependencies.
255
-
Here we show how you can do that for i18next and the i18next-xhr-backend, but this
224
+
Here we show how you can do that for i18next and the i18next-http-backend, but this
256
225
should be applicable to every other backend choice.
257
226
258
227
The way to get hold of those is using using npm or perhaps Yarn as with other packages.
@@ -275,20 +244,20 @@ with a solution proposed to fix complications should they arise.
275
244
> Info
276
245
> Alternatively, you can find this file in the plugins repository doc folder: `doc/i18next.d.ts`
277
246
278
-
As for the XHR-Backend you'll be using:
247
+
As for the HTTP-Backend you'll be using:
279
248
280
249
```Shell
281
-
npm install -D @types/i18next-xhr-backend
250
+
npm install -D @types/i18next-http-backend
282
251
```
283
252
284
253
or for yarn
285
254
286
255
```Shell
287
-
yarn add -D @types/i18next-xhr-backend
256
+
yarn add -D @types/i18next-http-backend
288
257
```
289
258
290
259
> Info
291
-
> Alternative, you can find this file in the plugins repository doc folder: `doc/i18next-xhr-backend.d.ts`
260
+
> Alternative, you can find this file in the plugins repository doc folder: `doc/i18next-http-backend.d.ts`
292
261
293
262
Note: if you decide to use the `doc/*.d.ts` files, you should copy them to another folder, e.g. `custom_typings`.
294
263
@@ -313,13 +282,13 @@ or if you are using TypeScript 2.0 or later, you can add them to the types secti
313
282
314
283
```JavaScript Configuring custom typings in tsconfig.json
315
284
... existing configuration code
316
-
"types": [ "i18next", "i18next-xhr-backend" ]
285
+
"types": [ "i18next", "i18next-http-backend" ]
317
286
],
318
287
... other existing configuration code
319
288
```
320
289
321
290
> Warning
322
-
> TypeScript will throw errors like `Module xxx not found` either for aurelia-i18n or one of the backends. This is due to the fact that TypeScript does not see proper ES6 exported defaults. So you can now either switch to alias imports `import * as Backend from 'i18next-xhr-backend'` or update your tsconfig with `"allowSyntheticDefaultImports": true` to maintain the same import style.
291
+
> TypeScript will throw errors like `Module xxx not found` either for aurelia-i18n or one of the backends. This is due to the fact that TypeScript does not see proper ES6 exported defaults. So you can now either switch to alias imports `import * as Backend from 'i18next-http-backend'` or update your tsconfig with `"allowSyntheticDefaultImports": true` to maintain the same import style.
0 commit comments