i18next.js
1 year ago
i18next.min.js
1 year ago
i18nextHttpBackend.js
1 year ago
i18nextHttpBackend.min.js
1 year ago
i18nextSprintfPostProcessor.js
1 year ago
i18nextSprintfPostProcessor.min.js
1 year ago
ng-i18next.js
1 year ago
ng-i18next.min.js
1 year ago
i18nextHttpBackend.js
448 lines
| 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i18nextHttpBackend = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ |
| 2 | (function (global){(function (){ |
| 3 | var fetchApi |
| 4 | if (typeof fetch === 'function') { |
| 5 | if (typeof global !== 'undefined' && global.fetch) { |
| 6 | fetchApi = global.fetch |
| 7 | } else if (typeof window !== 'undefined' && window.fetch) { |
| 8 | fetchApi = window.fetch |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | if (typeof require !== 'undefined' && (typeof window === 'undefined' || typeof window.document === 'undefined')) { |
| 13 | var f = fetchApi || require('cross-fetch') |
| 14 | if (f.default) f = f.default |
| 15 | exports.default = f |
| 16 | module.exports = exports.default |
| 17 | } |
| 18 | |
| 19 | }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
| 20 | },{"cross-fetch":5}],2:[function(require,module,exports){ |
| 21 | "use strict"; |
| 22 | |
| 23 | Object.defineProperty(exports, "__esModule", { |
| 24 | value: true |
| 25 | }); |
| 26 | exports.default = void 0; |
| 27 | |
| 28 | var _utils = require("./utils.js"); |
| 29 | |
| 30 | var _request = _interopRequireDefault(require("./request.js")); |
| 31 | |
| 32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 33 | |
| 34 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 35 | |
| 36 | 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); } } |
| 37 | |
| 38 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } |
| 39 | |
| 40 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
| 41 | |
| 42 | var getDefaults = function getDefaults() { |
| 43 | return { |
| 44 | loadPath: '/locales/{{lng}}/{{ns}}.json', |
| 45 | addPath: '/locales/add/{{lng}}/{{ns}}', |
| 46 | allowMultiLoading: false, |
| 47 | parse: function parse(data) { |
| 48 | return JSON.parse(data); |
| 49 | }, |
| 50 | stringify: JSON.stringify, |
| 51 | parsePayload: function parsePayload(namespace, key, fallbackValue) { |
| 52 | return _defineProperty({}, key, fallbackValue || ''); |
| 53 | }, |
| 54 | request: _request.default, |
| 55 | reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000, |
| 56 | customHeaders: {}, |
| 57 | queryStringParams: {}, |
| 58 | crossDomain: false, |
| 59 | withCredentials: false, |
| 60 | overrideMimeType: false, |
| 61 | requestOptions: { |
| 62 | mode: 'cors', |
| 63 | credentials: 'same-origin', |
| 64 | cache: 'default' |
| 65 | } |
| 66 | }; |
| 67 | }; |
| 68 | |
| 69 | var Backend = function () { |
| 70 | function Backend(services) { |
| 71 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 72 | var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
| 73 | |
| 74 | _classCallCheck(this, Backend); |
| 75 | |
| 76 | this.services = services; |
| 77 | this.options = options; |
| 78 | this.allOptions = allOptions; |
| 79 | this.type = 'backend'; |
| 80 | this.init(services, options, allOptions); |
| 81 | } |
| 82 | |
| 83 | _createClass(Backend, [{ |
| 84 | key: "init", |
| 85 | value: function init(services) { |
| 86 | var _this = this; |
| 87 | |
| 88 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 89 | var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
| 90 | this.services = services; |
| 91 | this.options = (0, _utils.defaults)(options, this.options || {}, getDefaults()); |
| 92 | this.allOptions = allOptions; |
| 93 | |
| 94 | if (this.services && this.options.reloadInterval) { |
| 95 | setInterval(function () { |
| 96 | return _this.reload(); |
| 97 | }, this.options.reloadInterval); |
| 98 | } |
| 99 | } |
| 100 | }, { |
| 101 | key: "readMulti", |
| 102 | value: function readMulti(languages, namespaces, callback) { |
| 103 | this._readAny(languages, languages, namespaces, namespaces, callback); |
| 104 | } |
| 105 | }, { |
| 106 | key: "read", |
| 107 | value: function read(language, namespace, callback) { |
| 108 | this._readAny([language], language, [namespace], namespace, callback); |
| 109 | } |
| 110 | }, { |
| 111 | key: "_readAny", |
| 112 | value: function _readAny(languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) { |
| 113 | var _this2 = this; |
| 114 | |
| 115 | var loadPath = this.options.loadPath; |
| 116 | |
| 117 | if (typeof this.options.loadPath === 'function') { |
| 118 | loadPath = this.options.loadPath(languages, namespaces); |
| 119 | } |
| 120 | |
| 121 | loadPath = (0, _utils.makePromise)(loadPath); |
| 122 | loadPath.then(function (resolvedLoadPath) { |
| 123 | var url = _this2.services.interpolator.interpolate(resolvedLoadPath, { |
| 124 | lng: languages.join('+'), |
| 125 | ns: namespaces.join('+') |
| 126 | }); |
| 127 | |
| 128 | _this2.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces); |
| 129 | }); |
| 130 | } |
| 131 | }, { |
| 132 | key: "loadUrl", |
| 133 | value: function loadUrl(url, callback, languages, namespaces) { |
| 134 | var _this3 = this; |
| 135 | |
| 136 | this.options.request(this.options, url, undefined, function (err, res) { |
| 137 | if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true); |
| 138 | if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false); |
| 139 | if (!res && err && err.message && err.message.indexOf('Failed to fetch') > -1) return callback('failed loading ' + url + ': ' + err.message, true); |
| 140 | if (err) return callback(err, false); |
| 141 | var ret, parseErr; |
| 142 | |
| 143 | try { |
| 144 | if (typeof res.data === 'string') { |
| 145 | ret = _this3.options.parse(res.data, languages, namespaces); |
| 146 | } else { |
| 147 | ret = res.data; |
| 148 | } |
| 149 | } catch (e) { |
| 150 | parseErr = 'failed parsing ' + url + ' to json'; |
| 151 | } |
| 152 | |
| 153 | if (parseErr) return callback(parseErr, false); |
| 154 | callback(null, ret); |
| 155 | }); |
| 156 | } |
| 157 | }, { |
| 158 | key: "create", |
| 159 | value: function create(languages, namespace, key, fallbackValue, callback) { |
| 160 | var _this4 = this; |
| 161 | |
| 162 | if (!this.options.addPath) return; |
| 163 | if (typeof languages === 'string') languages = [languages]; |
| 164 | var payload = this.options.parsePayload(namespace, key, fallbackValue); |
| 165 | var finished = 0; |
| 166 | var dataArray = []; |
| 167 | var resArray = []; |
| 168 | languages.forEach(function (lng) { |
| 169 | var addPath = _this4.options.addPath; |
| 170 | |
| 171 | if (typeof _this4.options.addPath === 'function') { |
| 172 | addPath = _this4.options.addPath(lng, namespace); |
| 173 | } |
| 174 | |
| 175 | var url = _this4.services.interpolator.interpolate(addPath, { |
| 176 | lng: lng, |
| 177 | ns: namespace |
| 178 | }); |
| 179 | |
| 180 | _this4.options.request(_this4.options, url, payload, function (data, res) { |
| 181 | finished += 1; |
| 182 | dataArray.push(data); |
| 183 | resArray.push(res); |
| 184 | |
| 185 | if (finished === languages.length) { |
| 186 | if (callback) callback(dataArray, resArray); |
| 187 | } |
| 188 | }); |
| 189 | }); |
| 190 | } |
| 191 | }, { |
| 192 | key: "reload", |
| 193 | value: function reload() { |
| 194 | var _this5 = this; |
| 195 | |
| 196 | var _this$services = this.services, |
| 197 | backendConnector = _this$services.backendConnector, |
| 198 | languageUtils = _this$services.languageUtils, |
| 199 | logger = _this$services.logger; |
| 200 | var currentLanguage = backendConnector.language; |
| 201 | if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return; |
| 202 | var toLoad = []; |
| 203 | |
| 204 | var append = function append(lng) { |
| 205 | var lngs = languageUtils.toResolveHierarchy(lng); |
| 206 | lngs.forEach(function (l) { |
| 207 | if (toLoad.indexOf(l) < 0) toLoad.push(l); |
| 208 | }); |
| 209 | }; |
| 210 | |
| 211 | append(currentLanguage); |
| 212 | if (this.allOptions.preload) this.allOptions.preload.forEach(function (l) { |
| 213 | return append(l); |
| 214 | }); |
| 215 | toLoad.forEach(function (lng) { |
| 216 | _this5.allOptions.ns.forEach(function (ns) { |
| 217 | backendConnector.read(lng, ns, 'read', null, null, function (err, data) { |
| 218 | if (err) logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err); |
| 219 | if (!err && data) logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data); |
| 220 | backendConnector.loaded("".concat(lng, "|").concat(ns), err, data); |
| 221 | }); |
| 222 | }); |
| 223 | }); |
| 224 | } |
| 225 | }]); |
| 226 | |
| 227 | return Backend; |
| 228 | }(); |
| 229 | |
| 230 | Backend.type = 'backend'; |
| 231 | var _default = Backend; |
| 232 | exports.default = _default; |
| 233 | module.exports = exports.default; |
| 234 | },{"./request.js":3,"./utils.js":4}],3:[function(require,module,exports){ |
| 235 | (function (global){(function (){ |
| 236 | "use strict"; |
| 237 | |
| 238 | Object.defineProperty(exports, "__esModule", { |
| 239 | value: true |
| 240 | }); |
| 241 | exports.default = void 0; |
| 242 | |
| 243 | var _utils = require("./utils.js"); |
| 244 | |
| 245 | var fetchNode = _interopRequireWildcard(require("./getFetch.js")); |
| 246 | |
| 247 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } |
| 248 | |
| 249 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
| 250 | |
| 251 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } |
| 252 | |
| 253 | var fetchApi; |
| 254 | |
| 255 | if (typeof fetch === 'function') { |
| 256 | if (typeof global !== 'undefined' && global.fetch) { |
| 257 | fetchApi = global.fetch; |
| 258 | } else if (typeof window !== 'undefined' && window.fetch) { |
| 259 | fetchApi = window.fetch; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | var XmlHttpRequestApi; |
| 264 | |
| 265 | if (_utils.hasXMLHttpRequest) { |
| 266 | if (typeof global !== 'undefined' && global.XMLHttpRequest) { |
| 267 | XmlHttpRequestApi = global.XMLHttpRequest; |
| 268 | } else if (typeof window !== 'undefined' && window.XMLHttpRequest) { |
| 269 | XmlHttpRequestApi = window.XMLHttpRequest; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | var ActiveXObjectApi; |
| 274 | |
| 275 | if (typeof ActiveXObject === 'function') { |
| 276 | if (typeof global !== 'undefined' && global.ActiveXObject) { |
| 277 | ActiveXObjectApi = global.ActiveXObject; |
| 278 | } else if (typeof window !== 'undefined' && window.ActiveXObject) { |
| 279 | ActiveXObjectApi = window.ActiveXObject; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode; |
| 284 | if (typeof fetchApi !== 'function') fetchApi = undefined; |
| 285 | |
| 286 | var addQueryString = function addQueryString(url, params) { |
| 287 | if (params && _typeof(params) === 'object') { |
| 288 | var queryString = ''; |
| 289 | |
| 290 | for (var paramName in params) { |
| 291 | queryString += '&' + encodeURIComponent(paramName) + '=' + encodeURIComponent(params[paramName]); |
| 292 | } |
| 293 | |
| 294 | if (!queryString) return url; |
| 295 | url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1); |
| 296 | } |
| 297 | |
| 298 | return url; |
| 299 | }; |
| 300 | |
| 301 | var requestWithFetch = function requestWithFetch(options, url, payload, callback) { |
| 302 | if (options.queryStringParams) { |
| 303 | url = addQueryString(url, options.queryStringParams); |
| 304 | } |
| 305 | |
| 306 | var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders); |
| 307 | if (payload) headers['Content-Type'] = 'application/json'; |
| 308 | fetchApi(url, (0, _utils.defaults)({ |
| 309 | method: payload ? 'POST' : 'GET', |
| 310 | body: payload ? options.stringify(payload) : undefined, |
| 311 | headers: headers |
| 312 | }, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions)).then(function (response) { |
| 313 | if (!response.ok) return callback(response.statusText || 'Error', { |
| 314 | status: response.status |
| 315 | }); |
| 316 | response.text().then(function (data) { |
| 317 | callback(null, { |
| 318 | status: response.status, |
| 319 | data: data |
| 320 | }); |
| 321 | }).catch(callback); |
| 322 | }).catch(callback); |
| 323 | }; |
| 324 | |
| 325 | var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) { |
| 326 | if (payload && _typeof(payload) === 'object') { |
| 327 | payload = addQueryString('', payload).slice(1); |
| 328 | } |
| 329 | |
| 330 | if (options.queryStringParams) { |
| 331 | url = addQueryString(url, options.queryStringParams); |
| 332 | } |
| 333 | |
| 334 | try { |
| 335 | var x; |
| 336 | |
| 337 | if (XmlHttpRequestApi) { |
| 338 | x = new XmlHttpRequestApi(); |
| 339 | } else { |
| 340 | x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0'); |
| 341 | } |
| 342 | |
| 343 | x.open(payload ? 'POST' : 'GET', url, 1); |
| 344 | |
| 345 | if (!options.crossDomain) { |
| 346 | x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); |
| 347 | } |
| 348 | |
| 349 | x.withCredentials = !!options.withCredentials; |
| 350 | |
| 351 | if (payload) { |
| 352 | x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
| 353 | } |
| 354 | |
| 355 | if (x.overrideMimeType) { |
| 356 | x.overrideMimeType('application/json'); |
| 357 | } |
| 358 | |
| 359 | var h = options.customHeaders; |
| 360 | h = typeof h === 'function' ? h() : h; |
| 361 | |
| 362 | if (h) { |
| 363 | for (var i in h) { |
| 364 | x.setRequestHeader(i, h[i]); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | x.onreadystatechange = function () { |
| 369 | x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, { |
| 370 | status: x.status, |
| 371 | data: x.responseText |
| 372 | }); |
| 373 | }; |
| 374 | |
| 375 | x.send(payload); |
| 376 | } catch (e) { |
| 377 | console && console.log(e); |
| 378 | } |
| 379 | }; |
| 380 | |
| 381 | var request = function request(options, url, payload, callback) { |
| 382 | if (typeof payload === 'function') { |
| 383 | callback = payload; |
| 384 | payload = undefined; |
| 385 | } |
| 386 | |
| 387 | callback = callback || function () {}; |
| 388 | |
| 389 | if (fetchApi) { |
| 390 | return requestWithFetch(options, url, payload, callback); |
| 391 | } |
| 392 | |
| 393 | if (_utils.hasXMLHttpRequest || typeof ActiveXObject === 'function') { |
| 394 | return requestWithXmlHttpRequest(options, url, payload, callback); |
| 395 | } |
| 396 | }; |
| 397 | |
| 398 | var _default = request; |
| 399 | exports.default = _default; |
| 400 | module.exports = exports.default; |
| 401 | }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
| 402 | },{"./getFetch.js":1,"./utils.js":4}],4:[function(require,module,exports){ |
| 403 | "use strict"; |
| 404 | |
| 405 | Object.defineProperty(exports, "__esModule", { |
| 406 | value: true |
| 407 | }); |
| 408 | exports.defaults = defaults; |
| 409 | exports.hasXMLHttpRequest = hasXMLHttpRequest; |
| 410 | exports.makePromise = makePromise; |
| 411 | |
| 412 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } |
| 413 | |
| 414 | var arr = []; |
| 415 | var each = arr.forEach; |
| 416 | var slice = arr.slice; |
| 417 | |
| 418 | function defaults(obj) { |
| 419 | each.call(slice.call(arguments, 1), function (source) { |
| 420 | if (source) { |
| 421 | for (var prop in source) { |
| 422 | if (obj[prop] === undefined) obj[prop] = source[prop]; |
| 423 | } |
| 424 | } |
| 425 | }); |
| 426 | return obj; |
| 427 | } |
| 428 | |
| 429 | function hasXMLHttpRequest() { |
| 430 | return typeof XMLHttpRequest === 'function' || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof(XMLHttpRequest)) === 'object'; |
| 431 | } |
| 432 | |
| 433 | function isPromise(maybePromise) { |
| 434 | return !!maybePromise && typeof maybePromise.then === 'function'; |
| 435 | } |
| 436 | |
| 437 | function makePromise(maybePromise) { |
| 438 | if (isPromise(maybePromise)) { |
| 439 | return maybePromise; |
| 440 | } |
| 441 | |
| 442 | return Promise.resolve(maybePromise); |
| 443 | } |
| 444 | },{}],5:[function(require,module,exports){ |
| 445 | |
| 446 | },{}]},{},[2])(2) |
| 447 | }); |
| 448 |