i18next-xhr-backend
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "i18next-xhr-backend", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "backend layer for i18next using browsers xhr", | ||
"main": "./bin/index.js", | ||
"main": "./lib/index.js", | ||
"keywords": [ | ||
@@ -18,7 +18,7 @@ "i18next", | ||
"brfs": "1.4.2", | ||
"browserify": "12.0.1", | ||
"browserify": "12.0.2", | ||
"browserify-istanbul": "0.2.1", | ||
"chai": "2.3.0", | ||
"coveralls": "2.11.6", | ||
"eslint": "1.2.1", | ||
"eslint": "1.10.3", | ||
"gulp": "3.9.0", | ||
@@ -37,3 +37,3 @@ "gulp-babel": "5.2.1", | ||
"gulp-uglify": "1.5.1", | ||
"i18next": "2.0.18", | ||
"i18next": "2.1.0", | ||
"istanbul": "gotwarlost/istanbul#source-map", | ||
@@ -58,3 +58,3 @@ "json5": "0.4.0", | ||
"vinyl-source-stream": "1.1.0", | ||
"watchify": "3.6.1", | ||
"watchify": "3.7.0", | ||
"yargs": "3.31.0" | ||
@@ -61,0 +61,0 @@ }, |
@@ -55,3 +55,3 @@ # Introduction | ||
parse: function(data) { return data.replace(/a/g, ''); }, | ||
// allow cross domain requests | ||
@@ -95,1 +95,32 @@ crossDomain: false, | ||
``` | ||
### Usage with webpack | ||
To use with webpack, install [bundle-loader](https://github.com/webpack/bundle-loader) and [json-loader](https://github.com/webpack/json-loader). | ||
Define a custom xhr function, webpack's bundle loader will load the translations for you. | ||
```js | ||
function loadLocales(url, options, callback, data) { | ||
try { | ||
let waitForLocale = require('bundle!./locales/'+url+'.json'); | ||
waitForLocale((locale) => { | ||
callback(locale, {status: '200'}); | ||
}) | ||
} catch (e) { | ||
callback(null, {status: '404'}); | ||
} | ||
} | ||
i18next | ||
.use(XHR) | ||
.init({ | ||
backend: { | ||
loadPath: '{{lng}}', | ||
parse: (data) => data, | ||
ajax: loadLocales | ||
} | ||
}, (err, t) => { | ||
// ... | ||
}); | ||
``` |
23856
125