vendors-node_modules_taro_weapp_prebundle_i18next_js.js 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767
  1. "use strict";
  2. (wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([["vendors-node_modules_taro_weapp_prebundle_i18next_js"],{
  3. /***/ "./node_modules/.taro/weapp/prebundle/chunk-P7VEE7PG.js":
  4. /*!**************************************************************!*\
  5. !*** ./node_modules/.taro/weapp/prebundle/chunk-P7VEE7PG.js ***!
  6. \**************************************************************/
  7. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  8. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  9. /* harmony export */ __commonJS: function() { return /* binding */ __commonJS; },
  10. /* harmony export */ __esm: function() { return /* binding */ __esm; },
  11. /* harmony export */ __export: function() { return /* binding */ __export; },
  12. /* harmony export */ __toCommonJS: function() { return /* binding */ __toCommonJS; },
  13. /* harmony export */ __toESM: function() { return /* binding */ __toESM; }
  14. /* harmony export */ });
  15. var __create = Object.create;
  16. var __defProp = Object.defineProperty;
  17. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  18. var __getOwnPropNames = Object.getOwnPropertyNames;
  19. var __getProtoOf = Object.getPrototypeOf;
  20. var __hasOwnProp = Object.prototype.hasOwnProperty;
  21. var __esm = (fn, res)=>function __init() {
  22. return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
  23. };
  24. var __commonJS = (cb, mod)=>function __require() {
  25. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
  26. exports: {}
  27. }).exports, mod), mod.exports;
  28. };
  29. var __export = (target, all)=>{
  30. for(var name in all)__defProp(target, name, {
  31. get: all[name],
  32. enumerable: true
  33. });
  34. };
  35. var __copyProps = (to, from, except, desc)=>{
  36. if (from && typeof from === "object" || typeof from === "function") {
  37. for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
  38. get: ()=>from[key],
  39. enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
  40. });
  41. }
  42. return to;
  43. };
  44. var __toESM = (mod, isNodeMode, target)=>(target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
  45. value: mod,
  46. enumerable: true
  47. }) : target, mod));
  48. var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
  49. value: true
  50. }), mod);
  51. /***/ }),
  52. /***/ "./node_modules/.taro/weapp/prebundle/i18next.js":
  53. /*!*******************************************************!*\
  54. !*** ./node_modules/.taro/weapp/prebundle/i18next.js ***!
  55. \*******************************************************/
  56. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  57. __webpack_require__.r(__webpack_exports__);
  58. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  59. /* harmony export */ changeLanguage: function() { return /* binding */ changeLanguage; },
  60. /* harmony export */ createInstance: function() { return /* binding */ createInstance; },
  61. /* harmony export */ "default": function() { return /* binding */ i18next_default; },
  62. /* harmony export */ dir: function() { return /* binding */ dir; },
  63. /* harmony export */ exists: function() { return /* binding */ exists; },
  64. /* harmony export */ getFixedT: function() { return /* binding */ getFixedT; },
  65. /* harmony export */ hasLoadedNamespace: function() { return /* binding */ hasLoadedNamespace; },
  66. /* harmony export */ init: function() { return /* binding */ init; },
  67. /* harmony export */ loadLanguages: function() { return /* binding */ loadLanguages; },
  68. /* harmony export */ loadNamespaces: function() { return /* binding */ loadNamespaces; },
  69. /* harmony export */ loadResources: function() { return /* binding */ loadResources; },
  70. /* harmony export */ reloadResources: function() { return /* binding */ reloadResources; },
  71. /* harmony export */ setDefaultNamespace: function() { return /* binding */ setDefaultNamespace; },
  72. /* harmony export */ t: function() { return /* binding */ t; },
  73. /* harmony export */ use: function() { return /* binding */ use; }
  74. /* harmony export */ });
  75. /* harmony import */ var _chunk_P7VEE7PG_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./chunk-P7VEE7PG.js */ "./node_modules/.taro/weapp/prebundle/chunk-P7VEE7PG.js");
  76. function _defineProperty(obj, key, value) {
  77. if (key in obj) {
  78. Object.defineProperty(obj, key, {
  79. value: value,
  80. enumerable: true,
  81. configurable: true,
  82. writable: true
  83. });
  84. } else {
  85. obj[key] = value;
  86. }
  87. return obj;
  88. }
  89. function _objectSpread(target) {
  90. for(var i = 1; i < arguments.length; i++){
  91. var source = arguments[i] != null ? arguments[i] : {};
  92. var ownKeys = Object.keys(source);
  93. if (typeof Object.getOwnPropertySymbols === 'function') {
  94. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
  95. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  96. }));
  97. }
  98. ownKeys.forEach(function(key) {
  99. _defineProperty(target, key, source[key]);
  100. });
  101. }
  102. return target;
  103. }
  104. function ownKeys(object, enumerableOnly) {
  105. var keys = Object.keys(object);
  106. if (Object.getOwnPropertySymbols) {
  107. var symbols = Object.getOwnPropertySymbols(object);
  108. if (enumerableOnly) {
  109. symbols = symbols.filter(function(sym) {
  110. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  111. });
  112. }
  113. keys.push.apply(keys, symbols);
  114. }
  115. return keys;
  116. }
  117. function _objectSpreadProps(target, source) {
  118. source = source != null ? source : {};
  119. if (Object.getOwnPropertyDescriptors) {
  120. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  121. } else {
  122. ownKeys(Object(source)).forEach(function(key) {
  123. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  124. });
  125. }
  126. return target;
  127. }
  128. // node_modules/i18next/dist/esm/i18next.js
  129. var consoleLogger = {
  130. type: "logger",
  131. log (args) {
  132. this.output("log", args);
  133. },
  134. warn (args) {
  135. this.output("warn", args);
  136. },
  137. error (args) {
  138. this.output("error", args);
  139. },
  140. output (type, args) {
  141. if (console && console[type]) console[type].apply(console, args);
  142. }
  143. };
  144. var Logger = class {
  145. init(concreteLogger) {
  146. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  147. this.prefix = options.prefix || "i18next:";
  148. this.logger = concreteLogger || consoleLogger;
  149. this.options = options;
  150. this.debug = options.debug;
  151. }
  152. log() {
  153. for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
  154. args[_key] = arguments[_key];
  155. }
  156. return this.forward(args, "log", "", true);
  157. }
  158. warn() {
  159. for(var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++){
  160. args[_key2] = arguments[_key2];
  161. }
  162. return this.forward(args, "warn", "", true);
  163. }
  164. error() {
  165. for(var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++){
  166. args[_key3] = arguments[_key3];
  167. }
  168. return this.forward(args, "error", "");
  169. }
  170. deprecate() {
  171. for(var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++){
  172. args[_key4] = arguments[_key4];
  173. }
  174. return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
  175. }
  176. forward(args, lvl, prefix, debugOnly) {
  177. if (debugOnly && !this.debug) return null;
  178. if (typeof args[0] === "string") args[0] = `${prefix}${this.prefix} ${args[0]}`;
  179. return this.logger[lvl](args);
  180. }
  181. create(moduleName) {
  182. return new Logger(this.logger, _objectSpread({}, {
  183. prefix: `${this.prefix}:${moduleName}:`
  184. }, this.options));
  185. }
  186. clone(options) {
  187. options = options || this.options;
  188. options.prefix = options.prefix || this.prefix;
  189. return new Logger(this.logger, options);
  190. }
  191. constructor(concreteLogger){
  192. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  193. this.init(concreteLogger, options);
  194. }
  195. };
  196. var baseLogger = new Logger();
  197. var EventEmitter = class {
  198. on(events, listener) {
  199. events.split(" ").forEach((event)=>{
  200. this.observers[event] = this.observers[event] || [];
  201. this.observers[event].push(listener);
  202. });
  203. return this;
  204. }
  205. off(event, listener) {
  206. if (!this.observers[event]) return;
  207. if (!listener) {
  208. delete this.observers[event];
  209. return;
  210. }
  211. this.observers[event] = this.observers[event].filter((l)=>l !== listener);
  212. }
  213. emit(event) {
  214. for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
  215. args[_key - 1] = arguments[_key];
  216. }
  217. if (this.observers[event]) {
  218. const cloned = [].concat(this.observers[event]);
  219. cloned.forEach((observer)=>{
  220. observer(...args);
  221. });
  222. }
  223. if (this.observers["*"]) {
  224. const cloned1 = [].concat(this.observers["*"]);
  225. cloned1.forEach((observer)=>{
  226. observer.apply(observer, [
  227. event,
  228. ...args
  229. ]);
  230. });
  231. }
  232. }
  233. constructor(){
  234. this.observers = {};
  235. }
  236. };
  237. function defer() {
  238. let res;
  239. let rej;
  240. const promise = new Promise((resolve, reject)=>{
  241. res = resolve;
  242. rej = reject;
  243. });
  244. promise.resolve = res;
  245. promise.reject = rej;
  246. return promise;
  247. }
  248. function makeString(object) {
  249. if (object == null) return "";
  250. return "" + object;
  251. }
  252. function copy(a, s, t2) {
  253. a.forEach((m)=>{
  254. if (s[m]) t2[m] = s[m];
  255. });
  256. }
  257. function getLastOfPath(object, path, Empty) {
  258. function cleanKey(key) {
  259. return key && key.indexOf("###") > -1 ? key.replace(/###/g, ".") : key;
  260. }
  261. function canNotTraverseDeeper() {
  262. return !object || typeof object === "string";
  263. }
  264. const stack = typeof path !== "string" ? [].concat(path) : path.split(".");
  265. while(stack.length > 1){
  266. if (canNotTraverseDeeper()) return {};
  267. const key = cleanKey(stack.shift());
  268. if (!object[key] && Empty) object[key] = new Empty();
  269. if (Object.prototype.hasOwnProperty.call(object, key)) {
  270. object = object[key];
  271. } else {
  272. object = {};
  273. }
  274. }
  275. if (canNotTraverseDeeper()) return {};
  276. return {
  277. obj: object,
  278. k: cleanKey(stack.shift())
  279. };
  280. }
  281. function setPath(object, path, newValue) {
  282. const { obj , k } = getLastOfPath(object, path, Object);
  283. obj[k] = newValue;
  284. }
  285. function pushPath(object, path, newValue, concat) {
  286. const { obj , k } = getLastOfPath(object, path, Object);
  287. obj[k] = obj[k] || [];
  288. if (concat) obj[k] = obj[k].concat(newValue);
  289. if (!concat) obj[k].push(newValue);
  290. }
  291. function getPath(object, path) {
  292. const { obj , k } = getLastOfPath(object, path);
  293. if (!obj) return void 0;
  294. return obj[k];
  295. }
  296. function getPathWithDefaults(data, defaultData, key) {
  297. const value = getPath(data, key);
  298. if (value !== void 0) {
  299. return value;
  300. }
  301. return getPath(defaultData, key);
  302. }
  303. function deepExtend(target, source, overwrite) {
  304. for(const prop in source){
  305. if (prop !== "__proto__" && prop !== "constructor") {
  306. if (prop in target) {
  307. if (typeof target[prop] === "string" || target[prop] instanceof String || typeof source[prop] === "string" || source[prop] instanceof String) {
  308. if (overwrite) target[prop] = source[prop];
  309. } else {
  310. deepExtend(target[prop], source[prop], overwrite);
  311. }
  312. } else {
  313. target[prop] = source[prop];
  314. }
  315. }
  316. }
  317. return target;
  318. }
  319. function regexEscape(str) {
  320. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  321. }
  322. var _entityMap = {
  323. "&": "&amp;",
  324. "<": "&lt;",
  325. ">": "&gt;",
  326. '"': "&quot;",
  327. "'": "&#39;",
  328. "/": "&#x2F;"
  329. };
  330. function escape(data) {
  331. if (typeof data === "string") {
  332. return data.replace(/[&<>"'\/]/g, (s)=>_entityMap[s]);
  333. }
  334. return data;
  335. }
  336. var chars = [
  337. " ",
  338. ",",
  339. "?",
  340. "!",
  341. ";"
  342. ];
  343. function looksLikeObjectPath(key, nsSeparator, keySeparator) {
  344. nsSeparator = nsSeparator || "";
  345. keySeparator = keySeparator || "";
  346. const possibleChars = chars.filter((c)=>nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
  347. if (possibleChars.length === 0) return true;
  348. const r = new RegExp(`(${possibleChars.map((c)=>c === "?" ? "\\?" : c).join("|")})`);
  349. let matched = !r.test(key);
  350. if (!matched) {
  351. const ki = key.indexOf(keySeparator);
  352. if (ki > 0 && !r.test(key.substring(0, ki))) {
  353. matched = true;
  354. }
  355. }
  356. return matched;
  357. }
  358. function deepFind(obj, path) {
  359. let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
  360. if (!obj) return void 0;
  361. if (obj[path]) return obj[path];
  362. const paths = path.split(keySeparator);
  363. let current = obj;
  364. for(let i = 0; i < paths.length; ++i){
  365. if (!current) return void 0;
  366. if (typeof current[paths[i]] === "string" && i + 1 < paths.length) {
  367. return void 0;
  368. }
  369. if (current[paths[i]] === void 0) {
  370. let j = 2;
  371. let p = paths.slice(i, i + j).join(keySeparator);
  372. let mix = current[p];
  373. while(mix === void 0 && paths.length > i + j){
  374. j++;
  375. p = paths.slice(i, i + j).join(keySeparator);
  376. mix = current[p];
  377. }
  378. if (mix === void 0) return void 0;
  379. if (mix === null) return null;
  380. if (path.endsWith(p)) {
  381. if (typeof mix === "string") return mix;
  382. if (p && typeof mix[p] === "string") return mix[p];
  383. }
  384. const joinedPath = paths.slice(i + j).join(keySeparator);
  385. if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
  386. return void 0;
  387. }
  388. current = current[paths[i]];
  389. }
  390. return current;
  391. }
  392. function getCleanedCode(code) {
  393. if (code && code.indexOf("_") > 0) return code.replace("_", "-");
  394. return code;
  395. }
  396. var ResourceStore = class extends EventEmitter {
  397. addNamespaces(ns) {
  398. if (this.options.ns.indexOf(ns) < 0) {
  399. this.options.ns.push(ns);
  400. }
  401. }
  402. removeNamespaces(ns) {
  403. const index = this.options.ns.indexOf(ns);
  404. if (index > -1) {
  405. this.options.ns.splice(index, 1);
  406. }
  407. }
  408. getResource(lng, ns, key) {
  409. let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
  410. const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
  411. const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
  412. let path = [
  413. lng,
  414. ns
  415. ];
  416. if (key && typeof key !== "string") path = path.concat(key);
  417. if (key && typeof key === "string") path = path.concat(keySeparator ? key.split(keySeparator) : key);
  418. if (lng.indexOf(".") > -1) {
  419. path = lng.split(".");
  420. }
  421. const result = getPath(this.data, path);
  422. if (result || !ignoreJSONStructure || typeof key !== "string") return result;
  423. return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
  424. }
  425. addResource(lng, ns, key, value) {
  426. let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
  427. silent: false
  428. };
  429. const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
  430. let path = [
  431. lng,
  432. ns
  433. ];
  434. if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
  435. if (lng.indexOf(".") > -1) {
  436. path = lng.split(".");
  437. value = ns;
  438. ns = path[1];
  439. }
  440. this.addNamespaces(ns);
  441. setPath(this.data, path, value);
  442. if (!options.silent) this.emit("added", lng, ns, key, value);
  443. }
  444. addResources(lng, ns, resources) {
  445. let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
  446. silent: false
  447. };
  448. for(const m in resources){
  449. if (typeof resources[m] === "string" || Object.prototype.toString.apply(resources[m]) === "[object Array]") this.addResource(lng, ns, m, resources[m], {
  450. silent: true
  451. });
  452. }
  453. if (!options.silent) this.emit("added", lng, ns, resources);
  454. }
  455. addResourceBundle(lng, ns, resources, deep, overwrite) {
  456. let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
  457. silent: false
  458. };
  459. let path = [
  460. lng,
  461. ns
  462. ];
  463. if (lng.indexOf(".") > -1) {
  464. path = lng.split(".");
  465. deep = resources;
  466. resources = ns;
  467. ns = path[1];
  468. }
  469. this.addNamespaces(ns);
  470. let pack = getPath(this.data, path) || {};
  471. if (deep) {
  472. deepExtend(pack, resources, overwrite);
  473. } else {
  474. pack = _objectSpread({}, pack, resources);
  475. }
  476. setPath(this.data, path, pack);
  477. if (!options.silent) this.emit("added", lng, ns, resources);
  478. }
  479. removeResourceBundle(lng, ns) {
  480. if (this.hasResourceBundle(lng, ns)) {
  481. delete this.data[lng][ns];
  482. }
  483. this.removeNamespaces(ns);
  484. this.emit("removed", lng, ns);
  485. }
  486. hasResourceBundle(lng, ns) {
  487. return this.getResource(lng, ns) !== void 0;
  488. }
  489. getResourceBundle(lng, ns) {
  490. if (!ns) ns = this.options.defaultNS;
  491. if (this.options.compatibilityAPI === "v1") return _objectSpread({}, {}, this.getResource(lng, ns));
  492. return this.getResource(lng, ns);
  493. }
  494. getDataByLanguage(lng) {
  495. return this.data[lng];
  496. }
  497. hasLanguageSomeTranslations(lng) {
  498. const data = this.getDataByLanguage(lng);
  499. const n = data && Object.keys(data) || [];
  500. return !!n.find((v)=>data[v] && Object.keys(data[v]).length > 0);
  501. }
  502. toJSON() {
  503. return this.data;
  504. }
  505. constructor(data){
  506. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
  507. ns: [
  508. "translation"
  509. ],
  510. defaultNS: "translation"
  511. };
  512. super();
  513. this.data = data || {};
  514. this.options = options;
  515. if (this.options.keySeparator === void 0) {
  516. this.options.keySeparator = ".";
  517. }
  518. if (this.options.ignoreJSONStructure === void 0) {
  519. this.options.ignoreJSONStructure = true;
  520. }
  521. }
  522. };
  523. var postProcessor = {
  524. processors: {},
  525. addPostProcessor (module) {
  526. this.processors[module.name] = module;
  527. },
  528. handle (processors, value, key, options, translator) {
  529. processors.forEach((processor)=>{
  530. if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
  531. });
  532. return value;
  533. }
  534. };
  535. var checkedLoadedFor = {};
  536. var Translator = class extends EventEmitter {
  537. changeLanguage(lng) {
  538. if (lng) this.language = lng;
  539. }
  540. exists(key) {
  541. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
  542. interpolation: {}
  543. };
  544. if (key === void 0 || key === null) {
  545. return false;
  546. }
  547. const resolved = this.resolve(key, options);
  548. return resolved && resolved.res !== void 0;
  549. }
  550. extractFromKey(key, options) {
  551. let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
  552. if (nsSeparator === void 0) nsSeparator = ":";
  553. const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
  554. let namespaces = options.ns || this.options.defaultNS || [];
  555. const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
  556. const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
  557. if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
  558. const m = key.match(this.interpolator.nestingRegexp);
  559. if (m && m.length > 0) {
  560. return {
  561. key,
  562. namespaces
  563. };
  564. }
  565. const parts = key.split(nsSeparator);
  566. if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
  567. key = parts.join(keySeparator);
  568. }
  569. if (typeof namespaces === "string") namespaces = [
  570. namespaces
  571. ];
  572. return {
  573. key,
  574. namespaces
  575. };
  576. }
  577. translate(keys, options, lastKey) {
  578. if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
  579. options = this.options.overloadTranslationOptionHandler(arguments);
  580. }
  581. if (typeof options === "object") options = _objectSpread({}, options);
  582. if (!options) options = {};
  583. if (keys === void 0 || keys === null) return "";
  584. if (!Array.isArray(keys)) keys = [
  585. String(keys)
  586. ];
  587. const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
  588. const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
  589. const { key , namespaces } = this.extractFromKey(keys[keys.length - 1], options);
  590. const namespace = namespaces[namespaces.length - 1];
  591. const lng = options.lng || this.language;
  592. const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
  593. if (lng && lng.toLowerCase() === "cimode") {
  594. if (appendNamespaceToCIMode) {
  595. const nsSeparator = options.nsSeparator || this.options.nsSeparator;
  596. if (returnDetails) {
  597. return {
  598. res: `${namespace}${nsSeparator}${key}`,
  599. usedKey: key,
  600. exactUsedKey: key,
  601. usedLng: lng,
  602. usedNS: namespace
  603. };
  604. }
  605. return `${namespace}${nsSeparator}${key}`;
  606. }
  607. if (returnDetails) {
  608. return {
  609. res: key,
  610. usedKey: key,
  611. exactUsedKey: key,
  612. usedLng: lng,
  613. usedNS: namespace
  614. };
  615. }
  616. return key;
  617. }
  618. const resolved = this.resolve(keys, options);
  619. let res = resolved && resolved.res;
  620. const resUsedKey = resolved && resolved.usedKey || key;
  621. const resExactUsedKey = resolved && resolved.exactUsedKey || key;
  622. const resType = Object.prototype.toString.apply(res);
  623. const noObject = [
  624. "[object Number]",
  625. "[object Function]",
  626. "[object RegExp]"
  627. ];
  628. const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
  629. const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
  630. const handleAsObject = typeof res !== "string" && typeof res !== "boolean" && typeof res !== "number";
  631. if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === "string" && resType === "[object Array]")) {
  632. if (!options.returnObjects && !this.options.returnObjects) {
  633. if (!this.options.returnedObjectHandler) {
  634. this.logger.warn("accessing an object - but returnObjects options is not enabled!");
  635. }
  636. const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpreadProps(_objectSpread({}, options), {
  637. ns: namespaces
  638. })) : `key '${key} (${this.language})' returned an object instead of string.`;
  639. if (returnDetails) {
  640. resolved.res = r;
  641. return resolved;
  642. }
  643. return r;
  644. }
  645. if (keySeparator) {
  646. const resTypeIsArray = resType === "[object Array]";
  647. const copy2 = resTypeIsArray ? [] : {};
  648. const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
  649. for(const m in res){
  650. if (Object.prototype.hasOwnProperty.call(res, m)) {
  651. const deepKey = `${newKeyToUse}${keySeparator}${m}`;
  652. copy2[m] = this.translate(deepKey, _objectSpread({}, options, {
  653. joinArrays: false,
  654. ns: namespaces
  655. }));
  656. if (copy2[m] === deepKey) copy2[m] = res[m];
  657. }
  658. }
  659. res = copy2;
  660. }
  661. } else if (handleAsObjectInI18nFormat && typeof joinArrays === "string" && resType === "[object Array]") {
  662. res = res.join(joinArrays);
  663. if (res) res = this.extendTranslation(res, keys, options, lastKey);
  664. } else {
  665. let usedDefault = false;
  666. let usedKey = false;
  667. const needsPluralHandling = options.count !== void 0 && typeof options.count !== "string";
  668. const hasDefaultValue = Translator.hasDefaultValue(options);
  669. const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
  670. const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
  671. ordinal: false
  672. }) : "";
  673. const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
  674. if (!this.isValidLookup(res) && hasDefaultValue) {
  675. usedDefault = true;
  676. res = defaultValue;
  677. }
  678. if (!this.isValidLookup(res)) {
  679. usedKey = true;
  680. res = key;
  681. }
  682. const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
  683. const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
  684. const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
  685. if (usedKey || usedDefault || updateMissing) {
  686. this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
  687. if (keySeparator) {
  688. const fk = this.resolve(key, _objectSpreadProps(_objectSpread({}, options), {
  689. keySeparator: false
  690. }));
  691. if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
  692. }
  693. let lngs = [];
  694. const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
  695. if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
  696. for(let i = 0; i < fallbackLngs.length; i++){
  697. lngs.push(fallbackLngs[i]);
  698. }
  699. } else if (this.options.saveMissingTo === "all") {
  700. lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
  701. } else {
  702. lngs.push(options.lng || this.language);
  703. }
  704. const send = (l, k, specificDefaultValue)=>{
  705. const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
  706. if (this.options.missingKeyHandler) {
  707. this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
  708. } else if (this.backendConnector && this.backendConnector.saveMissing) {
  709. this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
  710. }
  711. this.emit("missingKey", l, namespace, k, res);
  712. };
  713. if (this.options.saveMissing) {
  714. if (this.options.saveMissingPlurals && needsPluralHandling) {
  715. lngs.forEach((language)=>{
  716. this.pluralResolver.getSuffixes(language, options).forEach((suffix)=>{
  717. send([
  718. language
  719. ], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
  720. });
  721. });
  722. } else {
  723. send(lngs, key, defaultValue);
  724. }
  725. }
  726. }
  727. res = this.extendTranslation(res, keys, options, resolved, lastKey);
  728. if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
  729. if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
  730. if (this.options.compatibilityAPI !== "v1") {
  731. res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
  732. } else {
  733. res = this.options.parseMissingKeyHandler(res);
  734. }
  735. }
  736. }
  737. if (returnDetails) {
  738. resolved.res = res;
  739. return resolved;
  740. }
  741. return res;
  742. }
  743. extendTranslation(res, key, options, resolved, lastKey) {
  744. var _this = this;
  745. if (this.i18nFormat && this.i18nFormat.parse) {
  746. res = this.i18nFormat.parse(res, _objectSpread({}, this.options.interpolation.defaultVariables, options), options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
  747. resolved
  748. });
  749. } else if (!options.skipInterpolation) {
  750. if (options.interpolation) this.interpolator.init(_objectSpread({}, options, {
  751. interpolation: _objectSpread({}, this.options.interpolation, options.interpolation)
  752. }));
  753. const skipOnVariables = typeof res === "string" && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
  754. let nestBef;
  755. if (skipOnVariables) {
  756. const nb = res.match(this.interpolator.nestingRegexp);
  757. nestBef = nb && nb.length;
  758. }
  759. let data = options.replace && typeof options.replace !== "string" ? options.replace : options;
  760. if (this.options.interpolation.defaultVariables) data = _objectSpread({}, this.options.interpolation.defaultVariables, data);
  761. res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
  762. if (skipOnVariables) {
  763. const na = res.match(this.interpolator.nestingRegexp);
  764. const nestAft = na && na.length;
  765. if (nestBef < nestAft) options.nest = false;
  766. }
  767. if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res) options.lng = resolved.usedLng;
  768. if (options.nest !== false) res = this.interpolator.nest(res, function() {
  769. for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
  770. args[_key] = arguments[_key];
  771. }
  772. if (lastKey && lastKey[0] === args[0] && !options.context) {
  773. _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
  774. return null;
  775. }
  776. return _this.translate(...args, key);
  777. }, options);
  778. if (options.interpolation) this.interpolator.reset();
  779. }
  780. const postProcess = options.postProcess || this.options.postProcess;
  781. const postProcessorNames = typeof postProcess === "string" ? [
  782. postProcess
  783. ] : postProcess;
  784. if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
  785. res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread({
  786. i18nResolved: resolved
  787. }, options) : options, this);
  788. }
  789. return res;
  790. }
  791. resolve(keys) {
  792. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  793. let found;
  794. let usedKey;
  795. let exactUsedKey;
  796. let usedLng;
  797. let usedNS;
  798. if (typeof keys === "string") keys = [
  799. keys
  800. ];
  801. keys.forEach((k)=>{
  802. if (this.isValidLookup(found)) return;
  803. const extracted = this.extractFromKey(k, options);
  804. const key = extracted.key;
  805. usedKey = key;
  806. let namespaces = extracted.namespaces;
  807. if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
  808. const needsPluralHandling = options.count !== void 0 && typeof options.count !== "string";
  809. const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
  810. const needsContextHandling = options.context !== void 0 && (typeof options.context === "string" || typeof options.context === "number") && options.context !== "";
  811. const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
  812. namespaces.forEach((ns)=>{
  813. if (this.isValidLookup(found)) return;
  814. usedNS = ns;
  815. if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
  816. checkedLoadedFor[`${codes[0]}-${ns}`] = true;
  817. this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
  818. }
  819. codes.forEach((code)=>{
  820. if (this.isValidLookup(found)) return;
  821. usedLng = code;
  822. const finalKeys = [
  823. key
  824. ];
  825. if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
  826. this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
  827. } else {
  828. let pluralSuffix;
  829. if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
  830. const zeroSuffix = `${this.options.pluralSeparator}zero`;
  831. const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
  832. if (needsPluralHandling) {
  833. finalKeys.push(key + pluralSuffix);
  834. if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
  835. finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
  836. }
  837. if (needsZeroSuffixLookup) {
  838. finalKeys.push(key + zeroSuffix);
  839. }
  840. }
  841. if (needsContextHandling) {
  842. const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
  843. finalKeys.push(contextKey);
  844. if (needsPluralHandling) {
  845. finalKeys.push(contextKey + pluralSuffix);
  846. if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
  847. finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
  848. }
  849. if (needsZeroSuffixLookup) {
  850. finalKeys.push(contextKey + zeroSuffix);
  851. }
  852. }
  853. }
  854. }
  855. let possibleKey;
  856. while(possibleKey = finalKeys.pop()){
  857. if (!this.isValidLookup(found)) {
  858. exactUsedKey = possibleKey;
  859. found = this.getResource(code, ns, possibleKey, options);
  860. }
  861. }
  862. });
  863. });
  864. });
  865. return {
  866. res: found,
  867. usedKey,
  868. exactUsedKey,
  869. usedLng,
  870. usedNS
  871. };
  872. }
  873. isValidLookup(res) {
  874. return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
  875. }
  876. getResource(code, ns, key) {
  877. let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
  878. if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
  879. return this.resourceStore.getResource(code, ns, key, options);
  880. }
  881. static hasDefaultValue(options) {
  882. const prefix = "defaultValue";
  883. for(const option in options){
  884. if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
  885. return true;
  886. }
  887. }
  888. return false;
  889. }
  890. constructor(services){
  891. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  892. super();
  893. copy([
  894. "resourceStore",
  895. "languageUtils",
  896. "pluralResolver",
  897. "interpolator",
  898. "backendConnector",
  899. "i18nFormat",
  900. "utils"
  901. ], services, this);
  902. this.options = options;
  903. if (this.options.keySeparator === void 0) {
  904. this.options.keySeparator = ".";
  905. }
  906. this.logger = baseLogger.create("translator");
  907. }
  908. };
  909. function capitalize(string) {
  910. return string.charAt(0).toUpperCase() + string.slice(1);
  911. }
  912. var LanguageUtil = class {
  913. getScriptPartFromCode(code) {
  914. code = getCleanedCode(code);
  915. if (!code || code.indexOf("-") < 0) return null;
  916. const p = code.split("-");
  917. if (p.length === 2) return null;
  918. p.pop();
  919. if (p[p.length - 1].toLowerCase() === "x") return null;
  920. return this.formatLanguageCode(p.join("-"));
  921. }
  922. getLanguagePartFromCode(code) {
  923. code = getCleanedCode(code);
  924. if (!code || code.indexOf("-") < 0) return code;
  925. const p = code.split("-");
  926. return this.formatLanguageCode(p[0]);
  927. }
  928. formatLanguageCode(code) {
  929. if (typeof code === "string" && code.indexOf("-") > -1) {
  930. const specialCases = [
  931. "hans",
  932. "hant",
  933. "latn",
  934. "cyrl",
  935. "cans",
  936. "mong",
  937. "arab"
  938. ];
  939. let p = code.split("-");
  940. if (this.options.lowerCaseLng) {
  941. p = p.map((part)=>part.toLowerCase());
  942. } else if (p.length === 2) {
  943. p[0] = p[0].toLowerCase();
  944. p[1] = p[1].toUpperCase();
  945. if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
  946. } else if (p.length === 3) {
  947. p[0] = p[0].toLowerCase();
  948. if (p[1].length === 2) p[1] = p[1].toUpperCase();
  949. if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase();
  950. if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
  951. if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
  952. }
  953. return p.join("-");
  954. }
  955. return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
  956. }
  957. isSupportedCode(code) {
  958. if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
  959. code = this.getLanguagePartFromCode(code);
  960. }
  961. return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
  962. }
  963. getBestMatchFromCodes(codes) {
  964. if (!codes) return null;
  965. let found;
  966. codes.forEach((code)=>{
  967. if (found) return;
  968. const cleanedLng = this.formatLanguageCode(code);
  969. if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
  970. });
  971. if (!found && this.options.supportedLngs) {
  972. codes.forEach((code)=>{
  973. if (found) return;
  974. const lngOnly = this.getLanguagePartFromCode(code);
  975. if (this.isSupportedCode(lngOnly)) return found = lngOnly;
  976. found = this.options.supportedLngs.find((supportedLng)=>{
  977. if (supportedLng === lngOnly) return supportedLng;
  978. if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
  979. if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
  980. });
  981. });
  982. }
  983. if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
  984. return found;
  985. }
  986. getFallbackCodes(fallbacks, code) {
  987. if (!fallbacks) return [];
  988. if (typeof fallbacks === "function") fallbacks = fallbacks(code);
  989. if (typeof fallbacks === "string") fallbacks = [
  990. fallbacks
  991. ];
  992. if (Object.prototype.toString.apply(fallbacks) === "[object Array]") return fallbacks;
  993. if (!code) return fallbacks.default || [];
  994. let found = fallbacks[code];
  995. if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
  996. if (!found) found = fallbacks[this.formatLanguageCode(code)];
  997. if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
  998. if (!found) found = fallbacks.default;
  999. return found || [];
  1000. }
  1001. toResolveHierarchy(code, fallbackCode) {
  1002. const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
  1003. const codes = [];
  1004. const addCode = (c)=>{
  1005. if (!c) return;
  1006. if (this.isSupportedCode(c)) {
  1007. codes.push(c);
  1008. } else {
  1009. this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
  1010. }
  1011. };
  1012. if (typeof code === "string" && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
  1013. if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
  1014. if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
  1015. if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
  1016. } else if (typeof code === "string") {
  1017. addCode(this.formatLanguageCode(code));
  1018. }
  1019. fallbackCodes.forEach((fc)=>{
  1020. if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
  1021. });
  1022. return codes;
  1023. }
  1024. constructor(options){
  1025. this.options = options;
  1026. this.supportedLngs = this.options.supportedLngs || false;
  1027. this.logger = baseLogger.create("languageUtils");
  1028. }
  1029. };
  1030. var sets = [
  1031. {
  1032. lngs: [
  1033. "ach",
  1034. "ak",
  1035. "am",
  1036. "arn",
  1037. "br",
  1038. "fil",
  1039. "gun",
  1040. "ln",
  1041. "mfe",
  1042. "mg",
  1043. "mi",
  1044. "oc",
  1045. "pt",
  1046. "pt-BR",
  1047. "tg",
  1048. "tl",
  1049. "ti",
  1050. "tr",
  1051. "uz",
  1052. "wa"
  1053. ],
  1054. nr: [
  1055. 1,
  1056. 2
  1057. ],
  1058. fc: 1
  1059. },
  1060. {
  1061. lngs: [
  1062. "af",
  1063. "an",
  1064. "ast",
  1065. "az",
  1066. "bg",
  1067. "bn",
  1068. "ca",
  1069. "da",
  1070. "de",
  1071. "dev",
  1072. "el",
  1073. "en",
  1074. "eo",
  1075. "es",
  1076. "et",
  1077. "eu",
  1078. "fi",
  1079. "fo",
  1080. "fur",
  1081. "fy",
  1082. "gl",
  1083. "gu",
  1084. "ha",
  1085. "hi",
  1086. "hu",
  1087. "hy",
  1088. "ia",
  1089. "it",
  1090. "kk",
  1091. "kn",
  1092. "ku",
  1093. "lb",
  1094. "mai",
  1095. "ml",
  1096. "mn",
  1097. "mr",
  1098. "nah",
  1099. "nap",
  1100. "nb",
  1101. "ne",
  1102. "nl",
  1103. "nn",
  1104. "no",
  1105. "nso",
  1106. "pa",
  1107. "pap",
  1108. "pms",
  1109. "ps",
  1110. "pt-PT",
  1111. "rm",
  1112. "sco",
  1113. "se",
  1114. "si",
  1115. "so",
  1116. "son",
  1117. "sq",
  1118. "sv",
  1119. "sw",
  1120. "ta",
  1121. "te",
  1122. "tk",
  1123. "ur",
  1124. "yo"
  1125. ],
  1126. nr: [
  1127. 1,
  1128. 2
  1129. ],
  1130. fc: 2
  1131. },
  1132. {
  1133. lngs: [
  1134. "ay",
  1135. "bo",
  1136. "cgg",
  1137. "fa",
  1138. "ht",
  1139. "id",
  1140. "ja",
  1141. "jbo",
  1142. "ka",
  1143. "km",
  1144. "ko",
  1145. "ky",
  1146. "lo",
  1147. "ms",
  1148. "sah",
  1149. "su",
  1150. "th",
  1151. "tt",
  1152. "ug",
  1153. "vi",
  1154. "wo",
  1155. "zh"
  1156. ],
  1157. nr: [
  1158. 1
  1159. ],
  1160. fc: 3
  1161. },
  1162. {
  1163. lngs: [
  1164. "be",
  1165. "bs",
  1166. "cnr",
  1167. "dz",
  1168. "hr",
  1169. "ru",
  1170. "sr",
  1171. "uk"
  1172. ],
  1173. nr: [
  1174. 1,
  1175. 2,
  1176. 5
  1177. ],
  1178. fc: 4
  1179. },
  1180. {
  1181. lngs: [
  1182. "ar"
  1183. ],
  1184. nr: [
  1185. 0,
  1186. 1,
  1187. 2,
  1188. 3,
  1189. 11,
  1190. 100
  1191. ],
  1192. fc: 5
  1193. },
  1194. {
  1195. lngs: [
  1196. "cs",
  1197. "sk"
  1198. ],
  1199. nr: [
  1200. 1,
  1201. 2,
  1202. 5
  1203. ],
  1204. fc: 6
  1205. },
  1206. {
  1207. lngs: [
  1208. "csb",
  1209. "pl"
  1210. ],
  1211. nr: [
  1212. 1,
  1213. 2,
  1214. 5
  1215. ],
  1216. fc: 7
  1217. },
  1218. {
  1219. lngs: [
  1220. "cy"
  1221. ],
  1222. nr: [
  1223. 1,
  1224. 2,
  1225. 3,
  1226. 8
  1227. ],
  1228. fc: 8
  1229. },
  1230. {
  1231. lngs: [
  1232. "fr"
  1233. ],
  1234. nr: [
  1235. 1,
  1236. 2
  1237. ],
  1238. fc: 9
  1239. },
  1240. {
  1241. lngs: [
  1242. "ga"
  1243. ],
  1244. nr: [
  1245. 1,
  1246. 2,
  1247. 3,
  1248. 7,
  1249. 11
  1250. ],
  1251. fc: 10
  1252. },
  1253. {
  1254. lngs: [
  1255. "gd"
  1256. ],
  1257. nr: [
  1258. 1,
  1259. 2,
  1260. 3,
  1261. 20
  1262. ],
  1263. fc: 11
  1264. },
  1265. {
  1266. lngs: [
  1267. "is"
  1268. ],
  1269. nr: [
  1270. 1,
  1271. 2
  1272. ],
  1273. fc: 12
  1274. },
  1275. {
  1276. lngs: [
  1277. "jv"
  1278. ],
  1279. nr: [
  1280. 0,
  1281. 1
  1282. ],
  1283. fc: 13
  1284. },
  1285. {
  1286. lngs: [
  1287. "kw"
  1288. ],
  1289. nr: [
  1290. 1,
  1291. 2,
  1292. 3,
  1293. 4
  1294. ],
  1295. fc: 14
  1296. },
  1297. {
  1298. lngs: [
  1299. "lt"
  1300. ],
  1301. nr: [
  1302. 1,
  1303. 2,
  1304. 10
  1305. ],
  1306. fc: 15
  1307. },
  1308. {
  1309. lngs: [
  1310. "lv"
  1311. ],
  1312. nr: [
  1313. 1,
  1314. 2,
  1315. 0
  1316. ],
  1317. fc: 16
  1318. },
  1319. {
  1320. lngs: [
  1321. "mk"
  1322. ],
  1323. nr: [
  1324. 1,
  1325. 2
  1326. ],
  1327. fc: 17
  1328. },
  1329. {
  1330. lngs: [
  1331. "mnk"
  1332. ],
  1333. nr: [
  1334. 0,
  1335. 1,
  1336. 2
  1337. ],
  1338. fc: 18
  1339. },
  1340. {
  1341. lngs: [
  1342. "mt"
  1343. ],
  1344. nr: [
  1345. 1,
  1346. 2,
  1347. 11,
  1348. 20
  1349. ],
  1350. fc: 19
  1351. },
  1352. {
  1353. lngs: [
  1354. "or"
  1355. ],
  1356. nr: [
  1357. 2,
  1358. 1
  1359. ],
  1360. fc: 2
  1361. },
  1362. {
  1363. lngs: [
  1364. "ro"
  1365. ],
  1366. nr: [
  1367. 1,
  1368. 2,
  1369. 20
  1370. ],
  1371. fc: 20
  1372. },
  1373. {
  1374. lngs: [
  1375. "sl"
  1376. ],
  1377. nr: [
  1378. 5,
  1379. 1,
  1380. 2,
  1381. 3
  1382. ],
  1383. fc: 21
  1384. },
  1385. {
  1386. lngs: [
  1387. "he",
  1388. "iw"
  1389. ],
  1390. nr: [
  1391. 1,
  1392. 2,
  1393. 20,
  1394. 21
  1395. ],
  1396. fc: 22
  1397. }
  1398. ];
  1399. var _rulesPluralsTypes = {
  1400. 1: function(n) {
  1401. return Number(n > 1);
  1402. },
  1403. 2: function(n) {
  1404. return Number(n != 1);
  1405. },
  1406. 3: function(n) {
  1407. return 0;
  1408. },
  1409. 4: function(n) {
  1410. return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
  1411. },
  1412. 5: function(n) {
  1413. return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
  1414. },
  1415. 6: function(n) {
  1416. return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
  1417. },
  1418. 7: function(n) {
  1419. return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
  1420. },
  1421. 8: function(n) {
  1422. return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
  1423. },
  1424. 9: function(n) {
  1425. return Number(n >= 2);
  1426. },
  1427. 10: function(n) {
  1428. return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
  1429. },
  1430. 11: function(n) {
  1431. return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
  1432. },
  1433. 12: function(n) {
  1434. return Number(n % 10 != 1 || n % 100 == 11);
  1435. },
  1436. 13: function(n) {
  1437. return Number(n !== 0);
  1438. },
  1439. 14: function(n) {
  1440. return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
  1441. },
  1442. 15: function(n) {
  1443. return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
  1444. },
  1445. 16: function(n) {
  1446. return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
  1447. },
  1448. 17: function(n) {
  1449. return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
  1450. },
  1451. 18: function(n) {
  1452. return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
  1453. },
  1454. 19: function(n) {
  1455. return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
  1456. },
  1457. 20: function(n) {
  1458. return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
  1459. },
  1460. 21: function(n) {
  1461. return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
  1462. },
  1463. 22: function(n) {
  1464. return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
  1465. }
  1466. };
  1467. var nonIntlVersions = [
  1468. "v1",
  1469. "v2",
  1470. "v3"
  1471. ];
  1472. var intlVersions = [
  1473. "v4"
  1474. ];
  1475. var suffixesOrder = {
  1476. zero: 0,
  1477. one: 1,
  1478. two: 2,
  1479. few: 3,
  1480. many: 4,
  1481. other: 5
  1482. };
  1483. function createRules() {
  1484. const rules = {};
  1485. sets.forEach((set)=>{
  1486. set.lngs.forEach((l)=>{
  1487. rules[l] = {
  1488. numbers: set.nr,
  1489. plurals: _rulesPluralsTypes[set.fc]
  1490. };
  1491. });
  1492. });
  1493. return rules;
  1494. }
  1495. var PluralResolver = class {
  1496. addRule(lng, obj) {
  1497. this.rules[lng] = obj;
  1498. }
  1499. getRule(code) {
  1500. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  1501. if (this.shouldUseIntlApi()) {
  1502. try {
  1503. return new Intl.PluralRules(getCleanedCode(code), {
  1504. type: options.ordinal ? "ordinal" : "cardinal"
  1505. });
  1506. } catch (e) {
  1507. return;
  1508. }
  1509. }
  1510. return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
  1511. }
  1512. needsPlural(code) {
  1513. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  1514. const rule = this.getRule(code, options);
  1515. if (this.shouldUseIntlApi()) {
  1516. return rule && rule.resolvedOptions().pluralCategories.length > 1;
  1517. }
  1518. return rule && rule.numbers.length > 1;
  1519. }
  1520. getPluralFormsOfKey(code, key) {
  1521. let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  1522. return this.getSuffixes(code, options).map((suffix)=>`${key}${suffix}`);
  1523. }
  1524. getSuffixes(code) {
  1525. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  1526. const rule = this.getRule(code, options);
  1527. if (!rule) {
  1528. return [];
  1529. }
  1530. if (this.shouldUseIntlApi()) {
  1531. return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2)=>suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory)=>`${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
  1532. }
  1533. return rule.numbers.map((number)=>this.getSuffix(code, number, options));
  1534. }
  1535. getSuffix(code, count) {
  1536. let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  1537. const rule = this.getRule(code, options);
  1538. if (rule) {
  1539. if (this.shouldUseIntlApi()) {
  1540. return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
  1541. }
  1542. return this.getSuffixRetroCompatible(rule, count);
  1543. }
  1544. this.logger.warn(`no plural rule found for: ${code}`);
  1545. return "";
  1546. }
  1547. getSuffixRetroCompatible(rule, count) {
  1548. const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
  1549. let suffix = rule.numbers[idx];
  1550. if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
  1551. if (suffix === 2) {
  1552. suffix = "plural";
  1553. } else if (suffix === 1) {
  1554. suffix = "";
  1555. }
  1556. }
  1557. const returnSuffix = ()=>this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
  1558. if (this.options.compatibilityJSON === "v1") {
  1559. if (suffix === 1) return "";
  1560. if (typeof suffix === "number") return `_plural_${suffix.toString()}`;
  1561. return returnSuffix();
  1562. } else if (this.options.compatibilityJSON === "v2") {
  1563. return returnSuffix();
  1564. } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
  1565. return returnSuffix();
  1566. }
  1567. return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
  1568. }
  1569. shouldUseIntlApi() {
  1570. return !nonIntlVersions.includes(this.options.compatibilityJSON);
  1571. }
  1572. constructor(languageUtils){
  1573. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  1574. this.languageUtils = languageUtils;
  1575. this.options = options;
  1576. this.logger = baseLogger.create("pluralResolver");
  1577. if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
  1578. this.options.compatibilityJSON = "v3";
  1579. this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
  1580. }
  1581. this.rules = createRules();
  1582. }
  1583. };
  1584. function deepFindWithDefaults(data, defaultData, key) {
  1585. let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
  1586. let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
  1587. let path = getPathWithDefaults(data, defaultData, key);
  1588. if (!path && ignoreJSONStructure && typeof key === "string") {
  1589. path = deepFind(data, key, keySeparator);
  1590. if (path === void 0) path = deepFind(defaultData, key, keySeparator);
  1591. }
  1592. return path;
  1593. }
  1594. var Interpolator = class {
  1595. init() {
  1596. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  1597. if (!options.interpolation) options.interpolation = {
  1598. escapeValue: true
  1599. };
  1600. const iOpts = options.interpolation;
  1601. this.escape = iOpts.escape !== void 0 ? iOpts.escape : escape;
  1602. this.escapeValue = iOpts.escapeValue !== void 0 ? iOpts.escapeValue : true;
  1603. this.useRawValueToEscape = iOpts.useRawValueToEscape !== void 0 ? iOpts.useRawValueToEscape : false;
  1604. this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || "{{";
  1605. this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || "}}";
  1606. this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ",";
  1607. this.unescapePrefix = iOpts.unescapeSuffix ? "" : iOpts.unescapePrefix || "-";
  1608. this.unescapeSuffix = this.unescapePrefix ? "" : iOpts.unescapeSuffix || "";
  1609. this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape("$t(");
  1610. this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(")");
  1611. this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ",";
  1612. this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1e3;
  1613. this.alwaysFormat = iOpts.alwaysFormat !== void 0 ? iOpts.alwaysFormat : false;
  1614. this.resetRegExp();
  1615. }
  1616. reset() {
  1617. if (this.options) this.init(this.options);
  1618. }
  1619. resetRegExp() {
  1620. const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
  1621. this.regexp = new RegExp(regexpStr, "g");
  1622. const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
  1623. this.regexpUnescape = new RegExp(regexpUnescapeStr, "g");
  1624. const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
  1625. this.nestingRegexp = new RegExp(nestingRegexpStr, "g");
  1626. }
  1627. interpolate(str, data, lng, options) {
  1628. let match;
  1629. let value;
  1630. let replaces;
  1631. const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
  1632. function regexSafe(val) {
  1633. return val.replace(/\$/g, "$$$$");
  1634. }
  1635. const handleFormat = (key)=>{
  1636. if (key.indexOf(this.formatSeparator) < 0) {
  1637. const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
  1638. return this.alwaysFormat ? this.format(path, void 0, lng, _objectSpreadProps(_objectSpread({}, options, data), {
  1639. interpolationkey: key
  1640. })) : path;
  1641. }
  1642. const p = key.split(this.formatSeparator);
  1643. const k = p.shift().trim();
  1644. const f = p.join(this.formatSeparator).trim();
  1645. return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, _objectSpreadProps(_objectSpread({}, options, data), {
  1646. interpolationkey: k
  1647. }));
  1648. };
  1649. this.resetRegExp();
  1650. const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
  1651. const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
  1652. const todos = [
  1653. {
  1654. regex: this.regexpUnescape,
  1655. safeValue: (val)=>regexSafe(val)
  1656. },
  1657. {
  1658. regex: this.regexp,
  1659. safeValue: (val)=>this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
  1660. }
  1661. ];
  1662. todos.forEach((todo)=>{
  1663. replaces = 0;
  1664. while(match = todo.regex.exec(str)){
  1665. const matchedVar = match[1].trim();
  1666. value = handleFormat(matchedVar);
  1667. if (value === void 0) {
  1668. if (typeof missingInterpolationHandler === "function") {
  1669. const temp = missingInterpolationHandler(str, match, options);
  1670. value = typeof temp === "string" ? temp : "";
  1671. } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
  1672. value = "";
  1673. } else if (skipOnVariables) {
  1674. value = match[0];
  1675. continue;
  1676. } else {
  1677. this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
  1678. value = "";
  1679. }
  1680. } else if (typeof value !== "string" && !this.useRawValueToEscape) {
  1681. value = makeString(value);
  1682. }
  1683. const safeValue = todo.safeValue(value);
  1684. str = str.replace(match[0], safeValue);
  1685. if (skipOnVariables) {
  1686. todo.regex.lastIndex += value.length;
  1687. todo.regex.lastIndex -= match[0].length;
  1688. } else {
  1689. todo.regex.lastIndex = 0;
  1690. }
  1691. replaces++;
  1692. if (replaces >= this.maxReplaces) {
  1693. break;
  1694. }
  1695. }
  1696. });
  1697. return str;
  1698. }
  1699. nest(str, fc) {
  1700. let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  1701. let match;
  1702. let value;
  1703. let clonedOptions;
  1704. function handleHasOptions(key, inheritedOptions) {
  1705. const sep = this.nestingOptionsSeparator;
  1706. if (key.indexOf(sep) < 0) return key;
  1707. const c = key.split(new RegExp(`${sep}[ ]*{`));
  1708. let optionsString = `{${c[1]}`;
  1709. key = c[0];
  1710. optionsString = this.interpolate(optionsString, clonedOptions);
  1711. const matchedSingleQuotes = optionsString.match(/'/g);
  1712. const matchedDoubleQuotes = optionsString.match(/"/g);
  1713. if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
  1714. optionsString = optionsString.replace(/'/g, '"');
  1715. }
  1716. try {
  1717. clonedOptions = JSON.parse(optionsString);
  1718. if (inheritedOptions) clonedOptions = _objectSpread({}, inheritedOptions, clonedOptions);
  1719. } catch (e) {
  1720. this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
  1721. return `${key}${sep}${optionsString}`;
  1722. }
  1723. delete clonedOptions.defaultValue;
  1724. return key;
  1725. }
  1726. while(match = this.nestingRegexp.exec(str)){
  1727. let formatters = [];
  1728. clonedOptions = _objectSpread({}, options);
  1729. clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== "string" ? clonedOptions.replace : clonedOptions;
  1730. clonedOptions.applyPostProcessor = false;
  1731. delete clonedOptions.defaultValue;
  1732. let doReduce = false;
  1733. if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
  1734. const r = match[1].split(this.formatSeparator).map((elem)=>elem.trim());
  1735. match[1] = r.shift();
  1736. formatters = r;
  1737. doReduce = true;
  1738. }
  1739. value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
  1740. if (value && match[0] === str && typeof value !== "string") return value;
  1741. if (typeof value !== "string") value = makeString(value);
  1742. if (!value) {
  1743. this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
  1744. value = "";
  1745. }
  1746. if (doReduce) {
  1747. value = formatters.reduce((v, f)=>this.format(v, f, options.lng, _objectSpreadProps(_objectSpread({}, options), {
  1748. interpolationkey: match[1].trim()
  1749. })), value.trim());
  1750. }
  1751. str = str.replace(match[0], value);
  1752. this.regexp.lastIndex = 0;
  1753. }
  1754. return str;
  1755. }
  1756. constructor(){
  1757. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  1758. this.logger = baseLogger.create("interpolator");
  1759. this.options = options;
  1760. this.format = options.interpolation && options.interpolation.format || ((value)=>value);
  1761. this.init(options);
  1762. }
  1763. };
  1764. function parseFormatStr(formatStr) {
  1765. let formatName = formatStr.toLowerCase().trim();
  1766. const formatOptions = {};
  1767. if (formatStr.indexOf("(") > -1) {
  1768. const p = formatStr.split("(");
  1769. formatName = p[0].toLowerCase().trim();
  1770. const optStr = p[1].substring(0, p[1].length - 1);
  1771. if (formatName === "currency" && optStr.indexOf(":") < 0) {
  1772. if (!formatOptions.currency) formatOptions.currency = optStr.trim();
  1773. } else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
  1774. if (!formatOptions.range) formatOptions.range = optStr.trim();
  1775. } else {
  1776. const opts = optStr.split(";");
  1777. opts.forEach((opt)=>{
  1778. if (!opt) return;
  1779. const [key, ...rest] = opt.split(":");
  1780. const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
  1781. if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
  1782. if (val === "false") formatOptions[key.trim()] = false;
  1783. if (val === "true") formatOptions[key.trim()] = true;
  1784. if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
  1785. });
  1786. }
  1787. }
  1788. return {
  1789. formatName,
  1790. formatOptions
  1791. };
  1792. }
  1793. function createCachedFormatter(fn) {
  1794. const cache = {};
  1795. return function invokeFormatter(val, lng, options) {
  1796. const key = lng + JSON.stringify(options);
  1797. let formatter = cache[key];
  1798. if (!formatter) {
  1799. formatter = fn(getCleanedCode(lng), options);
  1800. cache[key] = formatter;
  1801. }
  1802. return formatter(val);
  1803. };
  1804. }
  1805. var Formatter = class {
  1806. init(services) {
  1807. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
  1808. interpolation: {}
  1809. };
  1810. const iOpts = options.interpolation;
  1811. this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ",";
  1812. }
  1813. add(name, fc) {
  1814. this.formats[name.toLowerCase().trim()] = fc;
  1815. }
  1816. addCached(name, fc) {
  1817. this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
  1818. }
  1819. format(value, format, lng) {
  1820. let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
  1821. const formats = format.split(this.formatSeparator);
  1822. const result = formats.reduce((mem, f)=>{
  1823. const { formatName , formatOptions } = parseFormatStr(f);
  1824. if (this.formats[formatName]) {
  1825. let formatted = mem;
  1826. try {
  1827. const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
  1828. const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
  1829. formatted = this.formats[formatName](mem, l, _objectSpread({}, formatOptions, options, valOptions));
  1830. } catch (error) {
  1831. this.logger.warn(error);
  1832. }
  1833. return formatted;
  1834. } else {
  1835. this.logger.warn(`there was no format function for ${formatName}`);
  1836. }
  1837. return mem;
  1838. }, value);
  1839. return result;
  1840. }
  1841. constructor(){
  1842. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  1843. this.logger = baseLogger.create("formatter");
  1844. this.options = options;
  1845. this.formats = {
  1846. number: createCachedFormatter((lng, opt)=>{
  1847. const formatter = new Intl.NumberFormat(lng, _objectSpread({}, opt));
  1848. return (val)=>formatter.format(val);
  1849. }),
  1850. currency: createCachedFormatter((lng, opt)=>{
  1851. const formatter = new Intl.NumberFormat(lng, _objectSpreadProps(_objectSpread({}, opt), {
  1852. style: "currency"
  1853. }));
  1854. return (val)=>formatter.format(val);
  1855. }),
  1856. datetime: createCachedFormatter((lng, opt)=>{
  1857. const formatter = new Intl.DateTimeFormat(lng, _objectSpread({}, opt));
  1858. return (val)=>formatter.format(val);
  1859. }),
  1860. relativetime: createCachedFormatter((lng, opt)=>{
  1861. const formatter = new Intl.RelativeTimeFormat(lng, _objectSpread({}, opt));
  1862. return (val)=>formatter.format(val, opt.range || "day");
  1863. }),
  1864. list: createCachedFormatter((lng, opt)=>{
  1865. const formatter = new Intl.ListFormat(lng, _objectSpread({}, opt));
  1866. return (val)=>formatter.format(val);
  1867. })
  1868. };
  1869. this.init(options);
  1870. }
  1871. };
  1872. function removePending(q, name) {
  1873. if (q.pending[name] !== void 0) {
  1874. delete q.pending[name];
  1875. q.pendingCount--;
  1876. }
  1877. }
  1878. var Connector = class extends EventEmitter {
  1879. queueLoad(languages, namespaces, options, callback) {
  1880. const toLoad = {};
  1881. const pending = {};
  1882. const toLoadLanguages = {};
  1883. const toLoadNamespaces = {};
  1884. languages.forEach((lng)=>{
  1885. let hasAllNamespaces = true;
  1886. namespaces.forEach((ns)=>{
  1887. const name = `${lng}|${ns}`;
  1888. if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
  1889. this.state[name] = 2;
  1890. } else if (this.state[name] < 0) ;
  1891. else if (this.state[name] === 1) {
  1892. if (pending[name] === void 0) pending[name] = true;
  1893. } else {
  1894. this.state[name] = 1;
  1895. hasAllNamespaces = false;
  1896. if (pending[name] === void 0) pending[name] = true;
  1897. if (toLoad[name] === void 0) toLoad[name] = true;
  1898. if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
  1899. }
  1900. });
  1901. if (!hasAllNamespaces) toLoadLanguages[lng] = true;
  1902. });
  1903. if (Object.keys(toLoad).length || Object.keys(pending).length) {
  1904. this.queue.push({
  1905. pending,
  1906. pendingCount: Object.keys(pending).length,
  1907. loaded: {},
  1908. errors: [],
  1909. callback
  1910. });
  1911. }
  1912. return {
  1913. toLoad: Object.keys(toLoad),
  1914. pending: Object.keys(pending),
  1915. toLoadLanguages: Object.keys(toLoadLanguages),
  1916. toLoadNamespaces: Object.keys(toLoadNamespaces)
  1917. };
  1918. }
  1919. loaded(name, err, data) {
  1920. const s = name.split("|");
  1921. const lng = s[0];
  1922. const ns = s[1];
  1923. if (err) this.emit("failedLoading", lng, ns, err);
  1924. if (data) {
  1925. this.store.addResourceBundle(lng, ns, data);
  1926. }
  1927. this.state[name] = err ? -1 : 2;
  1928. const loaded = {};
  1929. this.queue.forEach((q)=>{
  1930. pushPath(q.loaded, [
  1931. lng
  1932. ], ns);
  1933. removePending(q, name);
  1934. if (err) q.errors.push(err);
  1935. if (q.pendingCount === 0 && !q.done) {
  1936. Object.keys(q.loaded).forEach((l)=>{
  1937. if (!loaded[l]) loaded[l] = {};
  1938. const loadedKeys = q.loaded[l];
  1939. if (loadedKeys.length) {
  1940. loadedKeys.forEach((n)=>{
  1941. if (loaded[l][n] === void 0) loaded[l][n] = true;
  1942. });
  1943. }
  1944. });
  1945. q.done = true;
  1946. if (q.errors.length) {
  1947. q.callback(q.errors);
  1948. } else {
  1949. q.callback();
  1950. }
  1951. }
  1952. });
  1953. this.emit("loaded", loaded);
  1954. this.queue = this.queue.filter((q)=>!q.done);
  1955. }
  1956. read(lng, ns, fcName) {
  1957. let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
  1958. let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
  1959. let callback = arguments.length > 5 ? arguments[5] : void 0;
  1960. if (!lng.length) return callback(null, {});
  1961. if (this.readingCalls >= this.maxParallelReads) {
  1962. this.waitingReads.push({
  1963. lng,
  1964. ns,
  1965. fcName,
  1966. tried,
  1967. wait,
  1968. callback
  1969. });
  1970. return;
  1971. }
  1972. this.readingCalls++;
  1973. const resolver = (err, data)=>{
  1974. this.readingCalls--;
  1975. if (this.waitingReads.length > 0) {
  1976. const next = this.waitingReads.shift();
  1977. this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
  1978. }
  1979. if (err && data && tried < this.maxRetries) {
  1980. setTimeout(()=>{
  1981. this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
  1982. }, wait);
  1983. return;
  1984. }
  1985. callback(err, data);
  1986. };
  1987. const fc = this.backend[fcName].bind(this.backend);
  1988. if (fc.length === 2) {
  1989. try {
  1990. const r = fc(lng, ns);
  1991. if (r && typeof r.then === "function") {
  1992. r.then((data)=>resolver(null, data)).catch(resolver);
  1993. } else {
  1994. resolver(null, r);
  1995. }
  1996. } catch (err) {
  1997. resolver(err);
  1998. }
  1999. return;
  2000. }
  2001. return fc(lng, ns, resolver);
  2002. }
  2003. prepareLoading(languages, namespaces) {
  2004. let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  2005. let callback = arguments.length > 3 ? arguments[3] : void 0;
  2006. if (!this.backend) {
  2007. this.logger.warn("No backend was added via i18next.use. Will not load resources.");
  2008. return callback && callback();
  2009. }
  2010. if (typeof languages === "string") languages = this.languageUtils.toResolveHierarchy(languages);
  2011. if (typeof namespaces === "string") namespaces = [
  2012. namespaces
  2013. ];
  2014. const toLoad = this.queueLoad(languages, namespaces, options, callback);
  2015. if (!toLoad.toLoad.length) {
  2016. if (!toLoad.pending.length) callback();
  2017. return null;
  2018. }
  2019. toLoad.toLoad.forEach((name)=>{
  2020. this.loadOne(name);
  2021. });
  2022. }
  2023. load(languages, namespaces, callback) {
  2024. this.prepareLoading(languages, namespaces, {}, callback);
  2025. }
  2026. reload(languages, namespaces, callback) {
  2027. this.prepareLoading(languages, namespaces, {
  2028. reload: true
  2029. }, callback);
  2030. }
  2031. loadOne(name) {
  2032. let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
  2033. const s = name.split("|");
  2034. const lng = s[0];
  2035. const ns = s[1];
  2036. this.read(lng, ns, "read", void 0, void 0, (err, data)=>{
  2037. if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
  2038. if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
  2039. this.loaded(name, err, data);
  2040. });
  2041. }
  2042. saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
  2043. let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
  2044. let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : ()=>{};
  2045. if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
  2046. this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
  2047. return;
  2048. }
  2049. if (key === void 0 || key === null || key === "") return;
  2050. if (this.backend && this.backend.create) {
  2051. const opts = _objectSpreadProps(_objectSpread({}, options), {
  2052. isUpdate
  2053. });
  2054. const fc = this.backend.create.bind(this.backend);
  2055. if (fc.length < 6) {
  2056. try {
  2057. let r;
  2058. if (fc.length === 5) {
  2059. r = fc(languages, namespace, key, fallbackValue, opts);
  2060. } else {
  2061. r = fc(languages, namespace, key, fallbackValue);
  2062. }
  2063. if (r && typeof r.then === "function") {
  2064. r.then((data)=>clb(null, data)).catch(clb);
  2065. } else {
  2066. clb(null, r);
  2067. }
  2068. } catch (err) {
  2069. clb(err);
  2070. }
  2071. } else {
  2072. fc(languages, namespace, key, fallbackValue, clb, opts);
  2073. }
  2074. }
  2075. if (!languages || !languages[0]) return;
  2076. this.store.addResource(languages[0], namespace, key, fallbackValue);
  2077. }
  2078. constructor(backend, store, services){
  2079. let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
  2080. super();
  2081. this.backend = backend;
  2082. this.store = store;
  2083. this.services = services;
  2084. this.languageUtils = services.languageUtils;
  2085. this.options = options;
  2086. this.logger = baseLogger.create("backendConnector");
  2087. this.waitingReads = [];
  2088. this.maxParallelReads = options.maxParallelReads || 10;
  2089. this.readingCalls = 0;
  2090. this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
  2091. this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
  2092. this.state = {};
  2093. this.queue = [];
  2094. if (this.backend && this.backend.init) {
  2095. this.backend.init(services, options.backend, options);
  2096. }
  2097. }
  2098. };
  2099. function get() {
  2100. return {
  2101. debug: false,
  2102. initImmediate: true,
  2103. ns: [
  2104. "translation"
  2105. ],
  2106. defaultNS: [
  2107. "translation"
  2108. ],
  2109. fallbackLng: [
  2110. "dev"
  2111. ],
  2112. fallbackNS: false,
  2113. supportedLngs: false,
  2114. nonExplicitSupportedLngs: false,
  2115. load: "all",
  2116. preload: false,
  2117. simplifyPluralSuffix: true,
  2118. keySeparator: ".",
  2119. nsSeparator: ":",
  2120. pluralSeparator: "_",
  2121. contextSeparator: "_",
  2122. partialBundledLanguages: false,
  2123. saveMissing: false,
  2124. updateMissing: false,
  2125. saveMissingTo: "fallback",
  2126. saveMissingPlurals: true,
  2127. missingKeyHandler: false,
  2128. missingInterpolationHandler: false,
  2129. postProcess: false,
  2130. postProcessPassResolved: false,
  2131. returnNull: false,
  2132. returnEmptyString: true,
  2133. returnObjects: false,
  2134. joinArrays: false,
  2135. returnedObjectHandler: false,
  2136. parseMissingKeyHandler: false,
  2137. appendNamespaceToMissingKey: false,
  2138. appendNamespaceToCIMode: false,
  2139. overloadTranslationOptionHandler: function handle(args) {
  2140. let ret = {};
  2141. if (typeof args[1] === "object") ret = args[1];
  2142. if (typeof args[1] === "string") ret.defaultValue = args[1];
  2143. if (typeof args[2] === "string") ret.tDescription = args[2];
  2144. if (typeof args[2] === "object" || typeof args[3] === "object") {
  2145. const options = args[3] || args[2];
  2146. Object.keys(options).forEach((key)=>{
  2147. ret[key] = options[key];
  2148. });
  2149. }
  2150. return ret;
  2151. },
  2152. interpolation: {
  2153. escapeValue: true,
  2154. format: (value, format, lng, options)=>value,
  2155. prefix: "{{",
  2156. suffix: "}}",
  2157. formatSeparator: ",",
  2158. unescapePrefix: "-",
  2159. nestingPrefix: "$t(",
  2160. nestingSuffix: ")",
  2161. nestingOptionsSeparator: ",",
  2162. maxReplaces: 1e3,
  2163. skipOnVariables: true
  2164. }
  2165. };
  2166. }
  2167. function transformOptions(options) {
  2168. if (typeof options.ns === "string") options.ns = [
  2169. options.ns
  2170. ];
  2171. if (typeof options.fallbackLng === "string") options.fallbackLng = [
  2172. options.fallbackLng
  2173. ];
  2174. if (typeof options.fallbackNS === "string") options.fallbackNS = [
  2175. options.fallbackNS
  2176. ];
  2177. if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
  2178. options.supportedLngs = options.supportedLngs.concat([
  2179. "cimode"
  2180. ]);
  2181. }
  2182. return options;
  2183. }
  2184. function noop() {}
  2185. function bindMemberFunctions(inst) {
  2186. const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
  2187. mems.forEach((mem)=>{
  2188. if (typeof inst[mem] === "function") {
  2189. inst[mem] = inst[mem].bind(inst);
  2190. }
  2191. });
  2192. }
  2193. var I18n = class extends EventEmitter {
  2194. init() {
  2195. var _this = this;
  2196. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  2197. let callback = arguments.length > 1 ? arguments[1] : void 0;
  2198. if (typeof options === "function") {
  2199. callback = options;
  2200. options = {};
  2201. }
  2202. if (!options.defaultNS && options.defaultNS !== false && options.ns) {
  2203. if (typeof options.ns === "string") {
  2204. options.defaultNS = options.ns;
  2205. } else if (options.ns.indexOf("translation") < 0) {
  2206. options.defaultNS = options.ns[0];
  2207. }
  2208. }
  2209. const defOpts = get();
  2210. this.options = _objectSpread({}, defOpts, this.options, transformOptions(options));
  2211. if (this.options.compatibilityAPI !== "v1") {
  2212. this.options.interpolation = _objectSpread({}, defOpts.interpolation, this.options.interpolation);
  2213. }
  2214. if (options.keySeparator !== void 0) {
  2215. this.options.userDefinedKeySeparator = options.keySeparator;
  2216. }
  2217. if (options.nsSeparator !== void 0) {
  2218. this.options.userDefinedNsSeparator = options.nsSeparator;
  2219. }
  2220. function createClassOnDemand(ClassOrObject) {
  2221. if (!ClassOrObject) return null;
  2222. if (typeof ClassOrObject === "function") return new ClassOrObject();
  2223. return ClassOrObject;
  2224. }
  2225. if (!this.options.isClone) {
  2226. if (this.modules.logger) {
  2227. baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
  2228. } else {
  2229. baseLogger.init(null, this.options);
  2230. }
  2231. let formatter;
  2232. if (this.modules.formatter) {
  2233. formatter = this.modules.formatter;
  2234. } else if (typeof Intl !== "undefined") {
  2235. formatter = Formatter;
  2236. }
  2237. const lu = new LanguageUtil(this.options);
  2238. this.store = new ResourceStore(this.options.resources, this.options);
  2239. const s = this.services;
  2240. s.logger = baseLogger;
  2241. s.resourceStore = this.store;
  2242. s.languageUtils = lu;
  2243. s.pluralResolver = new PluralResolver(lu, {
  2244. prepend: this.options.pluralSeparator,
  2245. compatibilityJSON: this.options.compatibilityJSON,
  2246. simplifyPluralSuffix: this.options.simplifyPluralSuffix
  2247. });
  2248. if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
  2249. s.formatter = createClassOnDemand(formatter);
  2250. s.formatter.init(s, this.options);
  2251. this.options.interpolation.format = s.formatter.format.bind(s.formatter);
  2252. }
  2253. s.interpolator = new Interpolator(this.options);
  2254. s.utils = {
  2255. hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
  2256. };
  2257. s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
  2258. s.backendConnector.on("*", function(event) {
  2259. for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
  2260. args[_key - 1] = arguments[_key];
  2261. }
  2262. _this.emit(event, ...args);
  2263. });
  2264. if (this.modules.languageDetector) {
  2265. s.languageDetector = createClassOnDemand(this.modules.languageDetector);
  2266. if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
  2267. }
  2268. if (this.modules.i18nFormat) {
  2269. s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
  2270. if (s.i18nFormat.init) s.i18nFormat.init(this);
  2271. }
  2272. this.translator = new Translator(this.services, this.options);
  2273. this.translator.on("*", function(event) {
  2274. for(var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++){
  2275. args[_key2 - 1] = arguments[_key2];
  2276. }
  2277. _this.emit(event, ...args);
  2278. });
  2279. this.modules.external.forEach((m)=>{
  2280. if (m.init) m.init(this);
  2281. });
  2282. }
  2283. this.format = this.options.interpolation.format;
  2284. if (!callback) callback = noop;
  2285. if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
  2286. const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
  2287. if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
  2288. }
  2289. if (!this.services.languageDetector && !this.options.lng) {
  2290. this.logger.warn("init: no languageDetector is used and no lng is defined");
  2291. }
  2292. const storeApi = [
  2293. "getResource",
  2294. "hasResourceBundle",
  2295. "getResourceBundle",
  2296. "getDataByLanguage"
  2297. ];
  2298. storeApi.forEach((fcName)=>{
  2299. this[fcName] = function() {
  2300. return _this.store[fcName](...arguments);
  2301. };
  2302. });
  2303. const storeApiChained = [
  2304. "addResource",
  2305. "addResources",
  2306. "addResourceBundle",
  2307. "removeResourceBundle"
  2308. ];
  2309. storeApiChained.forEach((fcName)=>{
  2310. this[fcName] = function() {
  2311. _this.store[fcName](...arguments);
  2312. return _this;
  2313. };
  2314. });
  2315. const deferred = defer();
  2316. const load = ()=>{
  2317. const finish = (err, t2)=>{
  2318. if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
  2319. this.isInitialized = true;
  2320. if (!this.options.isClone) this.logger.log("initialized", this.options);
  2321. this.emit("initialized", this.options);
  2322. deferred.resolve(t2);
  2323. callback(err, t2);
  2324. };
  2325. if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized) return finish(null, this.t.bind(this));
  2326. this.changeLanguage(this.options.lng, finish);
  2327. };
  2328. if (this.options.resources || !this.options.initImmediate) {
  2329. load();
  2330. } else {
  2331. setTimeout(load, 0);
  2332. }
  2333. return deferred;
  2334. }
  2335. loadResources(language) {
  2336. let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
  2337. let usedCallback = callback;
  2338. const usedLng = typeof language === "string" ? language : this.language;
  2339. if (typeof language === "function") usedCallback = language;
  2340. if (!this.options.resources || this.options.partialBundledLanguages) {
  2341. if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
  2342. const toLoad = [];
  2343. const append = (lng)=>{
  2344. if (!lng) return;
  2345. if (lng === "cimode") return;
  2346. const lngs = this.services.languageUtils.toResolveHierarchy(lng);
  2347. lngs.forEach((l)=>{
  2348. if (l === "cimode") return;
  2349. if (toLoad.indexOf(l) < 0) toLoad.push(l);
  2350. });
  2351. };
  2352. if (!usedLng) {
  2353. const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
  2354. fallbacks.forEach((l)=>append(l));
  2355. } else {
  2356. append(usedLng);
  2357. }
  2358. if (this.options.preload) {
  2359. this.options.preload.forEach((l)=>append(l));
  2360. }
  2361. this.services.backendConnector.load(toLoad, this.options.ns, (e)=>{
  2362. if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
  2363. usedCallback(e);
  2364. });
  2365. } else {
  2366. usedCallback(null);
  2367. }
  2368. }
  2369. reloadResources(lngs, ns, callback) {
  2370. const deferred = defer();
  2371. if (!lngs) lngs = this.languages;
  2372. if (!ns) ns = this.options.ns;
  2373. if (!callback) callback = noop;
  2374. this.services.backendConnector.reload(lngs, ns, (err)=>{
  2375. deferred.resolve();
  2376. callback(err);
  2377. });
  2378. return deferred;
  2379. }
  2380. use(module) {
  2381. if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
  2382. if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
  2383. if (module.type === "backend") {
  2384. this.modules.backend = module;
  2385. }
  2386. if (module.type === "logger" || module.log && module.warn && module.error) {
  2387. this.modules.logger = module;
  2388. }
  2389. if (module.type === "languageDetector") {
  2390. this.modules.languageDetector = module;
  2391. }
  2392. if (module.type === "i18nFormat") {
  2393. this.modules.i18nFormat = module;
  2394. }
  2395. if (module.type === "postProcessor") {
  2396. postProcessor.addPostProcessor(module);
  2397. }
  2398. if (module.type === "formatter") {
  2399. this.modules.formatter = module;
  2400. }
  2401. if (module.type === "3rdParty") {
  2402. this.modules.external.push(module);
  2403. }
  2404. return this;
  2405. }
  2406. setResolvedLanguage(l) {
  2407. if (!l || !this.languages) return;
  2408. if ([
  2409. "cimode",
  2410. "dev"
  2411. ].indexOf(l) > -1) return;
  2412. for(let li = 0; li < this.languages.length; li++){
  2413. const lngInLngs = this.languages[li];
  2414. if ([
  2415. "cimode",
  2416. "dev"
  2417. ].indexOf(lngInLngs) > -1) continue;
  2418. if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
  2419. this.resolvedLanguage = lngInLngs;
  2420. break;
  2421. }
  2422. }
  2423. }
  2424. changeLanguage(lng, callback) {
  2425. var _this2 = this;
  2426. this.isLanguageChangingTo = lng;
  2427. const deferred = defer();
  2428. this.emit("languageChanging", lng);
  2429. const setLngProps = (l)=>{
  2430. this.language = l;
  2431. this.languages = this.services.languageUtils.toResolveHierarchy(l);
  2432. this.resolvedLanguage = void 0;
  2433. this.setResolvedLanguage(l);
  2434. };
  2435. const done = (err, l)=>{
  2436. if (l) {
  2437. setLngProps(l);
  2438. this.translator.changeLanguage(l);
  2439. this.isLanguageChangingTo = void 0;
  2440. this.emit("languageChanged", l);
  2441. this.logger.log("languageChanged", l);
  2442. } else {
  2443. this.isLanguageChangingTo = void 0;
  2444. }
  2445. deferred.resolve(function() {
  2446. return _this2.t(...arguments);
  2447. });
  2448. if (callback) callback(err, function() {
  2449. return _this2.t(...arguments);
  2450. });
  2451. };
  2452. const setLng = (lngs)=>{
  2453. if (!lng && !lngs && this.services.languageDetector) lngs = [];
  2454. const l = typeof lngs === "string" ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
  2455. if (l) {
  2456. if (!this.language) {
  2457. setLngProps(l);
  2458. }
  2459. if (!this.translator.language) this.translator.changeLanguage(l);
  2460. if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
  2461. }
  2462. this.loadResources(l, (err)=>{
  2463. done(err, l);
  2464. });
  2465. };
  2466. if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
  2467. setLng(this.services.languageDetector.detect());
  2468. } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
  2469. if (this.services.languageDetector.detect.length === 0) {
  2470. this.services.languageDetector.detect().then(setLng);
  2471. } else {
  2472. this.services.languageDetector.detect(setLng);
  2473. }
  2474. } else {
  2475. setLng(lng);
  2476. }
  2477. return deferred;
  2478. }
  2479. getFixedT(lng, ns, keyPrefix) {
  2480. var _this3 = this;
  2481. const fixedT = function(key, opts) {
  2482. let options;
  2483. if (typeof opts !== "object") {
  2484. for(var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++){
  2485. rest[_key3 - 2] = arguments[_key3];
  2486. }
  2487. options = _this3.options.overloadTranslationOptionHandler([
  2488. key,
  2489. opts
  2490. ].concat(rest));
  2491. } else {
  2492. options = _objectSpread({}, opts);
  2493. }
  2494. options.lng = options.lng || fixedT.lng;
  2495. options.lngs = options.lngs || fixedT.lngs;
  2496. options.ns = options.ns || fixedT.ns;
  2497. options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
  2498. const keySeparator = _this3.options.keySeparator || ".";
  2499. let resultKey;
  2500. if (options.keyPrefix && Array.isArray(key)) {
  2501. resultKey = key.map((k)=>`${options.keyPrefix}${keySeparator}${k}`);
  2502. } else {
  2503. resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
  2504. }
  2505. return _this3.t(resultKey, options);
  2506. };
  2507. if (typeof lng === "string") {
  2508. fixedT.lng = lng;
  2509. } else {
  2510. fixedT.lngs = lng;
  2511. }
  2512. fixedT.ns = ns;
  2513. fixedT.keyPrefix = keyPrefix;
  2514. return fixedT;
  2515. }
  2516. t() {
  2517. return this.translator && this.translator.translate(...arguments);
  2518. }
  2519. exists() {
  2520. return this.translator && this.translator.exists(...arguments);
  2521. }
  2522. setDefaultNamespace(ns) {
  2523. this.options.defaultNS = ns;
  2524. }
  2525. hasLoadedNamespace(ns) {
  2526. let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  2527. if (!this.isInitialized) {
  2528. this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
  2529. return false;
  2530. }
  2531. if (!this.languages || !this.languages.length) {
  2532. this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
  2533. return false;
  2534. }
  2535. const lng = options.lng || this.resolvedLanguage || this.languages[0];
  2536. const fallbackLng = this.options ? this.options.fallbackLng : false;
  2537. const lastLng = this.languages[this.languages.length - 1];
  2538. if (lng.toLowerCase() === "cimode") return true;
  2539. const loadNotPending = (l, n)=>{
  2540. const loadState = this.services.backendConnector.state[`${l}|${n}`];
  2541. return loadState === -1 || loadState === 2;
  2542. };
  2543. if (options.precheck) {
  2544. const preResult = options.precheck(this, loadNotPending);
  2545. if (preResult !== void 0) return preResult;
  2546. }
  2547. if (this.hasResourceBundle(lng, ns)) return true;
  2548. if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
  2549. if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
  2550. return false;
  2551. }
  2552. loadNamespaces(ns, callback) {
  2553. const deferred = defer();
  2554. if (!this.options.ns) {
  2555. if (callback) callback();
  2556. return Promise.resolve();
  2557. }
  2558. if (typeof ns === "string") ns = [
  2559. ns
  2560. ];
  2561. ns.forEach((n)=>{
  2562. if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
  2563. });
  2564. this.loadResources((err)=>{
  2565. deferred.resolve();
  2566. if (callback) callback(err);
  2567. });
  2568. return deferred;
  2569. }
  2570. loadLanguages(lngs, callback) {
  2571. const deferred = defer();
  2572. if (typeof lngs === "string") lngs = [
  2573. lngs
  2574. ];
  2575. const preloaded = this.options.preload || [];
  2576. const newLngs = lngs.filter((lng)=>preloaded.indexOf(lng) < 0);
  2577. if (!newLngs.length) {
  2578. if (callback) callback();
  2579. return Promise.resolve();
  2580. }
  2581. this.options.preload = preloaded.concat(newLngs);
  2582. this.loadResources((err)=>{
  2583. deferred.resolve();
  2584. if (callback) callback(err);
  2585. });
  2586. return deferred;
  2587. }
  2588. dir(lng) {
  2589. if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
  2590. if (!lng) return "rtl";
  2591. const rtlLngs = [
  2592. "ar",
  2593. "shu",
  2594. "sqr",
  2595. "ssh",
  2596. "xaa",
  2597. "yhd",
  2598. "yud",
  2599. "aao",
  2600. "abh",
  2601. "abv",
  2602. "acm",
  2603. "acq",
  2604. "acw",
  2605. "acx",
  2606. "acy",
  2607. "adf",
  2608. "ads",
  2609. "aeb",
  2610. "aec",
  2611. "afb",
  2612. "ajp",
  2613. "apc",
  2614. "apd",
  2615. "arb",
  2616. "arq",
  2617. "ars",
  2618. "ary",
  2619. "arz",
  2620. "auz",
  2621. "avl",
  2622. "ayh",
  2623. "ayl",
  2624. "ayn",
  2625. "ayp",
  2626. "bbz",
  2627. "pga",
  2628. "he",
  2629. "iw",
  2630. "ps",
  2631. "pbt",
  2632. "pbu",
  2633. "pst",
  2634. "prp",
  2635. "prd",
  2636. "ug",
  2637. "ur",
  2638. "ydd",
  2639. "yds",
  2640. "yih",
  2641. "ji",
  2642. "yi",
  2643. "hbo",
  2644. "men",
  2645. "xmn",
  2646. "fa",
  2647. "jpr",
  2648. "peo",
  2649. "pes",
  2650. "prs",
  2651. "dv",
  2652. "sam",
  2653. "ckb"
  2654. ];
  2655. const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
  2656. return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
  2657. }
  2658. static createInstance() {
  2659. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  2660. let callback = arguments.length > 1 ? arguments[1] : void 0;
  2661. return new I18n(options, callback);
  2662. }
  2663. cloneInstance() {
  2664. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  2665. let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
  2666. const forkResourceStore = options.forkResourceStore;
  2667. if (forkResourceStore) delete options.forkResourceStore;
  2668. const mergedOptions = _objectSpread({}, this.options, options, {
  2669. isClone: true
  2670. });
  2671. const clone = new I18n(mergedOptions);
  2672. if (options.debug !== void 0 || options.prefix !== void 0) {
  2673. clone.logger = clone.logger.clone(options);
  2674. }
  2675. const membersToCopy = [
  2676. "store",
  2677. "services",
  2678. "language"
  2679. ];
  2680. membersToCopy.forEach((m)=>{
  2681. clone[m] = this[m];
  2682. });
  2683. clone.services = _objectSpread({}, this.services);
  2684. clone.services.utils = {
  2685. hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
  2686. };
  2687. if (forkResourceStore) {
  2688. clone.store = new ResourceStore(this.store.data, mergedOptions);
  2689. clone.services.resourceStore = clone.store;
  2690. }
  2691. clone.translator = new Translator(clone.services, mergedOptions);
  2692. clone.translator.on("*", function(event) {
  2693. for(var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++){
  2694. args[_key4 - 1] = arguments[_key4];
  2695. }
  2696. clone.emit(event, ...args);
  2697. });
  2698. clone.init(mergedOptions, callback);
  2699. clone.translator.options = mergedOptions;
  2700. clone.translator.backendConnector.services.utils = {
  2701. hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
  2702. };
  2703. return clone;
  2704. }
  2705. toJSON() {
  2706. return {
  2707. options: this.options,
  2708. store: this.store,
  2709. language: this.language,
  2710. languages: this.languages,
  2711. resolvedLanguage: this.resolvedLanguage
  2712. };
  2713. }
  2714. constructor(){
  2715. let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  2716. let callback = arguments.length > 1 ? arguments[1] : void 0;
  2717. super();
  2718. this.options = transformOptions(options);
  2719. this.services = {};
  2720. this.logger = baseLogger;
  2721. this.modules = {
  2722. external: []
  2723. };
  2724. bindMemberFunctions(this);
  2725. if (callback && !this.isInitialized && !options.isClone) {
  2726. if (!this.options.initImmediate) {
  2727. this.init(options, callback);
  2728. return this;
  2729. }
  2730. setTimeout(()=>{
  2731. this.init(options, callback);
  2732. }, 0);
  2733. }
  2734. }
  2735. };
  2736. var instance = I18n.createInstance();
  2737. instance.createInstance = I18n.createInstance;
  2738. var createInstance = instance.createInstance;
  2739. var dir = instance.dir;
  2740. var init = instance.init;
  2741. var loadResources = instance.loadResources;
  2742. var reloadResources = instance.reloadResources;
  2743. var use = instance.use;
  2744. var changeLanguage = instance.changeLanguage;
  2745. var getFixedT = instance.getFixedT;
  2746. var t = instance.t;
  2747. var exists = instance.exists;
  2748. var setDefaultNamespace = instance.setDefaultNamespace;
  2749. var hasLoadedNamespace = instance.hasLoadedNamespace;
  2750. var loadNamespaces = instance.loadNamespaces;
  2751. var loadLanguages = instance.loadLanguages;
  2752. // entry:i18next
  2753. var i18next_default = instance;
  2754. /***/ })
  2755. }]);