From f4fb72f363434ec3b36c0eedda714ac874166605 Mon Sep 17 00:00:00 2001 From: s2 Date: Tue, 16 Apr 2019 09:02:57 +0200 Subject: [PATCH] load remote translations --- build.cmd | 2 + favicon.ico | Bin 0 -> 1150 bytes i18n/de.json | 4 + i18n/en.json | 4 + i18n/it.json | 4 + index.html | 15 +- js/index.js | 25 +-- .../i18next-xhr-backend/.coveralls.yml | 1 + node_modules/i18next-xhr-backend/.travis.yml | 6 + node_modules/i18next-xhr-backend/CHANGELOG.md | 53 +++++ node_modules/i18next-xhr-backend/LICENSE | 22 ++ node_modules/i18next-xhr-backend/README.md | 172 +++++++++++++++ .../i18next-xhr-backend/i18nextXHRBackend.js | 198 ++++++++++++++++++ .../i18nextXHRBackend.min.js | 1 + node_modules/i18next-xhr-backend/index.d.ts | 67 ++++++ node_modules/i18next-xhr-backend/index.js | 5 + node_modules/i18next-xhr-backend/package.json | 116 ++++++++++ .../i18next-xhr-backend/rollup.config.js | 31 +++ .../i18next-xhr-backend/tsconfig.json | 15 ++ node_modules/i18next-xhr-backend/tslint.json | 7 + package-lock.json | 5 + package.json | 1 + 22 files changed, 727 insertions(+), 27 deletions(-) create mode 100644 favicon.ico create mode 100644 i18n/de.json create mode 100644 i18n/en.json create mode 100644 i18n/it.json create mode 100644 node_modules/i18next-xhr-backend/.coveralls.yml create mode 100644 node_modules/i18next-xhr-backend/.travis.yml create mode 100644 node_modules/i18next-xhr-backend/CHANGELOG.md create mode 100644 node_modules/i18next-xhr-backend/LICENSE create mode 100644 node_modules/i18next-xhr-backend/README.md create mode 100644 node_modules/i18next-xhr-backend/i18nextXHRBackend.js create mode 100644 node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js create mode 100644 node_modules/i18next-xhr-backend/index.d.ts create mode 100644 node_modules/i18next-xhr-backend/index.js create mode 100644 node_modules/i18next-xhr-backend/package.json create mode 100644 node_modules/i18next-xhr-backend/rollup.config.js create mode 100644 node_modules/i18next-xhr-backend/tsconfig.json create mode 100644 node_modules/i18next-xhr-backend/tslint.json diff --git a/build.cmd b/build.cmd index 9113b87..aeb4645 100644 --- a/build.cmd +++ b/build.cmd @@ -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 diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..0e42825b97d7eec61727ab42401709fbbd0b0149 GIT binary patch literal 1150 zcmZ`&Ye-XJ7=E{jn``APSIj6ZhOXrV6EypggbS4<455&$A0?*!P|&2M`{9jE0x#HY zspN$ce~2JjX_#h#s5l!cZOjx?hih8f)Y_bzr|(@HIgHwP_I~ek`8eL{^Q%!3iUIUKaahpwBRY` zuVoi@{!2%0{9Si?Mb#5kT2jL3v~KbYK4YP(x)!xCVUWwat6`iz*>v}ln4 zhvz$sg&AEuYI?(BG>>=SH}27{)!t$HnQPOcSr!wQIEB6-4%_3jSw*y7Q`dYC`4B#T zb9rv|G|khsq48w_Ul8&OJ&5adT`x8Je~r;rZ_AXWt<#QAZOol2?W97P0R(5XD-Ui(Qa*Q2>i3yyFFfx_++#N zy(Rg#TakP7L6_#svRPDrSKEKjhTbprYW92dC&k4~A=lMCoQ{3G?6{fsFzXMi?GW?M zGH&GcqF;U@)QP^K@h=MO#UX-?pWj!+9-K|j@fXIJ`EaqwYMwVl(0Qyz<9vi#U9BuFd7v5lG^Ak8jQ{Vh z-hoV|QmJXEug_mwW!^17C3)G)33^%pw(AH!12|RzzAY1tOsjDKw9x1w-g1DEN&u$~ F;13S0LGu6r literal 0 HcmV?d00001 diff --git a/i18n/de.json b/i18n/de.json new file mode 100644 index 0000000..ab3b82e --- /dev/null +++ b/i18n/de.json @@ -0,0 +1,4 @@ +{ + "vanillaJS": "vanillaJS Beispiel Projekt", + "awesome": "Coole app." +} diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 0000000..a196451 --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,4 @@ +{ + "vanillaJS": "vanillaJS seed project", + "awesome": "This is an awesome app!" +} diff --git a/i18n/it.json b/i18n/it.json new file mode 100644 index 0000000..6526c74 --- /dev/null +++ b/i18n/it.json @@ -0,0 +1,4 @@ +{ + "vanillaJS": "progetto di esempio vanillaJS", + "awesome": "Questa app è fantastica!" +} diff --git a/index.html b/index.html index 1ee7914..20ee127 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - + @@ -12,15 +12,16 @@
- - - - - + + + + + + - + diff --git a/js/index.js b/js/index.js index 7c13dc7..f3a7ee6 100644 --- a/js/index.js +++ b/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 diff --git a/node_modules/i18next-xhr-backend/.coveralls.yml b/node_modules/i18next-xhr-backend/.coveralls.yml new file mode 100644 index 0000000..00665ea --- /dev/null +++ b/node_modules/i18next-xhr-backend/.coveralls.yml @@ -0,0 +1 @@ +repo_token: 95SiHydOTG99ngOBBMnlRSl28IgE9kAah diff --git a/node_modules/i18next-xhr-backend/.travis.yml b/node_modules/i18next-xhr-backend/.travis.yml new file mode 100644 index 0000000..40d0078 --- /dev/null +++ b/node_modules/i18next-xhr-backend/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "6.2" +before_script: + - npm install -g gulp + - npm install -g karma diff --git a/node_modules/i18next-xhr-backend/CHANGELOG.md b/node_modules/i18next-xhr-backend/CHANGELOG.md new file mode 100644 index 0000000..c5d9e71 --- /dev/null +++ b/node_modules/i18next-xhr-backend/CHANGELOG.md @@ -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 diff --git a/node_modules/i18next-xhr-backend/LICENSE b/node_modules/i18next-xhr-backend/LICENSE new file mode 100644 index 0000000..6f6eb63 --- /dev/null +++ b/node_modules/i18next-xhr-backend/LICENSE @@ -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. + diff --git a/node_modules/i18next-xhr-backend/README.md b/node_modules/i18next-xhr-backend/README.md new file mode 100644 index 0000000..a2dd9ff --- /dev/null +++ b/node_modules/i18next-xhr-backend/README.md @@ -0,0 +1,172 @@ +# Introduction + +[![Travis](https://img.shields.io/travis/i18next/i18next-xhr-backend/master.svg?style=flat-square)](https://travis-ci.org/i18next/i18next-xhr-backend) +[![Coveralls](https://img.shields.io/coveralls/i18next/i18next-xhr-backend/master.svg?style=flat-square)](https://coveralls.io/github/i18next/i18next-xhr-backend) +[![npm version](https://img.shields.io/npm/v/i18next-xhr-backend.svg?style=flat-square)](https://www.npmjs.com/package/i18next-xhr-backend) +[![Bower](https://img.shields.io/bower/v/i18next-xhr-backend.svg)]() +[![David](https://img.shields.io/david/i18next/i18next-xhr-backend.svg?style=flat-square)](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 + +-------------- + +

Gold Sponsors

+ +

+ + + +

diff --git a/node_modules/i18next-xhr-backend/i18nextXHRBackend.js b/node_modules/i18next-xhr-backend/i18nextXHRBackend.js new file mode 100644 index 0000000..0f91fe0 --- /dev/null +++ b/node_modules/i18next-xhr-backend/i18nextXHRBackend.js @@ -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; + +}))); diff --git a/node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js b/node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js new file mode 100644 index 0000000..6f940a0 --- /dev/null +++ b/node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js @@ -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;n1&&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}); diff --git a/node_modules/i18next-xhr-backend/index.d.ts b/node_modules/i18next-xhr-backend/index.d.ts new file mode 100644 index 0000000..eba9f12 --- /dev/null +++ b/node_modules/i18next-xhr-backend/index.d.ts @@ -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; +} diff --git a/node_modules/i18next-xhr-backend/index.js b/node_modules/i18next-xhr-backend/index.js new file mode 100644 index 0000000..1cadc8b --- /dev/null +++ b/node_modules/i18next-xhr-backend/index.js @@ -0,0 +1,5 @@ +/* eslint no-var: 0 */ +var main = require('./dist/commonjs/index.js').default; + +module.exports = main; +module.exports.default = main; diff --git a/node_modules/i18next-xhr-backend/package.json b/node_modules/i18next-xhr-backend/package.json new file mode 100644 index 0000000..b679ad7 --- /dev/null +++ b/node_modules/i18next-xhr-backend/package.json @@ -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" +} diff --git a/node_modules/i18next-xhr-backend/rollup.config.js b/node_modules/i18next-xhr-backend/rollup.config.js new file mode 100644 index 0000000..80db34f --- /dev/null +++ b/node_modules/i18next-xhr-backend/rollup.config.js @@ -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 +}; diff --git a/node_modules/i18next-xhr-backend/tsconfig.json b/node_modules/i18next-xhr-backend/tsconfig.json new file mode 100644 index 0000000..da91c39 --- /dev/null +++ b/node_modules/i18next-xhr-backend/tsconfig.json @@ -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*"] +} diff --git a/node_modules/i18next-xhr-backend/tslint.json b/node_modules/i18next-xhr-backend/tslint.json new file mode 100644 index 0000000..64cbccb --- /dev/null +++ b/node_modules/i18next-xhr-backend/tslint.json @@ -0,0 +1,7 @@ +{ + "defaultSeverity": "error", + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false + } +} diff --git a/package-lock.json b/package-lock.json index 31636c2..4023888 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 46ddf0b..bb8e97e 100644 --- a/package.json +++ b/package.json @@ -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",