load remote translations
This commit is contained in:
@@ -3,4 +3,6 @@ rem This bat file minifies all js and css and creates a dist folder with everyth
|
||||
node node_modules\minifyfromhtml\minifyfromhtml.js --js=dist\myapp.js --css=dist\myapp.css < index.html
|
||||
|
||||
copy /Y index.production.html dist\index.html
|
||||
copy /Y favicon.ico dist\favicon.ico
|
||||
xcopy /F /Y /I templates dist\templates
|
||||
xcopy /F /Y /I i18n dist\i18n
|
||||
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
4
i18n/de.json
Normal file
4
i18n/de.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"vanillaJS": "vanillaJS Beispiel Projekt",
|
||||
"awesome": "Coole app."
|
||||
}
|
4
i18n/en.json
Normal file
4
i18n/en.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"vanillaJS": "vanillaJS seed project",
|
||||
"awesome": "This is an awesome app!"
|
||||
}
|
4
i18n/it.json
Normal file
4
i18n/it.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"vanillaJS": "progetto di esempio vanillaJS",
|
||||
"awesome": "Questa app è fantastica!"
|
||||
}
|
15
index.html
15
index.html
@@ -4,7 +4,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
|
||||
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css" type="text/css" />
|
||||
<link rel="stylesheet" href="node_modules/pnotify/dist/PNotifyBrightTheme.css" type="text/css" />
|
||||
<link rel="stylesheet" href="css/styles.css" type="text/css" />
|
||||
</head>
|
||||
@@ -12,15 +12,16 @@
|
||||
<div class="js-main-content"></div>
|
||||
|
||||
<script type="text/javascript" src="js/polyfills.js"></script>
|
||||
<script type="text/javascript" src="node_modules/es6-promise/dist/es6-promise.auto.min.js"></script>
|
||||
<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="node_modules/i18next/i18next.min.js"></script>
|
||||
<script type="text/javascript" src="node_modules/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.min.js"></script>
|
||||
<script type="text/javascript" src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="node_modules/es6-promise/dist/es6-promise.auto.js"></script>
|
||||
<script type="text/javascript" src="node_modules/jquery/dist/jquery.js"></script>
|
||||
<script type="text/javascript" src="node_modules/i18next/i18next.js"></script>
|
||||
<script type="text/javascript" src="node_modules/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.js"></script>
|
||||
<script type="text/javascript" src="node_modules/i18next-xhr-backend/i18nextXHRBackend.js"></script>
|
||||
<script type="text/javascript" src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
|
||||
<script type="text/javascript" src="node_modules/pnotify/dist/iife/PNotify.js"></script>
|
||||
<script type="text/javascript" src="node_modules/pnotify/dist/iife/PNotifyButtons.js"></script>
|
||||
<script type="text/javascript" src="node_modules/page/page.js"></script>
|
||||
<script type="text/javascript" src="node_modules/ejs/ejs.min.js"></script>
|
||||
<script type="text/javascript" src="node_modules/ejs/ejs.js"></script>
|
||||
<script type="text/javascript" src="node_modules/ejs-render-remote/ejs-render-remote.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/config.js"></script>
|
||||
|
25
js/index.js
25
js/index.js
@@ -84,6 +84,7 @@
|
||||
// set language
|
||||
i18next
|
||||
.use(i18nextBrowserLanguageDetector)
|
||||
.use(i18nextXHRBackend)
|
||||
.init({
|
||||
detection: {
|
||||
order: ['querystring', 'cookie', 'navigator'],
|
||||
@@ -94,26 +95,9 @@
|
||||
},
|
||||
whitelist: ['en', 'de', 'it'],
|
||||
nonExplicitWhitelist: true,
|
||||
fallbackLng: 'en',
|
||||
resources: {
|
||||
en: {
|
||||
translation: {
|
||||
'vanillaJS': 'vanillaJS seed project',
|
||||
'awesome': 'This is an awesome app!'
|
||||
}
|
||||
},
|
||||
it: {
|
||||
translation: {
|
||||
'vanillaJS': 'progetto di esempio vanillaJS',
|
||||
'awesome': 'Questa app è fantastica!'
|
||||
}
|
||||
},
|
||||
de: {
|
||||
translation: {
|
||||
'vanillaJS': 'vanillaJS Beispiel Projekt',
|
||||
'awesome': 'Coole app.'
|
||||
}
|
||||
}
|
||||
fallbackLng: 'it',
|
||||
backend: {
|
||||
loadPath: '/i18n/{{lng}}.json'
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
@@ -124,6 +108,7 @@
|
||||
//removeURLParameter does not return the hash. add it back if there is one.
|
||||
newUrl = newUrl + window.location.hash;
|
||||
window.location = newUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
// render main shell
|
||||
|
1
node_modules/i18next-xhr-backend/.coveralls.yml
generated
vendored
Normal file
1
node_modules/i18next-xhr-backend/.coveralls.yml
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
repo_token: 95SiHydOTG99ngOBBMnlRSl28IgE9kAah
|
6
node_modules/i18next-xhr-backend/.travis.yml
generated
vendored
Normal file
6
node_modules/i18next-xhr-backend/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6.2"
|
||||
before_script:
|
||||
- npm install -g gulp
|
||||
- npm install -g karma
|
53
node_modules/i18next-xhr-backend/CHANGELOG.md
generated
vendored
Normal file
53
node_modules/i18next-xhr-backend/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
### 2.0.1
|
||||
|
||||
- typescript: fix types [298](https://github.com/i18next/i18next-xhr-backend/pull/298)
|
||||
|
||||
### 2.0.0
|
||||
|
||||
- typescript: add types
|
||||
|
||||
### 1.5.1
|
||||
|
||||
- fixes add path to use `/locales/...`
|
||||
|
||||
### 1.5.0
|
||||
|
||||
- add .js for browser import implementation [PR268](https://github.com/i18next/i18next-xhr-backend/pull/268)
|
||||
|
||||
### 1.4.3
|
||||
|
||||
- Fix XML parsing error in Firefox [PR265](https://github.com/i18next/i18next-xhr-backend/pull/265)
|
||||
|
||||
### 1.4.2
|
||||
|
||||
- usage with sinon [260](https://github.com/i18next/i18next-xhr-backend/pull/260)
|
||||
|
||||
### 1.4.1
|
||||
|
||||
- fixes ajax
|
||||
|
||||
### 1.4.0
|
||||
|
||||
- add `queryStringParams` option [PR255](https://github.com/i18next/i18next-xhr-backend/pull/255)
|
||||
|
||||
### 1.3.0
|
||||
|
||||
- add support for custom headers [PR250](https://github.com/i18next/i18next-xhr-backend/pull/250)
|
||||
- update dev dependencies
|
||||
|
||||
### 1.2.1
|
||||
|
||||
- downgrade babel-preset-es2015-native-modules to correctly build es files
|
||||
|
||||
### 1.2.0
|
||||
|
||||
- support withCredentials flag on XHR [PR238](https://github.com/i18next/i18next-xhr-backend/pull/238)
|
||||
|
||||
### 1.1.0
|
||||
|
||||
- allows loadPath to be a function [PR236](https://github.com/i18next/i18next-xhr-backend/pull/236)
|
||||
|
||||
### 1.0.1
|
||||
|
||||
- change amd export to unnamed
|
||||
- initial v1
|
22
node_modules/i18next-xhr-backend/LICENSE
generated
vendored
Normal file
22
node_modules/i18next-xhr-backend/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 i18next
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
172
node_modules/i18next-xhr-backend/README.md
generated
vendored
Normal file
172
node_modules/i18next-xhr-backend/README.md
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
# Introduction
|
||||
|
||||
[](https://travis-ci.org/i18next/i18next-xhr-backend)
|
||||
[](https://coveralls.io/github/i18next/i18next-xhr-backend)
|
||||
[](https://www.npmjs.com/package/i18next-xhr-backend)
|
||||
[]()
|
||||
[](https://david-dm.org/i18next/i18next-xhr-backend)
|
||||
|
||||
This is a simple i18next backend to be used in the browser. It will load resources from a backend server using xhr.
|
||||
|
||||
# Getting started
|
||||
|
||||
Source can be loaded via [npm](https://www.npmjs.com/package/i18next-xhr-backend), bower or [downloaded](https://github.com/i18next/i18next-xhr-backend/blob/master/i18nextXHRBackend.min.js) from this repo.
|
||||
|
||||
```
|
||||
# npm package
|
||||
$ npm install i18next-xhr-backend
|
||||
|
||||
# bower
|
||||
$ bower install i18next-xhr-backend
|
||||
```
|
||||
|
||||
Wiring up:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
|
||||
i18next
|
||||
.use(XHR)
|
||||
.init(i18nextOptions);
|
||||
```
|
||||
|
||||
- As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
|
||||
- If you don't use a module loader it will be added to `window.i18nextXHRBackend`
|
||||
|
||||
## Backend Options
|
||||
|
||||
```js
|
||||
{
|
||||
// path where resources get loaded from, or a function
|
||||
// returning a path:
|
||||
// function(lngs, namespaces) { return customPath; }
|
||||
// the returned path will interpolate lng, ns if provided like giving a static path
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
|
||||
// path to post missing resources
|
||||
addPath: 'locales/add/{{lng}}/{{ns}}',
|
||||
|
||||
// your backend server supports multiloading
|
||||
// /locales/resources.json?lng=de+en&ns=ns1+ns2
|
||||
// Adapter is needed to enable MultiLoading https://github.com/i18next/i18next-multiload-backend-adapter
|
||||
// Returned JSON structure in this case is
|
||||
// {
|
||||
// lang : {
|
||||
// namespaceA: {},
|
||||
// namespaceB: {},
|
||||
// ...etc
|
||||
// }
|
||||
// }
|
||||
allowMultiLoading: false, // set loadPath: '/locales/resources.json?lng={{lng}}&ns={{ns}}' to adapt to multiLoading
|
||||
|
||||
// parse data after it has been fetched
|
||||
// in example use https://www.npmjs.com/package/json5
|
||||
// here it removes the letter a from the json (bad idea)
|
||||
parse: function(data) { return data.replace(/a/g, ''); },
|
||||
|
||||
// allow cross domain requests
|
||||
crossDomain: false,
|
||||
|
||||
// allow credentials on cross domain requests
|
||||
withCredentials: false,
|
||||
|
||||
// define a custom xhr function
|
||||
// can be used to support XDomainRequest in IE 8 and 9
|
||||
//
|
||||
// 'url' will be passed the value of 'loadPath'
|
||||
// 'options' will be this entire options object
|
||||
// 'callback' is a function that takes two parameters, 'data' and 'xhr'.
|
||||
// 'data' should be the key:value translation pairs for the
|
||||
// requested language and namespace, or null in case of an error.
|
||||
// 'xhr' should be a status object, e.g. { status: 200 }
|
||||
// 'data' will be a key:value object used when saving missing translations
|
||||
ajax: function (url, options, callback, data) {},
|
||||
|
||||
// adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
queryStringParams: { v: '1.3.5' }
|
||||
}
|
||||
```
|
||||
|
||||
Options can be passed in:
|
||||
|
||||
**preferred** - by setting options.backend in i18next.init:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
|
||||
i18next
|
||||
.use(XHR)
|
||||
.init({
|
||||
backend: options
|
||||
});
|
||||
```
|
||||
|
||||
on construction:
|
||||
|
||||
```js
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
const xhr = new XHR(null, options);
|
||||
```
|
||||
|
||||
via calling init:
|
||||
|
||||
```js
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
const xhr = new XHR();
|
||||
xhr.init(null, options);
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
#### Usage with webpack's bundle loader instead of using xhr requests
|
||||
|
||||
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) => {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
#### TypeScript definitions
|
||||
|
||||
- Install from `@types` (for TypeScript v2 and later):
|
||||
|
||||
npm install --save-dev @types/i18next-xhr-backend
|
||||
|
||||
- Install from `typings`:
|
||||
|
||||
typings install --save --global dt~i18next-xhr-backend
|
||||
|
||||
--------------
|
||||
|
||||
<h3 align="center">Gold Sponsors</h3>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://locize.com/" target="_blank">
|
||||
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px">
|
||||
</a>
|
||||
</p>
|
198
node_modules/i18next-xhr-backend/i18nextXHRBackend.js
generated
vendored
Normal file
198
node_modules/i18next-xhr-backend/i18nextXHRBackend.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.i18nextXHRBackend = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent;
|
||||
|
||||
// Must encode data
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// https://gist.github.com/Xeoncross/7663273
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
|
||||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
}
|
||||
// URL encoded form data must be in querystring format
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
var h = options.customHeaders;
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: 'init',
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: 'readMulti',
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: languages.join('+'), ns: namespaces.join('+') });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'read',
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: language, ns: namespace });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'loadUrl',
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true /* retry */);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false /* no retry */);
|
||||
|
||||
var ret = void 0,
|
||||
err = void 0;
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'create',
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
|
||||
var payload = {};
|
||||
payload[key] = fallbackValue || '';
|
||||
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { lng: lng, ns: namespace });
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {
|
||||
//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
return Backend;
|
||||
|
||||
})));
|
1
node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js
generated
vendored
Normal file
1
node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.i18nextXHRBackend=e()}(this,function(){"use strict";function t(t){return r.call(s.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t}function e(t,e){if(e&&"object"===(void 0===e?"undefined":l(e))){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function n(t,n,o,i,a){i&&"object"===(void 0===i?"undefined":l(i))&&(a||(i._t=new Date),i=e("",i).slice(1)),n.queryStringParams&&(t=e(t,n.queryStringParams));try{var r;r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0"),r.open(i?"POST":"GET",t,1),n.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!n.withCredentials,i&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var s=n.customHeaders;if(s)for(var u in s)r.setRequestHeader(u,s[u]);r.onreadystatechange=function(){r.readyState>3&&o&&o(r.responseText,r)},r.send(i)}catch(t){console&&console.log(t)}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:n}}var a=[],r=a.forEach,s=a.slice,l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.init(t,n),this.type="backend"}return u(e,[{key:"init",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=e,this.options=t(n,this.options||{},i())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var a=void 0,r=void 0;try{a=n.options.parse(o,t)}catch(e){r="failed parsing "+t+" to json"}if(r)return e(r,!1);e(null,a)})}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var a={};a[n]=o||"",t.forEach(function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,function(t,e){},a)})}}]),e}();return c.type="backend",c});
|
67
node_modules/i18next-xhr-backend/index.d.ts
generated
vendored
Normal file
67
node_modules/i18next-xhr-backend/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
declare namespace I18NextXhrBackend {
|
||||
type LoadPathOption = string | ((lngs: string[], namespaces: string[]) => string);
|
||||
|
||||
interface BackendOptions {
|
||||
/**
|
||||
* path where resources get loaded from, or a function
|
||||
* returning a path:
|
||||
* function(lngs, namespaces) { return customPath; }
|
||||
* the returned path will interpolate lng, ns if provided like giving a static path
|
||||
*/
|
||||
loadPath?: LoadPathOption;
|
||||
/**
|
||||
* path to post missing resources
|
||||
*/
|
||||
addPath?: string;
|
||||
/**
|
||||
* your backend server supports multiLoading
|
||||
* locales/resources.json?lng=de+en&ns=ns1+ns2
|
||||
* set loadPath: '/locales/resources.json?lng={{lng}}&ns={{ns}}' to adapt to multiLoading
|
||||
*/
|
||||
allowMultiLoading?: boolean;
|
||||
/**
|
||||
* parse data after it has been fetched
|
||||
* in example use https://www.npmjs.com/package/json5
|
||||
* here it removes the letter a from the json (bad idea)
|
||||
*/
|
||||
parse?(data: string): string;
|
||||
/**
|
||||
* allow cross domain requests
|
||||
*/
|
||||
crossDomain?: boolean;
|
||||
/**
|
||||
* allow credentials on cross domain requests
|
||||
*/
|
||||
withCredentials?: boolean;
|
||||
/**
|
||||
* define a custom xhr function
|
||||
* can be used to support XDomainRequest in IE 8 and 9
|
||||
*/
|
||||
ajax?(url: string, options: BackendOptions, callback: AjaxRequestCallback, data: {} | string, cache: boolean): void;
|
||||
/**
|
||||
* adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
*/
|
||||
queryStringParams?: { [key: string]: string };
|
||||
|
||||
/**
|
||||
* @see https://github.com/i18next/i18next-xhr-backend/blob/281c7e235e1157b33122adacef1957252e5700f1/src/ajax.js#L52
|
||||
*/
|
||||
customHeaders?: { [key: string]: string };
|
||||
}
|
||||
|
||||
type AjaxRequestCallback = (response: string, x: XMLHttpRequest) => void;
|
||||
|
||||
type LoadCallback = (error: any, result: string | false) => void;
|
||||
}
|
||||
|
||||
export default class I18NextXhrBackend {
|
||||
constructor(services?: any, options?: I18NextXhrBackend.BackendOptions);
|
||||
init(services?: any, options?: I18NextXhrBackend.BackendOptions): void;
|
||||
readMulti(languages: string[], namespaces: string[], callback: I18NextXhrBackend.LoadCallback): void;
|
||||
read(language: string, namespace: string, callback: I18NextXhrBackend.LoadCallback): void;
|
||||
loadUrl(url: string, callback: I18NextXhrBackend.LoadCallback): void;
|
||||
create(languages: string | string[], namespace: string, key: string, fallbackValue: string): void;
|
||||
type: "backend";
|
||||
services: any;
|
||||
options: I18NextXhrBackend.BackendOptions;
|
||||
}
|
5
node_modules/i18next-xhr-backend/index.js
generated
vendored
Normal file
5
node_modules/i18next-xhr-backend/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/* eslint no-var: 0 */
|
||||
var main = require('./dist/commonjs/index.js').default;
|
||||
|
||||
module.exports = main;
|
||||
module.exports.default = main;
|
116
node_modules/i18next-xhr-backend/package.json
generated
vendored
Normal file
116
node_modules/i18next-xhr-backend/package.json
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"_from": "i18next-xhr-backend",
|
||||
"_id": "i18next-xhr-backend@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-CP0XPjJsTE4hY1rM1KXFYo63Ib61EBLEcTvMDyJwr0vs9p/UTuA3ENCmzSs9+ghZgWSjdOigc0oUERHaxctbsQ==",
|
||||
"_location": "/i18next-xhr-backend",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "i18next-xhr-backend",
|
||||
"name": "i18next-xhr-backend",
|
||||
"escapedName": "i18next-xhr-backend",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/i18next-xhr-backend/-/i18next-xhr-backend-2.0.1.tgz",
|
||||
"_shasum": "7af735ee1b0c6d4ce49fa5756591040a0fba6db7",
|
||||
"_spec": "i18next-xhr-backend",
|
||||
"_where": "F:\\projects\\vanillajs-seed",
|
||||
"author": {
|
||||
"name": "Jan Mühlemann",
|
||||
"email": "jan.muehlemann@gmail.com",
|
||||
"url": "https://github.com/jamuhl"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/i18next/i18next-xhr-backend/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "backend layer for i18next using browsers xhr",
|
||||
"devDependencies": {
|
||||
"babel-cli": "6.18.0",
|
||||
"babel-core": "6.21.0",
|
||||
"babel-eslint": "7.1.1",
|
||||
"babel-preset-es2015": "6.18.0",
|
||||
"babel-preset-stage-0": "6.16.0",
|
||||
"babelify": "7.3.0",
|
||||
"browserify": "13.3.0",
|
||||
"browserify-istanbul": "2.0.0",
|
||||
"chai": "3.5.0",
|
||||
"coveralls": "2.11.15",
|
||||
"dtslint": "^0.4.2",
|
||||
"eslint": "3.13.0",
|
||||
"eslint-config-airbnb": "13.0.0",
|
||||
"i18next": "4.1.4",
|
||||
"istanbul": "github:gotwarlost/istanbul#source-map",
|
||||
"json5": "0.5.1",
|
||||
"karma": "1.3.0",
|
||||
"karma-browserify": "5.1.0",
|
||||
"karma-chai": "0.1.0",
|
||||
"karma-chrome-launcher": "2.0.0",
|
||||
"karma-cli": "1.0.1",
|
||||
"karma-coverage": "github:douglasduteil/karma-coverage#next",
|
||||
"karma-coveralls": "1.1.2",
|
||||
"karma-expect": "1.1.3",
|
||||
"karma-mocha": "1.3.0",
|
||||
"karma-phantomjs-launcher": "1.0.2",
|
||||
"karma-rollup-preprocessor": "3.0.3",
|
||||
"karma-sinon": "1.0.5",
|
||||
"karma-spec-reporter": "0.0.26",
|
||||
"mkdirp": "0.5.1",
|
||||
"mocha": "3.2.0",
|
||||
"phantomjs-prebuilt": "2.1.14",
|
||||
"rimraf": "2.5.4",
|
||||
"rollup": "0.41.1",
|
||||
"rollup-plugin-babel": "2.7.1",
|
||||
"rollup-plugin-node-resolve": "2.0.0",
|
||||
"rollup-plugin-uglify": "1.0.1",
|
||||
"sinon": "1.17.7",
|
||||
"tslint": "^5.12.1",
|
||||
"typescript": "^3.3.1",
|
||||
"yargs": "6.6.0"
|
||||
},
|
||||
"homepage": "https://github.com/i18next/i18next-xhr-backend",
|
||||
"jsnext:main": "dist/es/index.js",
|
||||
"keywords": [
|
||||
"i18next",
|
||||
"i18next-backend"
|
||||
],
|
||||
"license": "MIT",
|
||||
"lock": false,
|
||||
"main": "./index.js",
|
||||
"name": "i18next-xhr-backend",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/i18next/i18next-xhr-backend.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:umd && npm run copy",
|
||||
"build-win": "npm run clean && npm run build:cjs && npm run build:es-win && npm run build:umd && npm run copy-win",
|
||||
"build:amd": "rollup -c rollup.config.js --format amd && rollup -c rollup.config.js --format umd --uglify",
|
||||
"build:cjs": "babel src --out-dir dist/commonjs",
|
||||
"build:es": "BABEL_ENV=jsnext babel src --out-dir dist/es",
|
||||
"build:es-win": "SET BABEL_ENV=jsnext babel src --out-dir dist/es",
|
||||
"build:iife": "rollup -c rollup.config.js --format iife && rollup -c rollup.config.js --format iife --uglify",
|
||||
"build:umd": "rollup -c rollup.config.js --format umd && rollup -c rollup.config.js --format umd --uglify",
|
||||
"clean": "rimraf dist && mkdirp dist",
|
||||
"copy": "cp ./dist/umd/i18nextXHRBackend.min.js ./i18nextXHRBackend.min.js && cp ./dist/umd/i18nextXHRBackend.js ./i18nextXHRBackend.js",
|
||||
"copy-win": "xcopy .\\dist\\umd\\i18nextXHRBackend.min.js .\\i18nextXHRBackend.min.js /y && xcopy .\\dist\\umd\\i18nextXHRBackend.js .\\i18nextXHRBackend.js /y",
|
||||
"postversion": "git push && git push --tags",
|
||||
"pretest": "npm run test:typescript",
|
||||
"preversion": "npm run test && npm run build && git push",
|
||||
"tdd": "karma start karma.conf.js",
|
||||
"test": "karma start karma.conf.js --singleRun",
|
||||
"test:typescript": "tslint --project tsconfig.json"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"version": "2.0.1"
|
||||
}
|
31
node_modules/i18next-xhr-backend/rollup.config.js
generated
vendored
Normal file
31
node_modules/i18next-xhr-backend/rollup.config.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import babel from 'rollup-plugin-babel';
|
||||
import uglify from 'rollup-plugin-uglify';
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import { argv } from 'yargs';
|
||||
|
||||
const format = argv.format || argv.f || 'iife';
|
||||
const compress = argv.uglify;
|
||||
|
||||
const babelOptions = {
|
||||
exclude: 'node_modules/**',
|
||||
presets: [['es2015', { modules: false }], 'stage-0'],
|
||||
babelrc: false
|
||||
};
|
||||
|
||||
const dest = {
|
||||
amd: `dist/amd/i18nextXHRBackend${compress ? '.min' : ''}.js`,
|
||||
umd: `dist/umd/i18nextXHRBackend${compress ? '.min' : ''}.js`,
|
||||
iife: `dist/iife/i18nextXHRBackend${compress ? '.min' : ''}.js`
|
||||
}[format];
|
||||
|
||||
export default {
|
||||
entry: 'src/index.js',
|
||||
format,
|
||||
plugins: [
|
||||
babel(babelOptions),
|
||||
nodeResolve({ jsnext: true })
|
||||
].concat(compress ? uglify() : []),
|
||||
moduleName: 'i18nextXHRBackend',
|
||||
//moduleId: 'i18nextXHRBackend',
|
||||
dest
|
||||
};
|
15
node_modules/i18next-xhr-backend/tsconfig.json
generated
vendored
Normal file
15
node_modules/i18next-xhr-backend/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": ["es6", "dom"],
|
||||
"jsx": "react",
|
||||
"moduleResolution": "node",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"baseUrl": ".",
|
||||
"paths": { "i18next-xhr-backend": ["./index.d.ts"] }
|
||||
},
|
||||
"include": ["./indext.d.ts", "./test/**/*.ts*"]
|
||||
}
|
7
node_modules/i18next-xhr-backend/tslint.json
generated
vendored
Normal file
7
node_modules/i18next-xhr-backend/tslint.json
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": "dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"semicolon": false
|
||||
}
|
||||
}
|
5
package-lock.json
generated
5
package-lock.json
generated
@@ -422,6 +422,11 @@
|
||||
"resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-3.0.1.tgz",
|
||||
"integrity": "sha512-WFjPLNPWl62uu07AHY2g+KsC9qz0tyMq+OZEB/H7N58YKL/JLiCz9U709gaR20Mule/Ppn+uyfVx5REJJjn1HA=="
|
||||
},
|
||||
"i18next-xhr-backend": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/i18next-xhr-backend/-/i18next-xhr-backend-2.0.1.tgz",
|
||||
"integrity": "sha512-CP0XPjJsTE4hY1rM1KXFYo63Ib61EBLEcTvMDyJwr0vs9p/UTuA3ENCmzSs9+ghZgWSjdOigc0oUERHaxctbsQ=="
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
|
@@ -15,6 +15,7 @@
|
||||
"es6-promise": "^4.2.6",
|
||||
"i18next": "^15.0.9",
|
||||
"i18next-browser-languagedetector": "^3.0.1",
|
||||
"i18next-xhr-backend": "^2.0.1",
|
||||
"jquery": "^3.4.0",
|
||||
"page": "^1.11.4",
|
||||
"pnotify": "^4.0.0-beta.2",
|
||||
|
Reference in New Issue
Block a user