Skip to content

Commit 9cba375

Browse files
doc(i18n): Update 4. i18n.md for deprecated i18next-xhr-backend (#490)
Replaced deprecated i18next-xhr-backend with i18next-http-backend. #i18n/357
1 parent 57c8416 commit 9cba375

File tree

1 file changed

+24
-55
lines changed

1 file changed

+24
-55
lines changed

current/en-us/7. plugins/4. i18n.md

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Aurelia-I18N is tested and optimized to support both JS and TS, as well as the f
2626
* Webpack
2727

2828
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),
3030
or a variation of this plugin — `aurelia-i18n-loader` — that uses the aurelia loader, which is bundled with the aurelia-i18n plugin.
3131
We'll discuss TypeScript specifics in a later section.
3232

@@ -38,11 +38,11 @@ In order to install the Plugin with a CLI Project, first install the plugin via
3838
npm install aurelia-i18n
3939
```
4040

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:
4343

4444
```Shell
45-
npm install i18next i18next-xhr-backend
45+
npm install i18next i18next-http-backend
4646
```
4747

4848
### JSPM
@@ -56,7 +56,7 @@ jspm install aurelia-i18n
5656
And optionally install the backend service using:
5757

5858
```Shell
59-
jspm install npm:i18next-xhr-backend
59+
jspm install npm:i18next-http-backend
6060
```
6161

6262
> Info
@@ -76,16 +76,16 @@ or if you prefer yarn
7676
yarn add aurelia-i18n
7777
```
7878

79-
Also optionally install the `i18next-xhr-backend` plugin:
79+
Also optionally install the `i18next-http-backend` plugin:
8080

8181
```Shell
82-
npm install i18next-xhr-backend
82+
npm install i18next-http-backend
8383
```
8484

8585
or using yarn
8686

8787
```Shell
88-
yarn add i18next-xhr-backend
88+
yarn add i18next-http-backend
8989
```
9090

9191
> Info
@@ -137,50 +137,19 @@ Fourth, in those subfolders create a file named `translation.json` which contain
137137
}
138138
```
139139

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+
142143

143144
> Info
144145
> 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.
145146
146-
```JavaScript Registering the Plugin - using the built-in aurelia loader backed
147-
import {I18N, Backend, TCustomAttribute} from 'aurelia-i18n';
148-
149-
export function configure(aurelia) {
150-
aurelia.use
151-
.standardConfiguration()
152-
.developmentLogging()
153-
.plugin('aurelia-i18n', (instance) => {
154-
let aliases = ['t', 'i18n'];
155-
// add aliases for 't' attribute
156-
TCustomAttribute.configureAliases(aliases);
157-
158-
// register backend plugin
159-
instance.i18next.use(Backend.with(aurelia.loader));
160-
161-
// adapt options to your needs (see https://i18next.com/docs/options/)
162-
// make sure to return the promise of the setup method, in order to guarantee proper loading
163-
return instance.setup({
164-
backend: { // <-- configure backend settings
165-
loadPath: './locales/{{lng}}/{{ns}}.json', // <-- XHR settings for where to get the files from
166-
},
167-
attributes: aliases,
168-
lng : 'de',
169-
fallbackLng : 'en',
170-
debug : false
171-
});
172-
});
173-
174-
aurelia.start().then(a => a.setRoot());
175-
}
176-
```
177-
178-
```JavaScript Registering the Plugin - using the i18next-xhr-backend
147+
```JavaScript Registering the Plugin - using the i18next-http-backend
179148
import {I18N, TCustomAttribute} from 'aurelia-i18n';
180-
import Backend from 'i18next-xhr-backend'; // <-- your previously installed backend plugin
149+
import Backend from 'i18next-http-backend'; // <-- your previously installed backend plugin
181150

182151
// 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';
184153
// otherwise add "allowSyntheticDefaultImports": true, to your tsconfig
185154

186155
export function configure(aurelia) {
@@ -199,7 +168,7 @@ export function configure(aurelia) {
199168
// make sure to return the promise of the setup method, in order to guarantee proper loading
200169
return instance.setup({
201170
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
203172
},
204173
attributes: aliases,
205174
lng : 'de',
@@ -212,9 +181,9 @@ export function configure(aurelia) {
212181
}
213182
```
214183

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`.
216185

217-
```JavaScript Copy translation files for webpack and i18next-xhr-backend
186+
```JavaScript Copy translation files for webpack and i18next-http-backend
218187
plugins: [
219188
// ...
220189
new CopyWebpackPlugin([
@@ -252,7 +221,7 @@ If you are using [`reflect-metadata`](https://www.npmjs.com/package/reflect-meta
252221

253222
In order to get proper support for autocompletion and typesafety you should install
254223
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
256225
should be applicable to every other backend choice.
257226

258227
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.
275244
> Info
276245
> Alternatively, you can find this file in the plugins repository doc folder: `doc/i18next.d.ts`
277246
278-
As for the XHR-Backend you'll be using:
247+
As for the HTTP-Backend you'll be using:
279248

280249
```Shell
281-
npm install -D @types/i18next-xhr-backend
250+
npm install -D @types/i18next-http-backend
282251
```
283252

284253
or for yarn
285254

286255
```Shell
287-
yarn add -D @types/i18next-xhr-backend
256+
yarn add -D @types/i18next-http-backend
288257
```
289258

290259
> 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`
292261
293262
Note: if you decide to use the `doc/*.d.ts` files, you should copy them to another folder, e.g. `custom_typings`.
294263

@@ -313,13 +282,13 @@ or if you are using TypeScript 2.0 or later, you can add them to the types secti
313282

314283
```JavaScript Configuring custom typings in tsconfig.json
315284
... existing configuration code
316-
"types": [ "i18next", "i18next-xhr-backend" ]
285+
"types": [ "i18next", "i18next-http-backend" ]
317286
],
318287
... other existing configuration code
319288
```
320289

321290
> 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.
323292
324293
## Using the Plugin
325294

0 commit comments

Comments
 (0)