willba-component-library 0.0.35 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -114,8 +114,8 @@ function styleInject(css, ref) {
114
114
  }
115
115
  }
116
116
 
117
- var css_248z$8 = ".storybook-button {\r\n font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\r\n font-weight: 700;\r\n border: 0;\r\n border-radius: 3em;\r\n cursor: pointer;\r\n display: inline-block;\r\n line-height: 1;\r\n}\r\n.storybook-button--primary {\r\n color: white;\r\n background-color: #1ea7fd;\r\n}\r\n.storybook-button--secondary {\r\n color: #333;\r\n background-color: transparent;\r\n box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;\r\n}\r\n.storybook-button--small {\r\n font-size: 12px;\r\n padding: 10px 16px;\r\n}\r\n.storybook-button--medium {\r\n font-size: 14px;\r\n padding: 11px 20px;\r\n}\r\n.storybook-button--large {\r\n font-size: 16px;\r\n padding: 12px 24px;\r\n}";
118
- styleInject(css_248z$8);
117
+ var css_248z$9 = ".storybook-button {\r\n font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\r\n font-weight: 700;\r\n border: 0;\r\n border-radius: 3em;\r\n cursor: pointer;\r\n display: inline-block;\r\n line-height: 1;\r\n}\r\n.storybook-button--primary {\r\n color: white;\r\n background-color: #1ea7fd;\r\n}\r\n.storybook-button--secondary {\r\n color: #333;\r\n background-color: transparent;\r\n box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;\r\n}\r\n.storybook-button--small {\r\n font-size: 12px;\r\n padding: 10px 16px;\r\n}\r\n.storybook-button--medium {\r\n font-size: 14px;\r\n padding: 11px 20px;\r\n}\r\n.storybook-button--large {\r\n font-size: 16px;\r\n padding: 12px 24px;\r\n}";
118
+ styleInject(css_248z$9);
119
119
 
120
120
  /**
121
121
  * Primary UI component for user interaction
@@ -126,23 +126,282 @@ var Button$1 = function (_a) {
126
126
  return (React__default.createElement("button", { type: "button", className: classNames("storybook-button", "storybook-button--".concat(size), "storybook-button--".concat(type)), style: textColor ? { color: textColor } : {}, onClick: onClick }, "".concat(label, " ").concat(theState)));
127
127
  };
128
128
 
129
- var css_248z$7 = ".filter-bar-divider {\n width: 1px;\n margin: 0 10px;\n height: 35px;\n background-color: #384265;\n}";
130
- styleInject(css_248z$7);
129
+ function warn() {
130
+ if (console && console.warn) {
131
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
132
+ args[_key] = arguments[_key];
133
+ }
134
+ if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
135
+ console.warn(...args);
136
+ }
137
+ }
138
+ const alreadyWarned = {};
139
+ function warnOnce() {
140
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
141
+ args[_key2] = arguments[_key2];
142
+ }
143
+ if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
144
+ if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
145
+ warn(...args);
146
+ }
147
+ const loadedClb = (i18n, cb) => () => {
148
+ if (i18n.isInitialized) {
149
+ cb();
150
+ } else {
151
+ const initialized = () => {
152
+ setTimeout(() => {
153
+ i18n.off('initialized', initialized);
154
+ }, 0);
155
+ cb();
156
+ };
157
+ i18n.on('initialized', initialized);
158
+ }
159
+ };
160
+ function loadNamespaces(i18n, ns, cb) {
161
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
162
+ }
163
+ function loadLanguages(i18n, lng, ns, cb) {
164
+ if (typeof ns === 'string') ns = [ns];
165
+ ns.forEach(n => {
166
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
167
+ });
168
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
169
+ }
170
+ function oldI18nextHasLoadedNamespace(ns, i18n) {
171
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
172
+ const lng = i18n.languages[0];
173
+ const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
174
+ const lastLng = i18n.languages[i18n.languages.length - 1];
175
+ if (lng.toLowerCase() === 'cimode') return true;
176
+ const loadNotPending = (l, n) => {
177
+ const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
178
+ return loadState === -1 || loadState === 2;
179
+ };
180
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
181
+ if (i18n.hasResourceBundle(lng, ns)) return true;
182
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
183
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
184
+ return false;
185
+ }
186
+ function hasLoadedNamespace(ns, i18n) {
187
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
188
+ if (!i18n.languages || !i18n.languages.length) {
189
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
190
+ return true;
191
+ }
192
+ const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
193
+ if (!isNewerI18next) {
194
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
195
+ }
196
+ return i18n.hasLoadedNamespace(ns, {
197
+ lng: options.lng,
198
+ precheck: (i18nInstance, loadNotPending) => {
199
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
200
+ }
201
+ });
202
+ }
203
+
204
+ const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
205
+ const htmlEntities = {
206
+ '&amp;': '&',
207
+ '&#38;': '&',
208
+ '&lt;': '<',
209
+ '&#60;': '<',
210
+ '&gt;': '>',
211
+ '&#62;': '>',
212
+ '&apos;': "'",
213
+ '&#39;': "'",
214
+ '&quot;': '"',
215
+ '&#34;': '"',
216
+ '&nbsp;': ' ',
217
+ '&#160;': ' ',
218
+ '&copy;': '©',
219
+ '&#169;': '©',
220
+ '&reg;': '®',
221
+ '&#174;': '®',
222
+ '&hellip;': '…',
223
+ '&#8230;': '…',
224
+ '&#x2F;': '/',
225
+ '&#47;': '/'
226
+ };
227
+ const unescapeHtmlEntity = m => htmlEntities[m];
228
+ const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
229
+
230
+ let defaultOptions$1 = {
231
+ bindI18n: 'languageChanged',
232
+ bindI18nStore: '',
233
+ transEmptyNodeValue: '',
234
+ transSupportBasicHtmlNodes: true,
235
+ transWrapTextNodes: '',
236
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
237
+ useSuspense: true,
238
+ unescape
239
+ };
240
+ function setDefaults() {
241
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
242
+ defaultOptions$1 = {
243
+ ...defaultOptions$1,
244
+ ...options
245
+ };
246
+ }
247
+ function getDefaults() {
248
+ return defaultOptions$1;
249
+ }
250
+
251
+ let i18nInstance;
252
+ function setI18n(instance) {
253
+ i18nInstance = instance;
254
+ }
255
+ function getI18n() {
256
+ return i18nInstance;
257
+ }
258
+
259
+ const initReactI18next = {
260
+ type: '3rdParty',
261
+ init(instance) {
262
+ setDefaults(instance.options.react);
263
+ setI18n(instance);
264
+ }
265
+ };
266
+
267
+ const I18nContext = React__default.createContext();
268
+ class ReportNamespaces {
269
+ constructor() {
270
+ this.usedNamespaces = {};
271
+ }
272
+ addUsedNamespaces(namespaces) {
273
+ namespaces.forEach(ns => {
274
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
275
+ });
276
+ }
277
+ getUsedNamespaces() {
278
+ return Object.keys(this.usedNamespaces);
279
+ }
280
+ }
281
+
282
+ const usePrevious = (value, ignore) => {
283
+ const ref = React__default.useRef();
284
+ React__default.useEffect(() => {
285
+ ref.current = ignore ? ref.current : value;
286
+ }, [value, ignore]);
287
+ return ref.current;
288
+ };
289
+ function useTranslation(ns) {
290
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
291
+ const {
292
+ i18n: i18nFromProps
293
+ } = props;
294
+ const {
295
+ i18n: i18nFromContext,
296
+ defaultNS: defaultNSFromContext
297
+ } = React__default.useContext(I18nContext) || {};
298
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
299
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
300
+ if (!i18n) {
301
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
302
+ const notReadyT = (k, optsOrDefaultValue) => {
303
+ if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
304
+ if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
305
+ return Array.isArray(k) ? k[k.length - 1] : k;
306
+ };
307
+ const retNotReady = [notReadyT, {}, false];
308
+ retNotReady.t = notReadyT;
309
+ retNotReady.i18n = {};
310
+ retNotReady.ready = false;
311
+ return retNotReady;
312
+ }
313
+ if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
314
+ const i18nOptions = {
315
+ ...getDefaults(),
316
+ ...i18n.options.react,
317
+ ...props
318
+ };
319
+ const {
320
+ useSuspense,
321
+ keyPrefix
322
+ } = i18nOptions;
323
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
324
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
325
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
326
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
327
+ function getT() {
328
+ return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
329
+ }
330
+ const [t, setT] = React__default.useState(getT);
331
+ let joinedNS = namespaces.join();
332
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
333
+ const previousJoinedNS = usePrevious(joinedNS);
334
+ const isMounted = React__default.useRef(true);
335
+ React__default.useEffect(() => {
336
+ const {
337
+ bindI18n,
338
+ bindI18nStore
339
+ } = i18nOptions;
340
+ isMounted.current = true;
341
+ if (!ready && !useSuspense) {
342
+ if (props.lng) {
343
+ loadLanguages(i18n, props.lng, namespaces, () => {
344
+ if (isMounted.current) setT(getT);
345
+ });
346
+ } else {
347
+ loadNamespaces(i18n, namespaces, () => {
348
+ if (isMounted.current) setT(getT);
349
+ });
350
+ }
351
+ }
352
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
353
+ setT(getT);
354
+ }
355
+ function boundReset() {
356
+ if (isMounted.current) setT(getT);
357
+ }
358
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
359
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
360
+ return () => {
361
+ isMounted.current = false;
362
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
363
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
364
+ };
365
+ }, [i18n, joinedNS]);
366
+ const isInitial = React__default.useRef(true);
367
+ React__default.useEffect(() => {
368
+ if (isMounted.current && !isInitial.current) {
369
+ setT(getT);
370
+ }
371
+ isInitial.current = false;
372
+ }, [i18n, keyPrefix]);
373
+ const ret = [t, i18n, ready];
374
+ ret.t = t;
375
+ ret.i18n = i18n;
376
+ ret.ready = ready;
377
+ if (ready) return ret;
378
+ if (!ready && !useSuspense) return ret;
379
+ throw new Promise(resolve => {
380
+ if (props.lng) {
381
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
382
+ } else {
383
+ loadNamespaces(i18n, namespaces, () => resolve());
384
+ }
385
+ });
386
+ }
387
+
388
+ var css_248z$8 = ".filter-bar-divider {\n width: 1px;\n margin: 0 10px;\n height: 35px;\n background-color: #384265;\n}";
389
+ styleInject(css_248z$8);
131
390
 
132
391
  function Divider() {
133
392
  return React__default.createElement("div", { className: "filter-bar-divider" });
134
393
  }
135
394
 
136
- var css_248z$6 = ".filter-bar-select-button {\n width: 100%;\n height: auto;\n background-color: transparent;\n border: none;\n padding: 10px 20px;\n border-radius: 20px;\n cursor: pointer;\n}\n";
137
- styleInject(css_248z$6);
395
+ var css_248z$7 = ".filter-bar-select-button {\n width: 100%;\n height: auto;\n background-color: transparent;\n border: none;\n padding: 10px 20px;\n border-radius: 20px;\n cursor: pointer;\n}\n";
396
+ styleInject(css_248z$7);
138
397
 
139
398
  function SelectButton(_a) {
140
399
  var label = _a.label, onClick = _a.onClick;
141
400
  return (React__default.createElement("button", { className: "filter-bar-select-button", onClick: onClick }, label));
142
401
  }
143
402
 
144
- var css_248z$5 = ".filter-bar-submit-button {\n width: auto;\n height: auto;\n background-color: #384265;\n color: #fff;\n padding: 10px 20px;\n border-radius: 20px;\n cursor: pointer;\n border: none;\n white-space: nowrap;\n}";
145
- styleInject(css_248z$5);
403
+ var css_248z$6 = ".filter-bar-submit-button {\n width: auto;\n height: auto;\n background-color: #384265;\n color: #fff;\n padding: 10px 20px;\n border-radius: 20px;\n cursor: pointer;\n border: none;\n white-space: nowrap;\n}";
404
+ styleInject(css_248z$6);
146
405
 
147
406
  function SubmitButton(_a) {
148
407
  var onClick = _a.onClick;
@@ -5704,11 +5963,11 @@ function DayPicker(props) {
5704
5963
  React__default.createElement(Root, { initialProps: props })));
5705
5964
  }
5706
5965
 
5707
- var css_248z$4 = ".rdp {\n --rdp-cell-size: 40px;\n --rdp-caption-font-size: 18px;\n --rdp-accent-color: #0000ff;\n --rdp-background-color: #e7edff;\n --rdp-accent-color-dark: #3003e1;\n --rdp-background-color-dark: #180270;\n --rdp-outline: 2px solid var(--rdp-accent-color); /* Outline border for focused elements */\n --rdp-outline-selected: 3px solid var(--rdp-accent-color); /* Outline border for focused _and_ selected elements */\n\n margin: 1em;\n}\n\n/* Hide elements for devices that are not screen readers */\n.rdp-vhidden {\n box-sizing: border-box;\n padding: 0;\n margin: 0;\n background: transparent;\n border: 0;\n -moz-appearance: none;\n -webkit-appearance: none;\n appearance: none;\n position: absolute !important;\n top: 0;\n width: 1px !important;\n height: 1px !important;\n padding: 0 !important;\n overflow: hidden !important;\n clip: rect(1px, 1px, 1px, 1px) !important;\n border: 0 !important;\n}\n\n/* Buttons */\n.rdp-button_reset {\n appearance: none;\n position: relative;\n margin: 0;\n padding: 0;\n cursor: default;\n color: inherit;\n background: none;\n font: inherit;\n\n -moz-appearance: none;\n -webkit-appearance: none;\n}\n\n.rdp-button_reset:focus-visible {\n /* Make sure to reset outline only when :focus-visible is supported */\n outline: none;\n}\n\n.rdp-button {\n border: 2px solid transparent;\n}\n\n.rdp-button[disabled]:not(.rdp-day_selected) {\n opacity: 0.25;\n}\n\n.rdp-button:not([disabled]) {\n cursor: pointer;\n}\n\n.rdp-button:focus-visible:not([disabled]) {\n color: inherit;\n background-color: var(--rdp-background-color);\n border: var(--rdp-outline);\n}\n\n.rdp-button:hover:not([disabled]):not(.rdp-day_selected) {\n background-color: var(--rdp-background-color);\n}\n\n.rdp-months {\n display: flex;\n}\n\n.rdp-month {\n margin: 0 1em;\n}\n\n.rdp-month:first-child {\n margin-left: 0;\n}\n\n.rdp-month:last-child {\n margin-right: 0;\n}\n\n.rdp-table {\n margin: 0;\n max-width: calc(var(--rdp-cell-size) * 7);\n border-collapse: collapse;\n}\n\n.rdp-with_weeknumber .rdp-table {\n max-width: calc(var(--rdp-cell-size) * 8);\n border-collapse: collapse;\n}\n\n.rdp-caption {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 0;\n text-align: left;\n}\n\n.rdp-multiple_months .rdp-caption {\n position: relative;\n display: block;\n text-align: center;\n}\n\n.rdp-caption_dropdowns {\n position: relative;\n display: inline-flex;\n}\n\n.rdp-caption_label {\n position: relative;\n z-index: 1;\n display: inline-flex;\n align-items: center;\n margin: 0;\n padding: 0 0.25em;\n white-space: nowrap;\n color: currentColor;\n border: 0;\n border: 2px solid transparent;\n font-family: inherit;\n font-size: var(--rdp-caption-font-size);\n font-weight: bold;\n}\n\n.rdp-nav {\n white-space: nowrap;\n}\n\n.rdp-multiple_months .rdp-caption_start .rdp-nav {\n position: absolute;\n top: 50%;\n left: 0;\n transform: translateY(-50%);\n}\n\n.rdp-multiple_months .rdp-caption_end .rdp-nav {\n position: absolute;\n top: 50%;\n right: 0;\n transform: translateY(-50%);\n}\n\n.rdp-nav_button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: var(--rdp-cell-size);\n height: var(--rdp-cell-size);\n padding: 0.25em;\n border-radius: 100%;\n}\n\n/* ---------- */\n/* Dropdowns */\n/* ---------- */\n\n.rdp-dropdown_year,\n.rdp-dropdown_month {\n position: relative;\n display: inline-flex;\n align-items: center;\n}\n\n.rdp-dropdown {\n appearance: none;\n position: absolute;\n z-index: 2;\n top: 0;\n bottom: 0;\n left: 0;\n width: 100%;\n margin: 0;\n padding: 0;\n cursor: inherit;\n opacity: 0;\n border: none;\n background-color: transparent;\n font-family: inherit;\n font-size: inherit;\n line-height: inherit;\n}\n\n.rdp-dropdown[disabled] {\n opacity: unset;\n color: unset;\n}\n\n.rdp-dropdown:focus-visible:not([disabled]) + .rdp-caption_label {\n background-color: var(--rdp-background-color);\n border: var(--rdp-outline);\n border-radius: 6px;\n}\n\n.rdp-dropdown_icon {\n margin: 0 0 0 5px;\n}\n\n.rdp-head {\n border: 0;\n}\n\n.rdp-head_row,\n.rdp-row {\n height: 100%;\n}\n\n.rdp-head_cell {\n vertical-align: middle;\n font-size: 0.75em;\n font-weight: 700;\n text-align: center;\n height: 100%;\n height: var(--rdp-cell-size);\n padding: 0;\n text-transform: uppercase;\n}\n\n.rdp-tbody {\n border: 0;\n}\n\n.rdp-tfoot {\n margin: 0.5em;\n}\n\n.rdp-cell {\n width: var(--rdp-cell-size);\n height: 100%;\n height: var(--rdp-cell-size);\n padding: 0;\n text-align: center;\n}\n\n.rdp-weeknumber {\n font-size: 0.75em;\n}\n\n.rdp-weeknumber,\n.rdp-day {\n display: flex;\n overflow: hidden;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: var(--rdp-cell-size);\n max-width: var(--rdp-cell-size);\n height: var(--rdp-cell-size);\n margin: 0;\n border: 2px solid transparent;\n border-radius: 100%;\n}\n\n.rdp-day_today:not(.rdp-day_outside) {\n font-weight: bold;\n}\n\n.rdp-day_selected,\n.rdp-day_selected:focus-visible,\n.rdp-day_selected:hover {\n color: white;\n opacity: 1;\n background-color: var(--rdp-accent-color);\n}\n\n.rdp-day_outside {\n opacity: 0.5;\n}\n\n.rdp-day_selected:focus-visible {\n /* Since the background is the same use again the outline */\n outline: var(--rdp-outline);\n outline-offset: 2px;\n z-index: 1;\n}\n\n.rdp:not([dir='rtl']) .rdp-day_range_start:not(.rdp-day_range_end) {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n.rdp:not([dir='rtl']) .rdp-day_range_end:not(.rdp-day_range_start) {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n}\n\n.rdp[dir='rtl'] .rdp-day_range_start:not(.rdp-day_range_end) {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n}\n\n.rdp[dir='rtl'] .rdp-day_range_end:not(.rdp-day_range_start) {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n.rdp-day_range_end.rdp-day_range_start {\n border-radius: 100%;\n}\n\n.rdp-day_range_middle {\n border-radius: 0;\n}";
5708
- styleInject(css_248z$4);
5966
+ var css_248z$5 = ".rdp {\n --rdp-cell-size: 40px;\n --rdp-caption-font-size: 18px;\n --rdp-accent-color: #0000ff;\n --rdp-background-color: #e7edff;\n --rdp-accent-color-dark: #3003e1;\n --rdp-background-color-dark: #180270;\n --rdp-outline: 2px solid var(--rdp-accent-color); /* Outline border for focused elements */\n --rdp-outline-selected: 3px solid var(--rdp-accent-color); /* Outline border for focused _and_ selected elements */\n\n margin: 1em;\n}\n\n/* Hide elements for devices that are not screen readers */\n.rdp-vhidden {\n box-sizing: border-box;\n padding: 0;\n margin: 0;\n background: transparent;\n border: 0;\n -moz-appearance: none;\n -webkit-appearance: none;\n appearance: none;\n position: absolute !important;\n top: 0;\n width: 1px !important;\n height: 1px !important;\n padding: 0 !important;\n overflow: hidden !important;\n clip: rect(1px, 1px, 1px, 1px) !important;\n border: 0 !important;\n}\n\n/* Buttons */\n.rdp-button_reset {\n appearance: none;\n position: relative;\n margin: 0;\n padding: 0;\n cursor: default;\n color: inherit;\n background: none;\n font: inherit;\n\n -moz-appearance: none;\n -webkit-appearance: none;\n}\n\n.rdp-button_reset:focus-visible {\n /* Make sure to reset outline only when :focus-visible is supported */\n outline: none;\n}\n\n.rdp-button {\n border: 2px solid transparent;\n}\n\n.rdp-button[disabled]:not(.rdp-day_selected) {\n opacity: 0.25;\n}\n\n.rdp-button:not([disabled]) {\n cursor: pointer;\n}\n\n.rdp-button:focus-visible:not([disabled]) {\n color: inherit;\n background-color: var(--rdp-background-color);\n border: var(--rdp-outline);\n}\n\n.rdp-button:hover:not([disabled]):not(.rdp-day_selected) {\n background-color: var(--rdp-background-color);\n}\n\n.rdp-months {\n display: flex;\n}\n\n.rdp-month {\n margin: 0 1em;\n}\n\n.rdp-month:first-child {\n margin-left: 0;\n}\n\n.rdp-month:last-child {\n margin-right: 0;\n}\n\n.rdp-table {\n margin: 0;\n max-width: calc(var(--rdp-cell-size) * 7);\n border-collapse: collapse;\n}\n\n.rdp-with_weeknumber .rdp-table {\n max-width: calc(var(--rdp-cell-size) * 8);\n border-collapse: collapse;\n}\n\n.rdp-caption {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 0;\n text-align: left;\n}\n\n.rdp-multiple_months .rdp-caption {\n position: relative;\n display: block;\n text-align: center;\n}\n\n.rdp-caption_dropdowns {\n position: relative;\n display: inline-flex;\n}\n\n.rdp-caption_label {\n position: relative;\n z-index: 1;\n display: inline-flex;\n align-items: center;\n margin: 0;\n padding: 0 0.25em;\n white-space: nowrap;\n color: currentColor;\n border: 0;\n border: 2px solid transparent;\n font-family: inherit;\n font-size: var(--rdp-caption-font-size);\n font-weight: bold;\n}\n\n.rdp-nav {\n white-space: nowrap;\n}\n\n.rdp-multiple_months .rdp-caption_start .rdp-nav {\n position: absolute;\n top: 50%;\n left: 0;\n transform: translateY(-50%);\n}\n\n.rdp-multiple_months .rdp-caption_end .rdp-nav {\n position: absolute;\n top: 50%;\n right: 0;\n transform: translateY(-50%);\n}\n\n.rdp-nav_button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: var(--rdp-cell-size);\n height: var(--rdp-cell-size);\n padding: 0.25em;\n border-radius: 100%;\n}\n\n/* ---------- */\n/* Dropdowns */\n/* ---------- */\n\n.rdp-dropdown_year,\n.rdp-dropdown_month {\n position: relative;\n display: inline-flex;\n align-items: center;\n}\n\n.rdp-dropdown {\n appearance: none;\n position: absolute;\n z-index: 2;\n top: 0;\n bottom: 0;\n left: 0;\n width: 100%;\n margin: 0;\n padding: 0;\n cursor: inherit;\n opacity: 0;\n border: none;\n background-color: transparent;\n font-family: inherit;\n font-size: inherit;\n line-height: inherit;\n}\n\n.rdp-dropdown[disabled] {\n opacity: unset;\n color: unset;\n}\n\n.rdp-dropdown:focus-visible:not([disabled]) + .rdp-caption_label {\n background-color: var(--rdp-background-color);\n border: var(--rdp-outline);\n border-radius: 6px;\n}\n\n.rdp-dropdown_icon {\n margin: 0 0 0 5px;\n}\n\n.rdp-head {\n border: 0;\n}\n\n.rdp-head_row,\n.rdp-row {\n height: 100%;\n}\n\n.rdp-head_cell {\n vertical-align: middle;\n font-size: 0.75em;\n font-weight: 700;\n text-align: center;\n height: 100%;\n height: var(--rdp-cell-size);\n padding: 0;\n text-transform: uppercase;\n}\n\n.rdp-tbody {\n border: 0;\n}\n\n.rdp-tfoot {\n margin: 0.5em;\n}\n\n.rdp-cell {\n width: var(--rdp-cell-size);\n height: 100%;\n height: var(--rdp-cell-size);\n padding: 0;\n text-align: center;\n}\n\n.rdp-weeknumber {\n font-size: 0.75em;\n}\n\n.rdp-weeknumber,\n.rdp-day {\n display: flex;\n overflow: hidden;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: var(--rdp-cell-size);\n max-width: var(--rdp-cell-size);\n height: var(--rdp-cell-size);\n margin: 0;\n border: 2px solid transparent;\n border-radius: 100%;\n}\n\n.rdp-day_today:not(.rdp-day_outside) {\n font-weight: bold;\n}\n\n.rdp-day_selected,\n.rdp-day_selected:focus-visible,\n.rdp-day_selected:hover {\n color: white;\n opacity: 1;\n background-color: var(--rdp-accent-color);\n}\n\n.rdp-day_outside {\n opacity: 0.5;\n}\n\n.rdp-day_selected:focus-visible {\n /* Since the background is the same use again the outline */\n outline: var(--rdp-outline);\n outline-offset: 2px;\n z-index: 1;\n}\n\n.rdp:not([dir='rtl']) .rdp-day_range_start:not(.rdp-day_range_end) {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n.rdp:not([dir='rtl']) .rdp-day_range_end:not(.rdp-day_range_start) {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n}\n\n.rdp[dir='rtl'] .rdp-day_range_start:not(.rdp-day_range_end) {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n}\n\n.rdp[dir='rtl'] .rdp-day_range_end:not(.rdp-day_range_start) {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n.rdp-day_range_end.rdp-day_range_start {\n border-radius: 100%;\n}\n\n.rdp-day_range_middle {\n border-radius: 0;\n}";
5967
+ styleInject(css_248z$5);
5709
5968
 
5710
- var css_248z$3 = ".filter-bar-calendar {\n display: flex;\n justify-content: center;\n}";
5711
- styleInject(css_248z$3);
5969
+ var css_248z$4 = ".filter-bar-calendar {\n display: flex;\n justify-content: center;\n}";
5970
+ styleInject(css_248z$4);
5712
5971
 
5713
5972
  var currentMonth = new Date();
5714
5973
  function Calendar(_a) {
@@ -5725,34 +5984,36 @@ function Calendar(_a) {
5725
5984
  React__default.createElement(DayPicker, { id: "test", mode: "range", numberOfMonths: 2, defaultMonth: currentMonth, selected: calendarRange, onSelect: setCalendarRange })));
5726
5985
  }
5727
5986
 
5728
- var css_248z$2 = ".filter-bar-guests {\n text-align: initial;\n}\n\n.guests-filter-container {\n display: flex;\n margin-top: 30px;\n}\n\n.guests-filter-inner {\n display: flex;\n align-items: center;\n}\n\n.guests-filter-inner:not(:last-child) {\n margin-right: 50px;\n}\n\n.guests-filter-inner > span {\n display: block;\n margin-right: 20px;\n font-weight: bold;\n}\n\n.guests-filter-inner > div {\n display: flex;\n align-items: center;\n}\n\n.guests-filter-inner > div > span {\n margin: 0 10px;\n}\n\n.guests-filter-inner > div button {\n border-radius: 50%;\n border: none;\n background-color: #CDEEFF;\n width: 25px;\n height: 25px;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 20px;\n}";
5729
- styleInject(css_248z$2);
5987
+ var css_248z$3 = ".filter-bar-guests {\n text-align: initial;\n}\n\n.guests-filter-container {\n display: flex;\n margin-top: 30px;\n}\n\n.guests-filter-inner {\n display: flex;\n align-items: center;\n}\n\n.guests-filter-inner:not(:last-child) {\n margin-right: 50px;\n}\n\n.guests-filter-inner > span {\n display: block;\n margin-right: 20px;\n font-weight: bold;\n}\n\n.guests-filter-inner > div {\n display: flex;\n align-items: center;\n}\n\n.guests-filter-inner > div > span {\n margin: 0 10px;\n}\n\n.guests-filter-inner > div button {\n border-radius: 50%;\n border: none;\n background-color: #CDEEFF;\n width: 25px;\n height: 25px;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 20px;\n}";
5988
+ styleInject(css_248z$3);
5730
5989
 
5731
5990
  function Guests(_a) {
5732
5991
  var guestsAdults = _a.guestsAdults, guestsKids = _a.guestsKids, decrementAdults = _a.decrementAdults, incrementAdults = _a.incrementAdults, decrementKids = _a.decrementKids, incrementKids = _a.incrementKids;
5992
+ var t = useTranslation('filterBar').t;
5733
5993
  return (React__default.createElement("div", { className: "filter-bar-guests" },
5734
- React__default.createElement("h3", null, "Guests"),
5735
- React__default.createElement("p", null, "Who's coming?"),
5994
+ React__default.createElement("h3", null, t('guests.title')),
5995
+ React__default.createElement("p", null, t('guests.subtitle')),
5736
5996
  React__default.createElement("div", { className: "guests-filter-container" },
5737
5997
  React__default.createElement("div", { className: "guests-filter-inner" },
5738
- React__default.createElement("span", null, "Adults"),
5998
+ React__default.createElement("span", null, t('guests.adultsLabel')),
5739
5999
  React__default.createElement("div", null,
5740
6000
  React__default.createElement("button", { onClick: decrementAdults, disabled: guestsAdults < 1 }, "-"),
5741
6001
  React__default.createElement("span", null, guestsAdults),
5742
6002
  React__default.createElement("button", { onClick: incrementAdults }, "+"))),
5743
6003
  React__default.createElement("div", { className: "guests-filter-inner" },
5744
- React__default.createElement("span", null, "Kids"),
6004
+ React__default.createElement("span", null, t('guests.kidsLabel')),
5745
6005
  React__default.createElement("div", null,
5746
6006
  React__default.createElement("button", { onClick: decrementKids, disabled: guestsKids < 1 }, "-"),
5747
6007
  React__default.createElement("span", null, guestsKids),
5748
6008
  React__default.createElement("button", { onClick: incrementKids }, "+"))))));
5749
6009
  }
5750
6010
 
5751
- var css_248z$1 = ".filter-bar-categories {\n text-align: center;\n}\n\n.categories-filter-inner {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 20px;\n}\n\n.categories-filter-inner input {\n cursor: pointer;\n margin-right: 10px;\n}\n";
5752
- styleInject(css_248z$1);
6011
+ var css_248z$2 = ".filter-bar-categories {\n text-align: center;\n}\n\n.categories-filter-inner {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 20px;\n}\n\n.categories-filter-inner input {\n cursor: pointer;\n margin-right: 10px;\n}\n";
6012
+ styleInject(css_248z$2);
5753
6013
 
5754
6014
  function Categories(_a) {
5755
6015
  _a.categories; var setCategories = _a.setCategories;
6016
+ var t = useTranslation('filterBar').t;
5756
6017
  var categoriesPlaceholder = [
5757
6018
  'Weekend',
5758
6019
  'Week',
@@ -5765,7 +6026,7 @@ function Categories(_a) {
5765
6026
  setCategories(selectedCategory);
5766
6027
  };
5767
6028
  return (React__default.createElement("div", { className: "filter-bar-categories" },
5768
- React__default.createElement("h3", null, "CATEGORY"),
6029
+ React__default.createElement("h3", null, t('categories.label')),
5769
6030
  React__default.createElement("div", { className: "categories-filter-inner" }, categoriesPlaceholder.map(function (itm, idx) { return (React__default.createElement("div", { key: idx },
5770
6031
  React__default.createElement("input", { type: "radio", value: itm, checked: selectedCategory === itm, onChange: function () { return handleCategoryChange(itm); } }),
5771
6032
  React__default.createElement("span", null, itm))); }))));
@@ -5817,20 +6078,2355 @@ function useFilterBar() {
5817
6078
  };
5818
6079
  }
5819
6080
 
5820
- var css_248z = ".filter-bar {\r\n box-sizing: border-box;\r\n max-width: 1100px;\r\n position: relative;\r\n}\r\n\r\n.filter-bar-header {\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n padding: 10px 20px;\r\n position: relative;\r\n z-index: 222;\r\n \r\n border-radius: 40px;\r\n background-color: #fff;\r\n box-shadow: 0px 6px 11px 0px #a7a4a480;\r\n}\r\n\r\n.filter-bar-container {\r\n background-color: #fff;\r\n min-height: 100px;\r\n \r\n padding: 90px 40px 30px 40px;\r\n position: absolute;\r\n top: 0;\r\n z-index: 111;\r\n border-radius: 40px;\r\n width: -webkit-fill-available;\r\n box-shadow: 0px 6px 11px 0px #a7a4a480;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
6081
+ var css_248z$1 = ".filter-bar {\r\n box-sizing: border-box;\r\n max-width: 1100px;\r\n position: relative;\r\n}\r\n\r\n.filter-bar-header {\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n padding: 10px 20px;\r\n position: relative;\r\n z-index: 222;\r\n \r\n border-radius: 40px;\r\n background-color: #fff;\r\n box-shadow: 0px 6px 11px 0px #a7a4a480;\r\n}\r\n\r\n.filter-bar-container {\r\n background-color: #fff;\r\n min-height: 100px;\r\n \r\n padding: 90px 40px 30px 40px;\r\n position: absolute;\r\n top: 0;\r\n z-index: 111;\r\n border-radius: 40px;\r\n width: -webkit-fill-available;\r\n box-shadow: var(--box-shadow);\r\n}";
6082
+ styleInject(css_248z$1);
6083
+
6084
+ var css_248z = ":root {\n --primary-color: #3498db;\n --font-size: 16px;\n --box-shadow: 0px 6px 11px 0px #a7a4a480\n}\n\n* {\n box-sizing: border-box;\n}\n\nhtml {\n background-color: aqua;\n}";
5821
6085
  styleInject(css_248z);
5822
6086
 
5823
- function FilterBar() {
5824
- var _a = useFilterBar(), selectedFilter = _a.selectedFilter, guestsAdults = _a.guestsAdults, guestsKids = _a.guestsKids, categories = _a.categories, calendarRange = _a.calendarRange, setCalendarRange = _a.setCalendarRange, setGuestsAdults = _a.setGuestsAdults, setGuestsKids = _a.setGuestsKids, setCategories = _a.setCategories, handleSelectedFilter = _a.handleSelectedFilter, handleSubmit = _a.handleSubmit;
6087
+ const consoleLogger = {
6088
+ type: 'logger',
6089
+ log(args) {
6090
+ this.output('log', args);
6091
+ },
6092
+ warn(args) {
6093
+ this.output('warn', args);
6094
+ },
6095
+ error(args) {
6096
+ this.output('error', args);
6097
+ },
6098
+ output(type, args) {
6099
+ if (console && console[type]) console[type].apply(console, args);
6100
+ }
6101
+ };
6102
+ class Logger {
6103
+ constructor(concreteLogger) {
6104
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6105
+ this.init(concreteLogger, options);
6106
+ }
6107
+ init(concreteLogger) {
6108
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6109
+ this.prefix = options.prefix || 'i18next:';
6110
+ this.logger = concreteLogger || consoleLogger;
6111
+ this.options = options;
6112
+ this.debug = options.debug;
6113
+ }
6114
+ log() {
6115
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6116
+ args[_key] = arguments[_key];
6117
+ }
6118
+ return this.forward(args, 'log', '', true);
6119
+ }
6120
+ warn() {
6121
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
6122
+ args[_key2] = arguments[_key2];
6123
+ }
6124
+ return this.forward(args, 'warn', '', true);
6125
+ }
6126
+ error() {
6127
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
6128
+ args[_key3] = arguments[_key3];
6129
+ }
6130
+ return this.forward(args, 'error', '');
6131
+ }
6132
+ deprecate() {
6133
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
6134
+ args[_key4] = arguments[_key4];
6135
+ }
6136
+ return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
6137
+ }
6138
+ forward(args, lvl, prefix, debugOnly) {
6139
+ if (debugOnly && !this.debug) return null;
6140
+ if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
6141
+ return this.logger[lvl](args);
6142
+ }
6143
+ create(moduleName) {
6144
+ return new Logger(this.logger, {
6145
+ ...{
6146
+ prefix: `${this.prefix}:${moduleName}:`
6147
+ },
6148
+ ...this.options
6149
+ });
6150
+ }
6151
+ clone(options) {
6152
+ options = options || this.options;
6153
+ options.prefix = options.prefix || this.prefix;
6154
+ return new Logger(this.logger, options);
6155
+ }
6156
+ }
6157
+ var baseLogger = new Logger();
6158
+
6159
+ class EventEmitter {
6160
+ constructor() {
6161
+ this.observers = {};
6162
+ }
6163
+ on(events, listener) {
6164
+ events.split(' ').forEach(event => {
6165
+ this.observers[event] = this.observers[event] || [];
6166
+ this.observers[event].push(listener);
6167
+ });
6168
+ return this;
6169
+ }
6170
+ off(event, listener) {
6171
+ if (!this.observers[event]) return;
6172
+ if (!listener) {
6173
+ delete this.observers[event];
6174
+ return;
6175
+ }
6176
+ this.observers[event] = this.observers[event].filter(l => l !== listener);
6177
+ }
6178
+ emit(event) {
6179
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6180
+ args[_key - 1] = arguments[_key];
6181
+ }
6182
+ if (this.observers[event]) {
6183
+ const cloned = [].concat(this.observers[event]);
6184
+ cloned.forEach(observer => {
6185
+ observer(...args);
6186
+ });
6187
+ }
6188
+ if (this.observers['*']) {
6189
+ const cloned = [].concat(this.observers['*']);
6190
+ cloned.forEach(observer => {
6191
+ observer.apply(observer, [event, ...args]);
6192
+ });
6193
+ }
6194
+ }
6195
+ }
6196
+
6197
+ function defer() {
6198
+ let res;
6199
+ let rej;
6200
+ const promise = new Promise((resolve, reject) => {
6201
+ res = resolve;
6202
+ rej = reject;
6203
+ });
6204
+ promise.resolve = res;
6205
+ promise.reject = rej;
6206
+ return promise;
6207
+ }
6208
+ function makeString(object) {
6209
+ if (object == null) return '';
6210
+ return '' + object;
6211
+ }
6212
+ function copy(a, s, t) {
6213
+ a.forEach(m => {
6214
+ if (s[m]) t[m] = s[m];
6215
+ });
6216
+ }
6217
+ function getLastOfPath(object, path, Empty) {
6218
+ function cleanKey(key) {
6219
+ return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
6220
+ }
6221
+ function canNotTraverseDeeper() {
6222
+ return !object || typeof object === 'string';
6223
+ }
6224
+ const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
6225
+ while (stack.length > 1) {
6226
+ if (canNotTraverseDeeper()) return {};
6227
+ const key = cleanKey(stack.shift());
6228
+ if (!object[key] && Empty) object[key] = new Empty();
6229
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
6230
+ object = object[key];
6231
+ } else {
6232
+ object = {};
6233
+ }
6234
+ }
6235
+ if (canNotTraverseDeeper()) return {};
6236
+ return {
6237
+ obj: object,
6238
+ k: cleanKey(stack.shift())
6239
+ };
6240
+ }
6241
+ function setPath(object, path, newValue) {
6242
+ const {
6243
+ obj,
6244
+ k
6245
+ } = getLastOfPath(object, path, Object);
6246
+ obj[k] = newValue;
6247
+ }
6248
+ function pushPath(object, path, newValue, concat) {
6249
+ const {
6250
+ obj,
6251
+ k
6252
+ } = getLastOfPath(object, path, Object);
6253
+ obj[k] = obj[k] || [];
6254
+ if (concat) obj[k] = obj[k].concat(newValue);
6255
+ if (!concat) obj[k].push(newValue);
6256
+ }
6257
+ function getPath(object, path) {
6258
+ const {
6259
+ obj,
6260
+ k
6261
+ } = getLastOfPath(object, path);
6262
+ if (!obj) return undefined;
6263
+ return obj[k];
6264
+ }
6265
+ function getPathWithDefaults(data, defaultData, key) {
6266
+ const value = getPath(data, key);
6267
+ if (value !== undefined) {
6268
+ return value;
6269
+ }
6270
+ return getPath(defaultData, key);
6271
+ }
6272
+ function deepExtend(target, source, overwrite) {
6273
+ for (const prop in source) {
6274
+ if (prop !== '__proto__' && prop !== 'constructor') {
6275
+ if (prop in target) {
6276
+ if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
6277
+ if (overwrite) target[prop] = source[prop];
6278
+ } else {
6279
+ deepExtend(target[prop], source[prop], overwrite);
6280
+ }
6281
+ } else {
6282
+ target[prop] = source[prop];
6283
+ }
6284
+ }
6285
+ }
6286
+ return target;
6287
+ }
6288
+ function regexEscape(str) {
6289
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
6290
+ }
6291
+ var _entityMap = {
6292
+ '&': '&amp;',
6293
+ '<': '&lt;',
6294
+ '>': '&gt;',
6295
+ '"': '&quot;',
6296
+ "'": '&#39;',
6297
+ '/': '&#x2F;'
6298
+ };
6299
+ function escape(data) {
6300
+ if (typeof data === 'string') {
6301
+ return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
6302
+ }
6303
+ return data;
6304
+ }
6305
+ const chars = [' ', ',', '?', '!', ';'];
6306
+ function looksLikeObjectPath(key, nsSeparator, keySeparator) {
6307
+ nsSeparator = nsSeparator || '';
6308
+ keySeparator = keySeparator || '';
6309
+ const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
6310
+ if (possibleChars.length === 0) return true;
6311
+ const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
6312
+ let matched = !r.test(key);
6313
+ if (!matched) {
6314
+ const ki = key.indexOf(keySeparator);
6315
+ if (ki > 0 && !r.test(key.substring(0, ki))) {
6316
+ matched = true;
6317
+ }
6318
+ }
6319
+ return matched;
6320
+ }
6321
+ function deepFind(obj, path) {
6322
+ let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
6323
+ if (!obj) return undefined;
6324
+ if (obj[path]) return obj[path];
6325
+ const paths = path.split(keySeparator);
6326
+ let current = obj;
6327
+ for (let i = 0; i < paths.length; ++i) {
6328
+ if (!current) return undefined;
6329
+ if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
6330
+ return undefined;
6331
+ }
6332
+ if (current[paths[i]] === undefined) {
6333
+ let j = 2;
6334
+ let p = paths.slice(i, i + j).join(keySeparator);
6335
+ let mix = current[p];
6336
+ while (mix === undefined && paths.length > i + j) {
6337
+ j++;
6338
+ p = paths.slice(i, i + j).join(keySeparator);
6339
+ mix = current[p];
6340
+ }
6341
+ if (mix === undefined) return undefined;
6342
+ if (mix === null) return null;
6343
+ if (path.endsWith(p)) {
6344
+ if (typeof mix === 'string') return mix;
6345
+ if (p && typeof mix[p] === 'string') return mix[p];
6346
+ }
6347
+ const joinedPath = paths.slice(i + j).join(keySeparator);
6348
+ if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
6349
+ return undefined;
6350
+ }
6351
+ current = current[paths[i]];
6352
+ }
6353
+ return current;
6354
+ }
6355
+ function getCleanedCode(code) {
6356
+ if (code && code.indexOf('_') > 0) return code.replace('_', '-');
6357
+ return code;
6358
+ }
6359
+
6360
+ class ResourceStore extends EventEmitter {
6361
+ constructor(data) {
6362
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
6363
+ ns: ['translation'],
6364
+ defaultNS: 'translation'
6365
+ };
6366
+ super();
6367
+ this.data = data || {};
6368
+ this.options = options;
6369
+ if (this.options.keySeparator === undefined) {
6370
+ this.options.keySeparator = '.';
6371
+ }
6372
+ if (this.options.ignoreJSONStructure === undefined) {
6373
+ this.options.ignoreJSONStructure = true;
6374
+ }
6375
+ }
6376
+ addNamespaces(ns) {
6377
+ if (this.options.ns.indexOf(ns) < 0) {
6378
+ this.options.ns.push(ns);
6379
+ }
6380
+ }
6381
+ removeNamespaces(ns) {
6382
+ const index = this.options.ns.indexOf(ns);
6383
+ if (index > -1) {
6384
+ this.options.ns.splice(index, 1);
6385
+ }
6386
+ }
6387
+ getResource(lng, ns, key) {
6388
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6389
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
6390
+ const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
6391
+ let path = [lng, ns];
6392
+ if (key && typeof key !== 'string') path = path.concat(key);
6393
+ if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
6394
+ if (lng.indexOf('.') > -1) {
6395
+ path = lng.split('.');
6396
+ }
6397
+ const result = getPath(this.data, path);
6398
+ if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
6399
+ return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
6400
+ }
6401
+ addResource(lng, ns, key, value) {
6402
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
6403
+ silent: false
6404
+ };
6405
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
6406
+ let path = [lng, ns];
6407
+ if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
6408
+ if (lng.indexOf('.') > -1) {
6409
+ path = lng.split('.');
6410
+ value = ns;
6411
+ ns = path[1];
6412
+ }
6413
+ this.addNamespaces(ns);
6414
+ setPath(this.data, path, value);
6415
+ if (!options.silent) this.emit('added', lng, ns, key, value);
6416
+ }
6417
+ addResources(lng, ns, resources) {
6418
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
6419
+ silent: false
6420
+ };
6421
+ for (const m in resources) {
6422
+ if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
6423
+ silent: true
6424
+ });
6425
+ }
6426
+ if (!options.silent) this.emit('added', lng, ns, resources);
6427
+ }
6428
+ addResourceBundle(lng, ns, resources, deep, overwrite) {
6429
+ let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
6430
+ silent: false
6431
+ };
6432
+ let path = [lng, ns];
6433
+ if (lng.indexOf('.') > -1) {
6434
+ path = lng.split('.');
6435
+ deep = resources;
6436
+ resources = ns;
6437
+ ns = path[1];
6438
+ }
6439
+ this.addNamespaces(ns);
6440
+ let pack = getPath(this.data, path) || {};
6441
+ if (deep) {
6442
+ deepExtend(pack, resources, overwrite);
6443
+ } else {
6444
+ pack = {
6445
+ ...pack,
6446
+ ...resources
6447
+ };
6448
+ }
6449
+ setPath(this.data, path, pack);
6450
+ if (!options.silent) this.emit('added', lng, ns, resources);
6451
+ }
6452
+ removeResourceBundle(lng, ns) {
6453
+ if (this.hasResourceBundle(lng, ns)) {
6454
+ delete this.data[lng][ns];
6455
+ }
6456
+ this.removeNamespaces(ns);
6457
+ this.emit('removed', lng, ns);
6458
+ }
6459
+ hasResourceBundle(lng, ns) {
6460
+ return this.getResource(lng, ns) !== undefined;
6461
+ }
6462
+ getResourceBundle(lng, ns) {
6463
+ if (!ns) ns = this.options.defaultNS;
6464
+ if (this.options.compatibilityAPI === 'v1') return {
6465
+ ...{},
6466
+ ...this.getResource(lng, ns)
6467
+ };
6468
+ return this.getResource(lng, ns);
6469
+ }
6470
+ getDataByLanguage(lng) {
6471
+ return this.data[lng];
6472
+ }
6473
+ hasLanguageSomeTranslations(lng) {
6474
+ const data = this.getDataByLanguage(lng);
6475
+ const n = data && Object.keys(data) || [];
6476
+ return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
6477
+ }
6478
+ toJSON() {
6479
+ return this.data;
6480
+ }
6481
+ }
6482
+
6483
+ var postProcessor = {
6484
+ processors: {},
6485
+ addPostProcessor(module) {
6486
+ this.processors[module.name] = module;
6487
+ },
6488
+ handle(processors, value, key, options, translator) {
6489
+ processors.forEach(processor => {
6490
+ if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
6491
+ });
6492
+ return value;
6493
+ }
6494
+ };
6495
+
6496
+ const checkedLoadedFor = {};
6497
+ class Translator extends EventEmitter {
6498
+ constructor(services) {
6499
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6500
+ super();
6501
+ copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
6502
+ this.options = options;
6503
+ if (this.options.keySeparator === undefined) {
6504
+ this.options.keySeparator = '.';
6505
+ }
6506
+ this.logger = baseLogger.create('translator');
6507
+ }
6508
+ changeLanguage(lng) {
6509
+ if (lng) this.language = lng;
6510
+ }
6511
+ exists(key) {
6512
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
6513
+ interpolation: {}
6514
+ };
6515
+ if (key === undefined || key === null) {
6516
+ return false;
6517
+ }
6518
+ const resolved = this.resolve(key, options);
6519
+ return resolved && resolved.res !== undefined;
6520
+ }
6521
+ extractFromKey(key, options) {
6522
+ let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
6523
+ if (nsSeparator === undefined) nsSeparator = ':';
6524
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
6525
+ let namespaces = options.ns || this.options.defaultNS || [];
6526
+ const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
6527
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
6528
+ if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
6529
+ const m = key.match(this.interpolator.nestingRegexp);
6530
+ if (m && m.length > 0) {
6531
+ return {
6532
+ key,
6533
+ namespaces
6534
+ };
6535
+ }
6536
+ const parts = key.split(nsSeparator);
6537
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
6538
+ key = parts.join(keySeparator);
6539
+ }
6540
+ if (typeof namespaces === 'string') namespaces = [namespaces];
6541
+ return {
6542
+ key,
6543
+ namespaces
6544
+ };
6545
+ }
6546
+ translate(keys, options, lastKey) {
6547
+ if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
6548
+ options = this.options.overloadTranslationOptionHandler(arguments);
6549
+ }
6550
+ if (typeof options === 'object') options = {
6551
+ ...options
6552
+ };
6553
+ if (!options) options = {};
6554
+ if (keys === undefined || keys === null) return '';
6555
+ if (!Array.isArray(keys)) keys = [String(keys)];
6556
+ const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
6557
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
6558
+ const {
6559
+ key,
6560
+ namespaces
6561
+ } = this.extractFromKey(keys[keys.length - 1], options);
6562
+ const namespace = namespaces[namespaces.length - 1];
6563
+ const lng = options.lng || this.language;
6564
+ const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
6565
+ if (lng && lng.toLowerCase() === 'cimode') {
6566
+ if (appendNamespaceToCIMode) {
6567
+ const nsSeparator = options.nsSeparator || this.options.nsSeparator;
6568
+ if (returnDetails) {
6569
+ return {
6570
+ res: `${namespace}${nsSeparator}${key}`,
6571
+ usedKey: key,
6572
+ exactUsedKey: key,
6573
+ usedLng: lng,
6574
+ usedNS: namespace
6575
+ };
6576
+ }
6577
+ return `${namespace}${nsSeparator}${key}`;
6578
+ }
6579
+ if (returnDetails) {
6580
+ return {
6581
+ res: key,
6582
+ usedKey: key,
6583
+ exactUsedKey: key,
6584
+ usedLng: lng,
6585
+ usedNS: namespace
6586
+ };
6587
+ }
6588
+ return key;
6589
+ }
6590
+ const resolved = this.resolve(keys, options);
6591
+ let res = resolved && resolved.res;
6592
+ const resUsedKey = resolved && resolved.usedKey || key;
6593
+ const resExactUsedKey = resolved && resolved.exactUsedKey || key;
6594
+ const resType = Object.prototype.toString.apply(res);
6595
+ const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
6596
+ const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
6597
+ const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
6598
+ const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
6599
+ if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
6600
+ if (!options.returnObjects && !this.options.returnObjects) {
6601
+ if (!this.options.returnedObjectHandler) {
6602
+ this.logger.warn('accessing an object - but returnObjects options is not enabled!');
6603
+ }
6604
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
6605
+ ...options,
6606
+ ns: namespaces
6607
+ }) : `key '${key} (${this.language})' returned an object instead of string.`;
6608
+ if (returnDetails) {
6609
+ resolved.res = r;
6610
+ return resolved;
6611
+ }
6612
+ return r;
6613
+ }
6614
+ if (keySeparator) {
6615
+ const resTypeIsArray = resType === '[object Array]';
6616
+ const copy = resTypeIsArray ? [] : {};
6617
+ const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
6618
+ for (const m in res) {
6619
+ if (Object.prototype.hasOwnProperty.call(res, m)) {
6620
+ const deepKey = `${newKeyToUse}${keySeparator}${m}`;
6621
+ copy[m] = this.translate(deepKey, {
6622
+ ...options,
6623
+ ...{
6624
+ joinArrays: false,
6625
+ ns: namespaces
6626
+ }
6627
+ });
6628
+ if (copy[m] === deepKey) copy[m] = res[m];
6629
+ }
6630
+ }
6631
+ res = copy;
6632
+ }
6633
+ } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
6634
+ res = res.join(joinArrays);
6635
+ if (res) res = this.extendTranslation(res, keys, options, lastKey);
6636
+ } else {
6637
+ let usedDefault = false;
6638
+ let usedKey = false;
6639
+ const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
6640
+ const hasDefaultValue = Translator.hasDefaultValue(options);
6641
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
6642
+ const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
6643
+ ordinal: false
6644
+ }) : '';
6645
+ const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
6646
+ if (!this.isValidLookup(res) && hasDefaultValue) {
6647
+ usedDefault = true;
6648
+ res = defaultValue;
6649
+ }
6650
+ if (!this.isValidLookup(res)) {
6651
+ usedKey = true;
6652
+ res = key;
6653
+ }
6654
+ const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
6655
+ const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
6656
+ const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
6657
+ if (usedKey || usedDefault || updateMissing) {
6658
+ this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
6659
+ if (keySeparator) {
6660
+ const fk = this.resolve(key, {
6661
+ ...options,
6662
+ keySeparator: false
6663
+ });
6664
+ 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.');
6665
+ }
6666
+ let lngs = [];
6667
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
6668
+ if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
6669
+ for (let i = 0; i < fallbackLngs.length; i++) {
6670
+ lngs.push(fallbackLngs[i]);
6671
+ }
6672
+ } else if (this.options.saveMissingTo === 'all') {
6673
+ lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
6674
+ } else {
6675
+ lngs.push(options.lng || this.language);
6676
+ }
6677
+ const send = (l, k, specificDefaultValue) => {
6678
+ const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
6679
+ if (this.options.missingKeyHandler) {
6680
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
6681
+ } else if (this.backendConnector && this.backendConnector.saveMissing) {
6682
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
6683
+ }
6684
+ this.emit('missingKey', l, namespace, k, res);
6685
+ };
6686
+ if (this.options.saveMissing) {
6687
+ if (this.options.saveMissingPlurals && needsPluralHandling) {
6688
+ lngs.forEach(language => {
6689
+ this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
6690
+ send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
6691
+ });
6692
+ });
6693
+ } else {
6694
+ send(lngs, key, defaultValue);
6695
+ }
6696
+ }
6697
+ }
6698
+ res = this.extendTranslation(res, keys, options, resolved, lastKey);
6699
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
6700
+ if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
6701
+ if (this.options.compatibilityAPI !== 'v1') {
6702
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
6703
+ } else {
6704
+ res = this.options.parseMissingKeyHandler(res);
6705
+ }
6706
+ }
6707
+ }
6708
+ if (returnDetails) {
6709
+ resolved.res = res;
6710
+ return resolved;
6711
+ }
6712
+ return res;
6713
+ }
6714
+ extendTranslation(res, key, options, resolved, lastKey) {
6715
+ var _this = this;
6716
+ if (this.i18nFormat && this.i18nFormat.parse) {
6717
+ res = this.i18nFormat.parse(res, {
6718
+ ...this.options.interpolation.defaultVariables,
6719
+ ...options
6720
+ }, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
6721
+ resolved
6722
+ });
6723
+ } else if (!options.skipInterpolation) {
6724
+ if (options.interpolation) this.interpolator.init({
6725
+ ...options,
6726
+ ...{
6727
+ interpolation: {
6728
+ ...this.options.interpolation,
6729
+ ...options.interpolation
6730
+ }
6731
+ }
6732
+ });
6733
+ const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
6734
+ let nestBef;
6735
+ if (skipOnVariables) {
6736
+ const nb = res.match(this.interpolator.nestingRegexp);
6737
+ nestBef = nb && nb.length;
6738
+ }
6739
+ let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
6740
+ if (this.options.interpolation.defaultVariables) data = {
6741
+ ...this.options.interpolation.defaultVariables,
6742
+ ...data
6743
+ };
6744
+ res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
6745
+ if (skipOnVariables) {
6746
+ const na = res.match(this.interpolator.nestingRegexp);
6747
+ const nestAft = na && na.length;
6748
+ if (nestBef < nestAft) options.nest = false;
6749
+ }
6750
+ if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
6751
+ if (options.nest !== false) res = this.interpolator.nest(res, function () {
6752
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6753
+ args[_key] = arguments[_key];
6754
+ }
6755
+ if (lastKey && lastKey[0] === args[0] && !options.context) {
6756
+ _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
6757
+ return null;
6758
+ }
6759
+ return _this.translate(...args, key);
6760
+ }, options);
6761
+ if (options.interpolation) this.interpolator.reset();
6762
+ }
6763
+ const postProcess = options.postProcess || this.options.postProcess;
6764
+ const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
6765
+ if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
6766
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
6767
+ i18nResolved: resolved,
6768
+ ...options
6769
+ } : options, this);
6770
+ }
6771
+ return res;
6772
+ }
6773
+ resolve(keys) {
6774
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6775
+ let found;
6776
+ let usedKey;
6777
+ let exactUsedKey;
6778
+ let usedLng;
6779
+ let usedNS;
6780
+ if (typeof keys === 'string') keys = [keys];
6781
+ keys.forEach(k => {
6782
+ if (this.isValidLookup(found)) return;
6783
+ const extracted = this.extractFromKey(k, options);
6784
+ const key = extracted.key;
6785
+ usedKey = key;
6786
+ let namespaces = extracted.namespaces;
6787
+ if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
6788
+ const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
6789
+ const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
6790
+ const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
6791
+ const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
6792
+ namespaces.forEach(ns => {
6793
+ if (this.isValidLookup(found)) return;
6794
+ usedNS = ns;
6795
+ if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
6796
+ checkedLoadedFor[`${codes[0]}-${ns}`] = true;
6797
+ 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!!!');
6798
+ }
6799
+ codes.forEach(code => {
6800
+ if (this.isValidLookup(found)) return;
6801
+ usedLng = code;
6802
+ const finalKeys = [key];
6803
+ if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
6804
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
6805
+ } else {
6806
+ let pluralSuffix;
6807
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
6808
+ const zeroSuffix = `${this.options.pluralSeparator}zero`;
6809
+ const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
6810
+ if (needsPluralHandling) {
6811
+ finalKeys.push(key + pluralSuffix);
6812
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
6813
+ finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
6814
+ }
6815
+ if (needsZeroSuffixLookup) {
6816
+ finalKeys.push(key + zeroSuffix);
6817
+ }
6818
+ }
6819
+ if (needsContextHandling) {
6820
+ const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
6821
+ finalKeys.push(contextKey);
6822
+ if (needsPluralHandling) {
6823
+ finalKeys.push(contextKey + pluralSuffix);
6824
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
6825
+ finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
6826
+ }
6827
+ if (needsZeroSuffixLookup) {
6828
+ finalKeys.push(contextKey + zeroSuffix);
6829
+ }
6830
+ }
6831
+ }
6832
+ }
6833
+ let possibleKey;
6834
+ while (possibleKey = finalKeys.pop()) {
6835
+ if (!this.isValidLookup(found)) {
6836
+ exactUsedKey = possibleKey;
6837
+ found = this.getResource(code, ns, possibleKey, options);
6838
+ }
6839
+ }
6840
+ });
6841
+ });
6842
+ });
6843
+ return {
6844
+ res: found,
6845
+ usedKey,
6846
+ exactUsedKey,
6847
+ usedLng,
6848
+ usedNS
6849
+ };
6850
+ }
6851
+ isValidLookup(res) {
6852
+ return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
6853
+ }
6854
+ getResource(code, ns, key) {
6855
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6856
+ if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
6857
+ return this.resourceStore.getResource(code, ns, key, options);
6858
+ }
6859
+ static hasDefaultValue(options) {
6860
+ const prefix = 'defaultValue';
6861
+ for (const option in options) {
6862
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
6863
+ return true;
6864
+ }
6865
+ }
6866
+ return false;
6867
+ }
6868
+ }
6869
+
6870
+ function capitalize(string) {
6871
+ return string.charAt(0).toUpperCase() + string.slice(1);
6872
+ }
6873
+ class LanguageUtil {
6874
+ constructor(options) {
6875
+ this.options = options;
6876
+ this.supportedLngs = this.options.supportedLngs || false;
6877
+ this.logger = baseLogger.create('languageUtils');
6878
+ }
6879
+ getScriptPartFromCode(code) {
6880
+ code = getCleanedCode(code);
6881
+ if (!code || code.indexOf('-') < 0) return null;
6882
+ const p = code.split('-');
6883
+ if (p.length === 2) return null;
6884
+ p.pop();
6885
+ if (p[p.length - 1].toLowerCase() === 'x') return null;
6886
+ return this.formatLanguageCode(p.join('-'));
6887
+ }
6888
+ getLanguagePartFromCode(code) {
6889
+ code = getCleanedCode(code);
6890
+ if (!code || code.indexOf('-') < 0) return code;
6891
+ const p = code.split('-');
6892
+ return this.formatLanguageCode(p[0]);
6893
+ }
6894
+ formatLanguageCode(code) {
6895
+ if (typeof code === 'string' && code.indexOf('-') > -1) {
6896
+ const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
6897
+ let p = code.split('-');
6898
+ if (this.options.lowerCaseLng) {
6899
+ p = p.map(part => part.toLowerCase());
6900
+ } else if (p.length === 2) {
6901
+ p[0] = p[0].toLowerCase();
6902
+ p[1] = p[1].toUpperCase();
6903
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
6904
+ } else if (p.length === 3) {
6905
+ p[0] = p[0].toLowerCase();
6906
+ if (p[1].length === 2) p[1] = p[1].toUpperCase();
6907
+ if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
6908
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
6909
+ if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
6910
+ }
6911
+ return p.join('-');
6912
+ }
6913
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
6914
+ }
6915
+ isSupportedCode(code) {
6916
+ if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
6917
+ code = this.getLanguagePartFromCode(code);
6918
+ }
6919
+ return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
6920
+ }
6921
+ getBestMatchFromCodes(codes) {
6922
+ if (!codes) return null;
6923
+ let found;
6924
+ codes.forEach(code => {
6925
+ if (found) return;
6926
+ const cleanedLng = this.formatLanguageCode(code);
6927
+ if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
6928
+ });
6929
+ if (!found && this.options.supportedLngs) {
6930
+ codes.forEach(code => {
6931
+ if (found) return;
6932
+ const lngOnly = this.getLanguagePartFromCode(code);
6933
+ if (this.isSupportedCode(lngOnly)) return found = lngOnly;
6934
+ found = this.options.supportedLngs.find(supportedLng => {
6935
+ if (supportedLng === lngOnly) return supportedLng;
6936
+ if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
6937
+ if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
6938
+ });
6939
+ });
6940
+ }
6941
+ if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
6942
+ return found;
6943
+ }
6944
+ getFallbackCodes(fallbacks, code) {
6945
+ if (!fallbacks) return [];
6946
+ if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
6947
+ if (typeof fallbacks === 'string') fallbacks = [fallbacks];
6948
+ if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
6949
+ if (!code) return fallbacks.default || [];
6950
+ let found = fallbacks[code];
6951
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
6952
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
6953
+ if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
6954
+ if (!found) found = fallbacks.default;
6955
+ return found || [];
6956
+ }
6957
+ toResolveHierarchy(code, fallbackCode) {
6958
+ const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
6959
+ const codes = [];
6960
+ const addCode = c => {
6961
+ if (!c) return;
6962
+ if (this.isSupportedCode(c)) {
6963
+ codes.push(c);
6964
+ } else {
6965
+ this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
6966
+ }
6967
+ };
6968
+ if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
6969
+ if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
6970
+ if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
6971
+ if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
6972
+ } else if (typeof code === 'string') {
6973
+ addCode(this.formatLanguageCode(code));
6974
+ }
6975
+ fallbackCodes.forEach(fc => {
6976
+ if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
6977
+ });
6978
+ return codes;
6979
+ }
6980
+ }
6981
+
6982
+ let sets = [{
6983
+ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
6984
+ nr: [1, 2],
6985
+ fc: 1
6986
+ }, {
6987
+ lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
6988
+ nr: [1, 2],
6989
+ fc: 2
6990
+ }, {
6991
+ lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
6992
+ nr: [1],
6993
+ fc: 3
6994
+ }, {
6995
+ lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
6996
+ nr: [1, 2, 5],
6997
+ fc: 4
6998
+ }, {
6999
+ lngs: ['ar'],
7000
+ nr: [0, 1, 2, 3, 11, 100],
7001
+ fc: 5
7002
+ }, {
7003
+ lngs: ['cs', 'sk'],
7004
+ nr: [1, 2, 5],
7005
+ fc: 6
7006
+ }, {
7007
+ lngs: ['csb', 'pl'],
7008
+ nr: [1, 2, 5],
7009
+ fc: 7
7010
+ }, {
7011
+ lngs: ['cy'],
7012
+ nr: [1, 2, 3, 8],
7013
+ fc: 8
7014
+ }, {
7015
+ lngs: ['fr'],
7016
+ nr: [1, 2],
7017
+ fc: 9
7018
+ }, {
7019
+ lngs: ['ga'],
7020
+ nr: [1, 2, 3, 7, 11],
7021
+ fc: 10
7022
+ }, {
7023
+ lngs: ['gd'],
7024
+ nr: [1, 2, 3, 20],
7025
+ fc: 11
7026
+ }, {
7027
+ lngs: ['is'],
7028
+ nr: [1, 2],
7029
+ fc: 12
7030
+ }, {
7031
+ lngs: ['jv'],
7032
+ nr: [0, 1],
7033
+ fc: 13
7034
+ }, {
7035
+ lngs: ['kw'],
7036
+ nr: [1, 2, 3, 4],
7037
+ fc: 14
7038
+ }, {
7039
+ lngs: ['lt'],
7040
+ nr: [1, 2, 10],
7041
+ fc: 15
7042
+ }, {
7043
+ lngs: ['lv'],
7044
+ nr: [1, 2, 0],
7045
+ fc: 16
7046
+ }, {
7047
+ lngs: ['mk'],
7048
+ nr: [1, 2],
7049
+ fc: 17
7050
+ }, {
7051
+ lngs: ['mnk'],
7052
+ nr: [0, 1, 2],
7053
+ fc: 18
7054
+ }, {
7055
+ lngs: ['mt'],
7056
+ nr: [1, 2, 11, 20],
7057
+ fc: 19
7058
+ }, {
7059
+ lngs: ['or'],
7060
+ nr: [2, 1],
7061
+ fc: 2
7062
+ }, {
7063
+ lngs: ['ro'],
7064
+ nr: [1, 2, 20],
7065
+ fc: 20
7066
+ }, {
7067
+ lngs: ['sl'],
7068
+ nr: [5, 1, 2, 3],
7069
+ fc: 21
7070
+ }, {
7071
+ lngs: ['he', 'iw'],
7072
+ nr: [1, 2, 20, 21],
7073
+ fc: 22
7074
+ }];
7075
+ let _rulesPluralsTypes = {
7076
+ 1: function (n) {
7077
+ return Number(n > 1);
7078
+ },
7079
+ 2: function (n) {
7080
+ return Number(n != 1);
7081
+ },
7082
+ 3: function (n) {
7083
+ return 0;
7084
+ },
7085
+ 4: function (n) {
7086
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
7087
+ },
7088
+ 5: function (n) {
7089
+ return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
7090
+ },
7091
+ 6: function (n) {
7092
+ return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
7093
+ },
7094
+ 7: function (n) {
7095
+ return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
7096
+ },
7097
+ 8: function (n) {
7098
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
7099
+ },
7100
+ 9: function (n) {
7101
+ return Number(n >= 2);
7102
+ },
7103
+ 10: function (n) {
7104
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
7105
+ },
7106
+ 11: function (n) {
7107
+ return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
7108
+ },
7109
+ 12: function (n) {
7110
+ return Number(n % 10 != 1 || n % 100 == 11);
7111
+ },
7112
+ 13: function (n) {
7113
+ return Number(n !== 0);
7114
+ },
7115
+ 14: function (n) {
7116
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
7117
+ },
7118
+ 15: function (n) {
7119
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
7120
+ },
7121
+ 16: function (n) {
7122
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
7123
+ },
7124
+ 17: function (n) {
7125
+ return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
7126
+ },
7127
+ 18: function (n) {
7128
+ return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
7129
+ },
7130
+ 19: function (n) {
7131
+ return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
7132
+ },
7133
+ 20: function (n) {
7134
+ return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
7135
+ },
7136
+ 21: function (n) {
7137
+ return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
7138
+ },
7139
+ 22: function (n) {
7140
+ return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
7141
+ }
7142
+ };
7143
+ const nonIntlVersions = ['v1', 'v2', 'v3'];
7144
+ const intlVersions = ['v4'];
7145
+ const suffixesOrder = {
7146
+ zero: 0,
7147
+ one: 1,
7148
+ two: 2,
7149
+ few: 3,
7150
+ many: 4,
7151
+ other: 5
7152
+ };
7153
+ function createRules() {
7154
+ const rules = {};
7155
+ sets.forEach(set => {
7156
+ set.lngs.forEach(l => {
7157
+ rules[l] = {
7158
+ numbers: set.nr,
7159
+ plurals: _rulesPluralsTypes[set.fc]
7160
+ };
7161
+ });
7162
+ });
7163
+ return rules;
7164
+ }
7165
+ class PluralResolver {
7166
+ constructor(languageUtils) {
7167
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7168
+ this.languageUtils = languageUtils;
7169
+ this.options = options;
7170
+ this.logger = baseLogger.create('pluralResolver');
7171
+ if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
7172
+ this.options.compatibilityJSON = 'v3';
7173
+ 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.');
7174
+ }
7175
+ this.rules = createRules();
7176
+ }
7177
+ addRule(lng, obj) {
7178
+ this.rules[lng] = obj;
7179
+ }
7180
+ getRule(code) {
7181
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7182
+ if (this.shouldUseIntlApi()) {
7183
+ try {
7184
+ return new Intl.PluralRules(getCleanedCode(code), {
7185
+ type: options.ordinal ? 'ordinal' : 'cardinal'
7186
+ });
7187
+ } catch {
7188
+ return;
7189
+ }
7190
+ }
7191
+ return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
7192
+ }
7193
+ needsPlural(code) {
7194
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7195
+ const rule = this.getRule(code, options);
7196
+ if (this.shouldUseIntlApi()) {
7197
+ return rule && rule.resolvedOptions().pluralCategories.length > 1;
7198
+ }
7199
+ return rule && rule.numbers.length > 1;
7200
+ }
7201
+ getPluralFormsOfKey(code, key) {
7202
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7203
+ return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
7204
+ }
7205
+ getSuffixes(code) {
7206
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7207
+ const rule = this.getRule(code, options);
7208
+ if (!rule) {
7209
+ return [];
7210
+ }
7211
+ if (this.shouldUseIntlApi()) {
7212
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
7213
+ }
7214
+ return rule.numbers.map(number => this.getSuffix(code, number, options));
7215
+ }
7216
+ getSuffix(code, count) {
7217
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7218
+ const rule = this.getRule(code, options);
7219
+ if (rule) {
7220
+ if (this.shouldUseIntlApi()) {
7221
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
7222
+ }
7223
+ return this.getSuffixRetroCompatible(rule, count);
7224
+ }
7225
+ this.logger.warn(`no plural rule found for: ${code}`);
7226
+ return '';
7227
+ }
7228
+ getSuffixRetroCompatible(rule, count) {
7229
+ const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
7230
+ let suffix = rule.numbers[idx];
7231
+ if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
7232
+ if (suffix === 2) {
7233
+ suffix = 'plural';
7234
+ } else if (suffix === 1) {
7235
+ suffix = '';
7236
+ }
7237
+ }
7238
+ const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
7239
+ if (this.options.compatibilityJSON === 'v1') {
7240
+ if (suffix === 1) return '';
7241
+ if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
7242
+ return returnSuffix();
7243
+ } else if (this.options.compatibilityJSON === 'v2') {
7244
+ return returnSuffix();
7245
+ } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
7246
+ return returnSuffix();
7247
+ }
7248
+ return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
7249
+ }
7250
+ shouldUseIntlApi() {
7251
+ return !nonIntlVersions.includes(this.options.compatibilityJSON);
7252
+ }
7253
+ }
7254
+
7255
+ function deepFindWithDefaults(data, defaultData, key) {
7256
+ let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
7257
+ let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
7258
+ let path = getPathWithDefaults(data, defaultData, key);
7259
+ if (!path && ignoreJSONStructure && typeof key === 'string') {
7260
+ path = deepFind(data, key, keySeparator);
7261
+ if (path === undefined) path = deepFind(defaultData, key, keySeparator);
7262
+ }
7263
+ return path;
7264
+ }
7265
+ class Interpolator {
7266
+ constructor() {
7267
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7268
+ this.logger = baseLogger.create('interpolator');
7269
+ this.options = options;
7270
+ this.format = options.interpolation && options.interpolation.format || (value => value);
7271
+ this.init(options);
7272
+ }
7273
+ init() {
7274
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7275
+ if (!options.interpolation) options.interpolation = {
7276
+ escapeValue: true
7277
+ };
7278
+ const iOpts = options.interpolation;
7279
+ this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
7280
+ this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
7281
+ this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
7282
+ this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
7283
+ this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
7284
+ this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
7285
+ this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
7286
+ this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
7287
+ this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
7288
+ this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
7289
+ this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
7290
+ this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
7291
+ this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
7292
+ this.resetRegExp();
7293
+ }
7294
+ reset() {
7295
+ if (this.options) this.init(this.options);
7296
+ }
7297
+ resetRegExp() {
7298
+ const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
7299
+ this.regexp = new RegExp(regexpStr, 'g');
7300
+ const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
7301
+ this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
7302
+ const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
7303
+ this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
7304
+ }
7305
+ interpolate(str, data, lng, options) {
7306
+ let match;
7307
+ let value;
7308
+ let replaces;
7309
+ const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
7310
+ function regexSafe(val) {
7311
+ return val.replace(/\$/g, '$$$$');
7312
+ }
7313
+ const handleFormat = key => {
7314
+ if (key.indexOf(this.formatSeparator) < 0) {
7315
+ const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
7316
+ return this.alwaysFormat ? this.format(path, undefined, lng, {
7317
+ ...options,
7318
+ ...data,
7319
+ interpolationkey: key
7320
+ }) : path;
7321
+ }
7322
+ const p = key.split(this.formatSeparator);
7323
+ const k = p.shift().trim();
7324
+ const f = p.join(this.formatSeparator).trim();
7325
+ return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
7326
+ ...options,
7327
+ ...data,
7328
+ interpolationkey: k
7329
+ });
7330
+ };
7331
+ this.resetRegExp();
7332
+ const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
7333
+ const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
7334
+ const todos = [{
7335
+ regex: this.regexpUnescape,
7336
+ safeValue: val => regexSafe(val)
7337
+ }, {
7338
+ regex: this.regexp,
7339
+ safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
7340
+ }];
7341
+ todos.forEach(todo => {
7342
+ replaces = 0;
7343
+ while (match = todo.regex.exec(str)) {
7344
+ const matchedVar = match[1].trim();
7345
+ value = handleFormat(matchedVar);
7346
+ if (value === undefined) {
7347
+ if (typeof missingInterpolationHandler === 'function') {
7348
+ const temp = missingInterpolationHandler(str, match, options);
7349
+ value = typeof temp === 'string' ? temp : '';
7350
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
7351
+ value = '';
7352
+ } else if (skipOnVariables) {
7353
+ value = match[0];
7354
+ continue;
7355
+ } else {
7356
+ this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
7357
+ value = '';
7358
+ }
7359
+ } else if (typeof value !== 'string' && !this.useRawValueToEscape) {
7360
+ value = makeString(value);
7361
+ }
7362
+ const safeValue = todo.safeValue(value);
7363
+ str = str.replace(match[0], safeValue);
7364
+ if (skipOnVariables) {
7365
+ todo.regex.lastIndex += value.length;
7366
+ todo.regex.lastIndex -= match[0].length;
7367
+ } else {
7368
+ todo.regex.lastIndex = 0;
7369
+ }
7370
+ replaces++;
7371
+ if (replaces >= this.maxReplaces) {
7372
+ break;
7373
+ }
7374
+ }
7375
+ });
7376
+ return str;
7377
+ }
7378
+ nest(str, fc) {
7379
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7380
+ let match;
7381
+ let value;
7382
+ let clonedOptions;
7383
+ function handleHasOptions(key, inheritedOptions) {
7384
+ const sep = this.nestingOptionsSeparator;
7385
+ if (key.indexOf(sep) < 0) return key;
7386
+ const c = key.split(new RegExp(`${sep}[ ]*{`));
7387
+ let optionsString = `{${c[1]}`;
7388
+ key = c[0];
7389
+ optionsString = this.interpolate(optionsString, clonedOptions);
7390
+ const matchedSingleQuotes = optionsString.match(/'/g);
7391
+ const matchedDoubleQuotes = optionsString.match(/"/g);
7392
+ if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
7393
+ optionsString = optionsString.replace(/'/g, '"');
7394
+ }
7395
+ try {
7396
+ clonedOptions = JSON.parse(optionsString);
7397
+ if (inheritedOptions) clonedOptions = {
7398
+ ...inheritedOptions,
7399
+ ...clonedOptions
7400
+ };
7401
+ } catch (e) {
7402
+ this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
7403
+ return `${key}${sep}${optionsString}`;
7404
+ }
7405
+ delete clonedOptions.defaultValue;
7406
+ return key;
7407
+ }
7408
+ while (match = this.nestingRegexp.exec(str)) {
7409
+ let formatters = [];
7410
+ clonedOptions = {
7411
+ ...options
7412
+ };
7413
+ clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
7414
+ clonedOptions.applyPostProcessor = false;
7415
+ delete clonedOptions.defaultValue;
7416
+ let doReduce = false;
7417
+ if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
7418
+ const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
7419
+ match[1] = r.shift();
7420
+ formatters = r;
7421
+ doReduce = true;
7422
+ }
7423
+ value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
7424
+ if (value && match[0] === str && typeof value !== 'string') return value;
7425
+ if (typeof value !== 'string') value = makeString(value);
7426
+ if (!value) {
7427
+ this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
7428
+ value = '';
7429
+ }
7430
+ if (doReduce) {
7431
+ value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
7432
+ ...options,
7433
+ interpolationkey: match[1].trim()
7434
+ }), value.trim());
7435
+ }
7436
+ str = str.replace(match[0], value);
7437
+ this.regexp.lastIndex = 0;
7438
+ }
7439
+ return str;
7440
+ }
7441
+ }
7442
+
7443
+ function parseFormatStr(formatStr) {
7444
+ let formatName = formatStr.toLowerCase().trim();
7445
+ const formatOptions = {};
7446
+ if (formatStr.indexOf('(') > -1) {
7447
+ const p = formatStr.split('(');
7448
+ formatName = p[0].toLowerCase().trim();
7449
+ const optStr = p[1].substring(0, p[1].length - 1);
7450
+ if (formatName === 'currency' && optStr.indexOf(':') < 0) {
7451
+ if (!formatOptions.currency) formatOptions.currency = optStr.trim();
7452
+ } else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
7453
+ if (!formatOptions.range) formatOptions.range = optStr.trim();
7454
+ } else {
7455
+ const opts = optStr.split(';');
7456
+ opts.forEach(opt => {
7457
+ if (!opt) return;
7458
+ const [key, ...rest] = opt.split(':');
7459
+ const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
7460
+ if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
7461
+ if (val === 'false') formatOptions[key.trim()] = false;
7462
+ if (val === 'true') formatOptions[key.trim()] = true;
7463
+ if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
7464
+ });
7465
+ }
7466
+ }
7467
+ return {
7468
+ formatName,
7469
+ formatOptions
7470
+ };
7471
+ }
7472
+ function createCachedFormatter(fn) {
7473
+ const cache = {};
7474
+ return function invokeFormatter(val, lng, options) {
7475
+ const key = lng + JSON.stringify(options);
7476
+ let formatter = cache[key];
7477
+ if (!formatter) {
7478
+ formatter = fn(getCleanedCode(lng), options);
7479
+ cache[key] = formatter;
7480
+ }
7481
+ return formatter(val);
7482
+ };
7483
+ }
7484
+ class Formatter {
7485
+ constructor() {
7486
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7487
+ this.logger = baseLogger.create('formatter');
7488
+ this.options = options;
7489
+ this.formats = {
7490
+ number: createCachedFormatter((lng, opt) => {
7491
+ const formatter = new Intl.NumberFormat(lng, {
7492
+ ...opt
7493
+ });
7494
+ return val => formatter.format(val);
7495
+ }),
7496
+ currency: createCachedFormatter((lng, opt) => {
7497
+ const formatter = new Intl.NumberFormat(lng, {
7498
+ ...opt,
7499
+ style: 'currency'
7500
+ });
7501
+ return val => formatter.format(val);
7502
+ }),
7503
+ datetime: createCachedFormatter((lng, opt) => {
7504
+ const formatter = new Intl.DateTimeFormat(lng, {
7505
+ ...opt
7506
+ });
7507
+ return val => formatter.format(val);
7508
+ }),
7509
+ relativetime: createCachedFormatter((lng, opt) => {
7510
+ const formatter = new Intl.RelativeTimeFormat(lng, {
7511
+ ...opt
7512
+ });
7513
+ return val => formatter.format(val, opt.range || 'day');
7514
+ }),
7515
+ list: createCachedFormatter((lng, opt) => {
7516
+ const formatter = new Intl.ListFormat(lng, {
7517
+ ...opt
7518
+ });
7519
+ return val => formatter.format(val);
7520
+ })
7521
+ };
7522
+ this.init(options);
7523
+ }
7524
+ init(services) {
7525
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
7526
+ interpolation: {}
7527
+ };
7528
+ const iOpts = options.interpolation;
7529
+ this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
7530
+ }
7531
+ add(name, fc) {
7532
+ this.formats[name.toLowerCase().trim()] = fc;
7533
+ }
7534
+ addCached(name, fc) {
7535
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
7536
+ }
7537
+ format(value, format, lng) {
7538
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
7539
+ const formats = format.split(this.formatSeparator);
7540
+ const result = formats.reduce((mem, f) => {
7541
+ const {
7542
+ formatName,
7543
+ formatOptions
7544
+ } = parseFormatStr(f);
7545
+ if (this.formats[formatName]) {
7546
+ let formatted = mem;
7547
+ try {
7548
+ const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
7549
+ const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
7550
+ formatted = this.formats[formatName](mem, l, {
7551
+ ...formatOptions,
7552
+ ...options,
7553
+ ...valOptions
7554
+ });
7555
+ } catch (error) {
7556
+ this.logger.warn(error);
7557
+ }
7558
+ return formatted;
7559
+ } else {
7560
+ this.logger.warn(`there was no format function for ${formatName}`);
7561
+ }
7562
+ return mem;
7563
+ }, value);
7564
+ return result;
7565
+ }
7566
+ }
7567
+
7568
+ function removePending(q, name) {
7569
+ if (q.pending[name] !== undefined) {
7570
+ delete q.pending[name];
7571
+ q.pendingCount--;
7572
+ }
7573
+ }
7574
+ class Connector extends EventEmitter {
7575
+ constructor(backend, store, services) {
7576
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
7577
+ super();
7578
+ this.backend = backend;
7579
+ this.store = store;
7580
+ this.services = services;
7581
+ this.languageUtils = services.languageUtils;
7582
+ this.options = options;
7583
+ this.logger = baseLogger.create('backendConnector');
7584
+ this.waitingReads = [];
7585
+ this.maxParallelReads = options.maxParallelReads || 10;
7586
+ this.readingCalls = 0;
7587
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
7588
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
7589
+ this.state = {};
7590
+ this.queue = [];
7591
+ if (this.backend && this.backend.init) {
7592
+ this.backend.init(services, options.backend, options);
7593
+ }
7594
+ }
7595
+ queueLoad(languages, namespaces, options, callback) {
7596
+ const toLoad = {};
7597
+ const pending = {};
7598
+ const toLoadLanguages = {};
7599
+ const toLoadNamespaces = {};
7600
+ languages.forEach(lng => {
7601
+ let hasAllNamespaces = true;
7602
+ namespaces.forEach(ns => {
7603
+ const name = `${lng}|${ns}`;
7604
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
7605
+ this.state[name] = 2;
7606
+ } else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
7607
+ if (pending[name] === undefined) pending[name] = true;
7608
+ } else {
7609
+ this.state[name] = 1;
7610
+ hasAllNamespaces = false;
7611
+ if (pending[name] === undefined) pending[name] = true;
7612
+ if (toLoad[name] === undefined) toLoad[name] = true;
7613
+ if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
7614
+ }
7615
+ });
7616
+ if (!hasAllNamespaces) toLoadLanguages[lng] = true;
7617
+ });
7618
+ if (Object.keys(toLoad).length || Object.keys(pending).length) {
7619
+ this.queue.push({
7620
+ pending,
7621
+ pendingCount: Object.keys(pending).length,
7622
+ loaded: {},
7623
+ errors: [],
7624
+ callback
7625
+ });
7626
+ }
7627
+ return {
7628
+ toLoad: Object.keys(toLoad),
7629
+ pending: Object.keys(pending),
7630
+ toLoadLanguages: Object.keys(toLoadLanguages),
7631
+ toLoadNamespaces: Object.keys(toLoadNamespaces)
7632
+ };
7633
+ }
7634
+ loaded(name, err, data) {
7635
+ const s = name.split('|');
7636
+ const lng = s[0];
7637
+ const ns = s[1];
7638
+ if (err) this.emit('failedLoading', lng, ns, err);
7639
+ if (data) {
7640
+ this.store.addResourceBundle(lng, ns, data);
7641
+ }
7642
+ this.state[name] = err ? -1 : 2;
7643
+ const loaded = {};
7644
+ this.queue.forEach(q => {
7645
+ pushPath(q.loaded, [lng], ns);
7646
+ removePending(q, name);
7647
+ if (err) q.errors.push(err);
7648
+ if (q.pendingCount === 0 && !q.done) {
7649
+ Object.keys(q.loaded).forEach(l => {
7650
+ if (!loaded[l]) loaded[l] = {};
7651
+ const loadedKeys = q.loaded[l];
7652
+ if (loadedKeys.length) {
7653
+ loadedKeys.forEach(n => {
7654
+ if (loaded[l][n] === undefined) loaded[l][n] = true;
7655
+ });
7656
+ }
7657
+ });
7658
+ q.done = true;
7659
+ if (q.errors.length) {
7660
+ q.callback(q.errors);
7661
+ } else {
7662
+ q.callback();
7663
+ }
7664
+ }
7665
+ });
7666
+ this.emit('loaded', loaded);
7667
+ this.queue = this.queue.filter(q => !q.done);
7668
+ }
7669
+ read(lng, ns, fcName) {
7670
+ let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
7671
+ let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
7672
+ let callback = arguments.length > 5 ? arguments[5] : undefined;
7673
+ if (!lng.length) return callback(null, {});
7674
+ if (this.readingCalls >= this.maxParallelReads) {
7675
+ this.waitingReads.push({
7676
+ lng,
7677
+ ns,
7678
+ fcName,
7679
+ tried,
7680
+ wait,
7681
+ callback
7682
+ });
7683
+ return;
7684
+ }
7685
+ this.readingCalls++;
7686
+ const resolver = (err, data) => {
7687
+ this.readingCalls--;
7688
+ if (this.waitingReads.length > 0) {
7689
+ const next = this.waitingReads.shift();
7690
+ this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
7691
+ }
7692
+ if (err && data && tried < this.maxRetries) {
7693
+ setTimeout(() => {
7694
+ this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
7695
+ }, wait);
7696
+ return;
7697
+ }
7698
+ callback(err, data);
7699
+ };
7700
+ const fc = this.backend[fcName].bind(this.backend);
7701
+ if (fc.length === 2) {
7702
+ try {
7703
+ const r = fc(lng, ns);
7704
+ if (r && typeof r.then === 'function') {
7705
+ r.then(data => resolver(null, data)).catch(resolver);
7706
+ } else {
7707
+ resolver(null, r);
7708
+ }
7709
+ } catch (err) {
7710
+ resolver(err);
7711
+ }
7712
+ return;
7713
+ }
7714
+ return fc(lng, ns, resolver);
7715
+ }
7716
+ prepareLoading(languages, namespaces) {
7717
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7718
+ let callback = arguments.length > 3 ? arguments[3] : undefined;
7719
+ if (!this.backend) {
7720
+ this.logger.warn('No backend was added via i18next.use. Will not load resources.');
7721
+ return callback && callback();
7722
+ }
7723
+ if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
7724
+ if (typeof namespaces === 'string') namespaces = [namespaces];
7725
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
7726
+ if (!toLoad.toLoad.length) {
7727
+ if (!toLoad.pending.length) callback();
7728
+ return null;
7729
+ }
7730
+ toLoad.toLoad.forEach(name => {
7731
+ this.loadOne(name);
7732
+ });
7733
+ }
7734
+ load(languages, namespaces, callback) {
7735
+ this.prepareLoading(languages, namespaces, {}, callback);
7736
+ }
7737
+ reload(languages, namespaces, callback) {
7738
+ this.prepareLoading(languages, namespaces, {
7739
+ reload: true
7740
+ }, callback);
7741
+ }
7742
+ loadOne(name) {
7743
+ let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
7744
+ const s = name.split('|');
7745
+ const lng = s[0];
7746
+ const ns = s[1];
7747
+ this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
7748
+ if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
7749
+ if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
7750
+ this.loaded(name, err, data);
7751
+ });
7752
+ }
7753
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
7754
+ let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
7755
+ let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
7756
+ if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
7757
+ 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!!!');
7758
+ return;
7759
+ }
7760
+ if (key === undefined || key === null || key === '') return;
7761
+ if (this.backend && this.backend.create) {
7762
+ const opts = {
7763
+ ...options,
7764
+ isUpdate
7765
+ };
7766
+ const fc = this.backend.create.bind(this.backend);
7767
+ if (fc.length < 6) {
7768
+ try {
7769
+ let r;
7770
+ if (fc.length === 5) {
7771
+ r = fc(languages, namespace, key, fallbackValue, opts);
7772
+ } else {
7773
+ r = fc(languages, namespace, key, fallbackValue);
7774
+ }
7775
+ if (r && typeof r.then === 'function') {
7776
+ r.then(data => clb(null, data)).catch(clb);
7777
+ } else {
7778
+ clb(null, r);
7779
+ }
7780
+ } catch (err) {
7781
+ clb(err);
7782
+ }
7783
+ } else {
7784
+ fc(languages, namespace, key, fallbackValue, clb, opts);
7785
+ }
7786
+ }
7787
+ if (!languages || !languages[0]) return;
7788
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
7789
+ }
7790
+ }
7791
+
7792
+ function get() {
7793
+ return {
7794
+ debug: false,
7795
+ initImmediate: true,
7796
+ ns: ['translation'],
7797
+ defaultNS: ['translation'],
7798
+ fallbackLng: ['dev'],
7799
+ fallbackNS: false,
7800
+ supportedLngs: false,
7801
+ nonExplicitSupportedLngs: false,
7802
+ load: 'all',
7803
+ preload: false,
7804
+ simplifyPluralSuffix: true,
7805
+ keySeparator: '.',
7806
+ nsSeparator: ':',
7807
+ pluralSeparator: '_',
7808
+ contextSeparator: '_',
7809
+ partialBundledLanguages: false,
7810
+ saveMissing: false,
7811
+ updateMissing: false,
7812
+ saveMissingTo: 'fallback',
7813
+ saveMissingPlurals: true,
7814
+ missingKeyHandler: false,
7815
+ missingInterpolationHandler: false,
7816
+ postProcess: false,
7817
+ postProcessPassResolved: false,
7818
+ returnNull: false,
7819
+ returnEmptyString: true,
7820
+ returnObjects: false,
7821
+ joinArrays: false,
7822
+ returnedObjectHandler: false,
7823
+ parseMissingKeyHandler: false,
7824
+ appendNamespaceToMissingKey: false,
7825
+ appendNamespaceToCIMode: false,
7826
+ overloadTranslationOptionHandler: function handle(args) {
7827
+ let ret = {};
7828
+ if (typeof args[1] === 'object') ret = args[1];
7829
+ if (typeof args[1] === 'string') ret.defaultValue = args[1];
7830
+ if (typeof args[2] === 'string') ret.tDescription = args[2];
7831
+ if (typeof args[2] === 'object' || typeof args[3] === 'object') {
7832
+ const options = args[3] || args[2];
7833
+ Object.keys(options).forEach(key => {
7834
+ ret[key] = options[key];
7835
+ });
7836
+ }
7837
+ return ret;
7838
+ },
7839
+ interpolation: {
7840
+ escapeValue: true,
7841
+ format: (value, format, lng, options) => value,
7842
+ prefix: '{{',
7843
+ suffix: '}}',
7844
+ formatSeparator: ',',
7845
+ unescapePrefix: '-',
7846
+ nestingPrefix: '$t(',
7847
+ nestingSuffix: ')',
7848
+ nestingOptionsSeparator: ',',
7849
+ maxReplaces: 1000,
7850
+ skipOnVariables: true
7851
+ }
7852
+ };
7853
+ }
7854
+ function transformOptions(options) {
7855
+ if (typeof options.ns === 'string') options.ns = [options.ns];
7856
+ if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
7857
+ if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
7858
+ if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
7859
+ options.supportedLngs = options.supportedLngs.concat(['cimode']);
7860
+ }
7861
+ return options;
7862
+ }
7863
+
7864
+ function noop() {}
7865
+ function bindMemberFunctions(inst) {
7866
+ const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
7867
+ mems.forEach(mem => {
7868
+ if (typeof inst[mem] === 'function') {
7869
+ inst[mem] = inst[mem].bind(inst);
7870
+ }
7871
+ });
7872
+ }
7873
+ class I18n extends EventEmitter {
7874
+ constructor() {
7875
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7876
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
7877
+ super();
7878
+ this.options = transformOptions(options);
7879
+ this.services = {};
7880
+ this.logger = baseLogger;
7881
+ this.modules = {
7882
+ external: []
7883
+ };
7884
+ bindMemberFunctions(this);
7885
+ if (callback && !this.isInitialized && !options.isClone) {
7886
+ if (!this.options.initImmediate) {
7887
+ this.init(options, callback);
7888
+ return this;
7889
+ }
7890
+ setTimeout(() => {
7891
+ this.init(options, callback);
7892
+ }, 0);
7893
+ }
7894
+ }
7895
+ init() {
7896
+ var _this = this;
7897
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7898
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
7899
+ if (typeof options === 'function') {
7900
+ callback = options;
7901
+ options = {};
7902
+ }
7903
+ if (!options.defaultNS && options.defaultNS !== false && options.ns) {
7904
+ if (typeof options.ns === 'string') {
7905
+ options.defaultNS = options.ns;
7906
+ } else if (options.ns.indexOf('translation') < 0) {
7907
+ options.defaultNS = options.ns[0];
7908
+ }
7909
+ }
7910
+ const defOpts = get();
7911
+ this.options = {
7912
+ ...defOpts,
7913
+ ...this.options,
7914
+ ...transformOptions(options)
7915
+ };
7916
+ if (this.options.compatibilityAPI !== 'v1') {
7917
+ this.options.interpolation = {
7918
+ ...defOpts.interpolation,
7919
+ ...this.options.interpolation
7920
+ };
7921
+ }
7922
+ if (options.keySeparator !== undefined) {
7923
+ this.options.userDefinedKeySeparator = options.keySeparator;
7924
+ }
7925
+ if (options.nsSeparator !== undefined) {
7926
+ this.options.userDefinedNsSeparator = options.nsSeparator;
7927
+ }
7928
+ function createClassOnDemand(ClassOrObject) {
7929
+ if (!ClassOrObject) return null;
7930
+ if (typeof ClassOrObject === 'function') return new ClassOrObject();
7931
+ return ClassOrObject;
7932
+ }
7933
+ if (!this.options.isClone) {
7934
+ if (this.modules.logger) {
7935
+ baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
7936
+ } else {
7937
+ baseLogger.init(null, this.options);
7938
+ }
7939
+ let formatter;
7940
+ if (this.modules.formatter) {
7941
+ formatter = this.modules.formatter;
7942
+ } else if (typeof Intl !== 'undefined') {
7943
+ formatter = Formatter;
7944
+ }
7945
+ const lu = new LanguageUtil(this.options);
7946
+ this.store = new ResourceStore(this.options.resources, this.options);
7947
+ const s = this.services;
7948
+ s.logger = baseLogger;
7949
+ s.resourceStore = this.store;
7950
+ s.languageUtils = lu;
7951
+ s.pluralResolver = new PluralResolver(lu, {
7952
+ prepend: this.options.pluralSeparator,
7953
+ compatibilityJSON: this.options.compatibilityJSON,
7954
+ simplifyPluralSuffix: this.options.simplifyPluralSuffix
7955
+ });
7956
+ if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
7957
+ s.formatter = createClassOnDemand(formatter);
7958
+ s.formatter.init(s, this.options);
7959
+ this.options.interpolation.format = s.formatter.format.bind(s.formatter);
7960
+ }
7961
+ s.interpolator = new Interpolator(this.options);
7962
+ s.utils = {
7963
+ hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
7964
+ };
7965
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
7966
+ s.backendConnector.on('*', function (event) {
7967
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
7968
+ args[_key - 1] = arguments[_key];
7969
+ }
7970
+ _this.emit(event, ...args);
7971
+ });
7972
+ if (this.modules.languageDetector) {
7973
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
7974
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
7975
+ }
7976
+ if (this.modules.i18nFormat) {
7977
+ s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
7978
+ if (s.i18nFormat.init) s.i18nFormat.init(this);
7979
+ }
7980
+ this.translator = new Translator(this.services, this.options);
7981
+ this.translator.on('*', function (event) {
7982
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
7983
+ args[_key2 - 1] = arguments[_key2];
7984
+ }
7985
+ _this.emit(event, ...args);
7986
+ });
7987
+ this.modules.external.forEach(m => {
7988
+ if (m.init) m.init(this);
7989
+ });
7990
+ }
7991
+ this.format = this.options.interpolation.format;
7992
+ if (!callback) callback = noop;
7993
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
7994
+ const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
7995
+ if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
7996
+ }
7997
+ if (!this.services.languageDetector && !this.options.lng) {
7998
+ this.logger.warn('init: no languageDetector is used and no lng is defined');
7999
+ }
8000
+ const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
8001
+ storeApi.forEach(fcName => {
8002
+ this[fcName] = function () {
8003
+ return _this.store[fcName](...arguments);
8004
+ };
8005
+ });
8006
+ const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
8007
+ storeApiChained.forEach(fcName => {
8008
+ this[fcName] = function () {
8009
+ _this.store[fcName](...arguments);
8010
+ return _this;
8011
+ };
8012
+ });
8013
+ const deferred = defer();
8014
+ const load = () => {
8015
+ const finish = (err, t) => {
8016
+ if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
8017
+ this.isInitialized = true;
8018
+ if (!this.options.isClone) this.logger.log('initialized', this.options);
8019
+ this.emit('initialized', this.options);
8020
+ deferred.resolve(t);
8021
+ callback(err, t);
8022
+ };
8023
+ if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
8024
+ this.changeLanguage(this.options.lng, finish);
8025
+ };
8026
+ if (this.options.resources || !this.options.initImmediate) {
8027
+ load();
8028
+ } else {
8029
+ setTimeout(load, 0);
8030
+ }
8031
+ return deferred;
8032
+ }
8033
+ loadResources(language) {
8034
+ let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
8035
+ let usedCallback = callback;
8036
+ const usedLng = typeof language === 'string' ? language : this.language;
8037
+ if (typeof language === 'function') usedCallback = language;
8038
+ if (!this.options.resources || this.options.partialBundledLanguages) {
8039
+ if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
8040
+ const toLoad = [];
8041
+ const append = lng => {
8042
+ if (!lng) return;
8043
+ const lngs = this.services.languageUtils.toResolveHierarchy(lng);
8044
+ lngs.forEach(l => {
8045
+ if (toLoad.indexOf(l) < 0) toLoad.push(l);
8046
+ });
8047
+ };
8048
+ if (!usedLng) {
8049
+ const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
8050
+ fallbacks.forEach(l => append(l));
8051
+ } else {
8052
+ append(usedLng);
8053
+ }
8054
+ if (this.options.preload) {
8055
+ this.options.preload.forEach(l => append(l));
8056
+ }
8057
+ this.services.backendConnector.load(toLoad, this.options.ns, e => {
8058
+ if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
8059
+ usedCallback(e);
8060
+ });
8061
+ } else {
8062
+ usedCallback(null);
8063
+ }
8064
+ }
8065
+ reloadResources(lngs, ns, callback) {
8066
+ const deferred = defer();
8067
+ if (!lngs) lngs = this.languages;
8068
+ if (!ns) ns = this.options.ns;
8069
+ if (!callback) callback = noop;
8070
+ this.services.backendConnector.reload(lngs, ns, err => {
8071
+ deferred.resolve();
8072
+ callback(err);
8073
+ });
8074
+ return deferred;
8075
+ }
8076
+ use(module) {
8077
+ if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
8078
+ if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
8079
+ if (module.type === 'backend') {
8080
+ this.modules.backend = module;
8081
+ }
8082
+ if (module.type === 'logger' || module.log && module.warn && module.error) {
8083
+ this.modules.logger = module;
8084
+ }
8085
+ if (module.type === 'languageDetector') {
8086
+ this.modules.languageDetector = module;
8087
+ }
8088
+ if (module.type === 'i18nFormat') {
8089
+ this.modules.i18nFormat = module;
8090
+ }
8091
+ if (module.type === 'postProcessor') {
8092
+ postProcessor.addPostProcessor(module);
8093
+ }
8094
+ if (module.type === 'formatter') {
8095
+ this.modules.formatter = module;
8096
+ }
8097
+ if (module.type === '3rdParty') {
8098
+ this.modules.external.push(module);
8099
+ }
8100
+ return this;
8101
+ }
8102
+ setResolvedLanguage(l) {
8103
+ if (!l || !this.languages) return;
8104
+ if (['cimode', 'dev'].indexOf(l) > -1) return;
8105
+ for (let li = 0; li < this.languages.length; li++) {
8106
+ const lngInLngs = this.languages[li];
8107
+ if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
8108
+ if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
8109
+ this.resolvedLanguage = lngInLngs;
8110
+ break;
8111
+ }
8112
+ }
8113
+ }
8114
+ changeLanguage(lng, callback) {
8115
+ var _this2 = this;
8116
+ this.isLanguageChangingTo = lng;
8117
+ const deferred = defer();
8118
+ this.emit('languageChanging', lng);
8119
+ const setLngProps = l => {
8120
+ this.language = l;
8121
+ this.languages = this.services.languageUtils.toResolveHierarchy(l);
8122
+ this.resolvedLanguage = undefined;
8123
+ this.setResolvedLanguage(l);
8124
+ };
8125
+ const done = (err, l) => {
8126
+ if (l) {
8127
+ setLngProps(l);
8128
+ this.translator.changeLanguage(l);
8129
+ this.isLanguageChangingTo = undefined;
8130
+ this.emit('languageChanged', l);
8131
+ this.logger.log('languageChanged', l);
8132
+ } else {
8133
+ this.isLanguageChangingTo = undefined;
8134
+ }
8135
+ deferred.resolve(function () {
8136
+ return _this2.t(...arguments);
8137
+ });
8138
+ if (callback) callback(err, function () {
8139
+ return _this2.t(...arguments);
8140
+ });
8141
+ };
8142
+ const setLng = lngs => {
8143
+ if (!lng && !lngs && this.services.languageDetector) lngs = [];
8144
+ const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
8145
+ if (l) {
8146
+ if (!this.language) {
8147
+ setLngProps(l);
8148
+ }
8149
+ if (!this.translator.language) this.translator.changeLanguage(l);
8150
+ if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
8151
+ }
8152
+ this.loadResources(l, err => {
8153
+ done(err, l);
8154
+ });
8155
+ };
8156
+ if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
8157
+ setLng(this.services.languageDetector.detect());
8158
+ } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
8159
+ if (this.services.languageDetector.detect.length === 0) {
8160
+ this.services.languageDetector.detect().then(setLng);
8161
+ } else {
8162
+ this.services.languageDetector.detect(setLng);
8163
+ }
8164
+ } else {
8165
+ setLng(lng);
8166
+ }
8167
+ return deferred;
8168
+ }
8169
+ getFixedT(lng, ns, keyPrefix) {
8170
+ var _this3 = this;
8171
+ const fixedT = function (key, opts) {
8172
+ let options;
8173
+ if (typeof opts !== 'object') {
8174
+ for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
8175
+ rest[_key3 - 2] = arguments[_key3];
8176
+ }
8177
+ options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
8178
+ } else {
8179
+ options = {
8180
+ ...opts
8181
+ };
8182
+ }
8183
+ options.lng = options.lng || fixedT.lng;
8184
+ options.lngs = options.lngs || fixedT.lngs;
8185
+ options.ns = options.ns || fixedT.ns;
8186
+ options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
8187
+ const keySeparator = _this3.options.keySeparator || '.';
8188
+ let resultKey;
8189
+ if (options.keyPrefix && Array.isArray(key)) {
8190
+ resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
8191
+ } else {
8192
+ resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
8193
+ }
8194
+ return _this3.t(resultKey, options);
8195
+ };
8196
+ if (typeof lng === 'string') {
8197
+ fixedT.lng = lng;
8198
+ } else {
8199
+ fixedT.lngs = lng;
8200
+ }
8201
+ fixedT.ns = ns;
8202
+ fixedT.keyPrefix = keyPrefix;
8203
+ return fixedT;
8204
+ }
8205
+ t() {
8206
+ return this.translator && this.translator.translate(...arguments);
8207
+ }
8208
+ exists() {
8209
+ return this.translator && this.translator.exists(...arguments);
8210
+ }
8211
+ setDefaultNamespace(ns) {
8212
+ this.options.defaultNS = ns;
8213
+ }
8214
+ hasLoadedNamespace(ns) {
8215
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8216
+ if (!this.isInitialized) {
8217
+ this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
8218
+ return false;
8219
+ }
8220
+ if (!this.languages || !this.languages.length) {
8221
+ this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
8222
+ return false;
8223
+ }
8224
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
8225
+ const fallbackLng = this.options ? this.options.fallbackLng : false;
8226
+ const lastLng = this.languages[this.languages.length - 1];
8227
+ if (lng.toLowerCase() === 'cimode') return true;
8228
+ const loadNotPending = (l, n) => {
8229
+ const loadState = this.services.backendConnector.state[`${l}|${n}`];
8230
+ return loadState === -1 || loadState === 2;
8231
+ };
8232
+ if (options.precheck) {
8233
+ const preResult = options.precheck(this, loadNotPending);
8234
+ if (preResult !== undefined) return preResult;
8235
+ }
8236
+ if (this.hasResourceBundle(lng, ns)) return true;
8237
+ if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
8238
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
8239
+ return false;
8240
+ }
8241
+ loadNamespaces(ns, callback) {
8242
+ const deferred = defer();
8243
+ if (!this.options.ns) {
8244
+ if (callback) callback();
8245
+ return Promise.resolve();
8246
+ }
8247
+ if (typeof ns === 'string') ns = [ns];
8248
+ ns.forEach(n => {
8249
+ if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
8250
+ });
8251
+ this.loadResources(err => {
8252
+ deferred.resolve();
8253
+ if (callback) callback(err);
8254
+ });
8255
+ return deferred;
8256
+ }
8257
+ loadLanguages(lngs, callback) {
8258
+ const deferred = defer();
8259
+ if (typeof lngs === 'string') lngs = [lngs];
8260
+ const preloaded = this.options.preload || [];
8261
+ const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
8262
+ if (!newLngs.length) {
8263
+ if (callback) callback();
8264
+ return Promise.resolve();
8265
+ }
8266
+ this.options.preload = preloaded.concat(newLngs);
8267
+ this.loadResources(err => {
8268
+ deferred.resolve();
8269
+ if (callback) callback(err);
8270
+ });
8271
+ return deferred;
8272
+ }
8273
+ dir(lng) {
8274
+ if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
8275
+ if (!lng) return 'rtl';
8276
+ const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
8277
+ const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
8278
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
8279
+ }
8280
+ static createInstance() {
8281
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8282
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
8283
+ return new I18n(options, callback);
8284
+ }
8285
+ cloneInstance() {
8286
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8287
+ let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
8288
+ const forkResourceStore = options.forkResourceStore;
8289
+ if (forkResourceStore) delete options.forkResourceStore;
8290
+ const mergedOptions = {
8291
+ ...this.options,
8292
+ ...options,
8293
+ ...{
8294
+ isClone: true
8295
+ }
8296
+ };
8297
+ const clone = new I18n(mergedOptions);
8298
+ if (options.debug !== undefined || options.prefix !== undefined) {
8299
+ clone.logger = clone.logger.clone(options);
8300
+ }
8301
+ const membersToCopy = ['store', 'services', 'language'];
8302
+ membersToCopy.forEach(m => {
8303
+ clone[m] = this[m];
8304
+ });
8305
+ clone.services = {
8306
+ ...this.services
8307
+ };
8308
+ clone.services.utils = {
8309
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
8310
+ };
8311
+ if (forkResourceStore) {
8312
+ clone.store = new ResourceStore(this.store.data, mergedOptions);
8313
+ clone.services.resourceStore = clone.store;
8314
+ }
8315
+ clone.translator = new Translator(clone.services, mergedOptions);
8316
+ clone.translator.on('*', function (event) {
8317
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
8318
+ args[_key4 - 1] = arguments[_key4];
8319
+ }
8320
+ clone.emit(event, ...args);
8321
+ });
8322
+ clone.init(mergedOptions, callback);
8323
+ clone.translator.options = mergedOptions;
8324
+ clone.translator.backendConnector.services.utils = {
8325
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
8326
+ };
8327
+ return clone;
8328
+ }
8329
+ toJSON() {
8330
+ return {
8331
+ options: this.options,
8332
+ store: this.store,
8333
+ language: this.language,
8334
+ languages: this.languages,
8335
+ resolvedLanguage: this.resolvedLanguage
8336
+ };
8337
+ }
8338
+ }
8339
+ const instance = I18n.createInstance();
8340
+ instance.createInstance = I18n.createInstance;
8341
+
8342
+ instance.createInstance;
8343
+ instance.dir;
8344
+ instance.init;
8345
+ instance.loadResources;
8346
+ instance.reloadResources;
8347
+ instance.use;
8348
+ instance.changeLanguage;
8349
+ instance.getFixedT;
8350
+ instance.t;
8351
+ instance.exists;
8352
+ instance.setDefaultNamespace;
8353
+ instance.hasLoadedNamespace;
8354
+ instance.loadNamespaces;
8355
+ instance.loadLanguages;
8356
+
8357
+ var calendar$1 = {
8358
+ startDate: "Start date",
8359
+ endDate: "End date"
8360
+ };
8361
+ var guests$1 = {
8362
+ label: "Guests",
8363
+ title: "Guests",
8364
+ subtitle: "Who's coming?",
8365
+ adultsLabel: "Adults",
8366
+ kidsLabel: "kids"
8367
+ };
8368
+ var categories$1 = {
8369
+ label: "Categories",
8370
+ title: "Category"
8371
+ };
8372
+ var enFilterBar = {
8373
+ calendar: calendar$1,
8374
+ guests: guests$1,
8375
+ categories: categories$1
8376
+ };
8377
+
8378
+ var calendar = {
8379
+ startDate: "Aloitus päivämäärä",
8380
+ endDate: "Päättymis päivämäärä"
8381
+ };
8382
+ var guests = {
8383
+ label: "Vieraat",
8384
+ title: "Vieraat",
8385
+ subtitle: "Kuka saapuu?",
8386
+ adultsLabel: "Aikuiset",
8387
+ kidsLabel: "lapset"
8388
+ };
8389
+ var categories = {
8390
+ label: "Kategoriat",
8391
+ title: "Kategoria"
8392
+ };
8393
+ var fiFilterBar = {
8394
+ calendar: calendar,
8395
+ guests: guests,
8396
+ categories: categories
8397
+ };
8398
+
8399
+ var urlParams = new URLSearchParams(window.location.search);
8400
+ var localeFromUrl = urlParams.get('locale') || 'fi';
8401
+ console.log(urlParams);
8402
+ var userPreferredLanguage = navigator.language;
8403
+ console.log('User Preferred Language:', userPreferredLanguage);
8404
+ instance.use(initReactI18next).init({
8405
+ resources: {
8406
+ en: { filterBar: enFilterBar },
8407
+ fi: { filterBar: fiFilterBar },
8408
+ },
8409
+ lng: localeFromUrl,
8410
+ fallbackLng: 'fi',
8411
+ interpolation: {
8412
+ escapeValue: false,
8413
+ },
8414
+ });
8415
+
8416
+ function FilterBar(_a) {
8417
+ _a.vendor;
8418
+ // useTheme({ vendor })
8419
+ var t = useTranslation('filterBar').t;
8420
+ var _b = useFilterBar(), selectedFilter = _b.selectedFilter, guestsAdults = _b.guestsAdults, guestsKids = _b.guestsKids, categories = _b.categories, calendarRange = _b.calendarRange, setCalendarRange = _b.setCalendarRange, setGuestsAdults = _b.setGuestsAdults, setGuestsKids = _b.setGuestsKids, setCategories = _b.setCategories, handleSelectedFilter = _b.handleSelectedFilter, handleSubmit = _b.handleSubmit;
5825
8421
  return (React__default.createElement("div", { className: "filter-bar" },
5826
8422
  React__default.createElement("div", { className: "filter-bar-header" },
5827
- React__default.createElement(SelectButton, { label: 'Start date', onClick: function () { return handleSelectedFilter(1); } }),
8423
+ React__default.createElement(SelectButton, { label: t('calendar.startDate'), onClick: function () { return handleSelectedFilter(1); } }),
5828
8424
  React__default.createElement(Divider, null),
5829
- React__default.createElement(SelectButton, { label: 'End date', onClick: function () { return handleSelectedFilter(2); } }),
8425
+ React__default.createElement(SelectButton, { label: t('calendar.endDate'), onClick: function () { return handleSelectedFilter(2); } }),
5830
8426
  React__default.createElement(Divider, null),
5831
- React__default.createElement(SelectButton, { label: "Guests", onClick: function () { return handleSelectedFilter(3); } }),
8427
+ React__default.createElement(SelectButton, { label: t('guests.label'), onClick: function () { return handleSelectedFilter(3); } }),
5832
8428
  React__default.createElement(Divider, null),
5833
- React__default.createElement(SelectButton, { label: "Categories", onClick: function () { return handleSelectedFilter(4); } }),
8429
+ React__default.createElement(SelectButton, { label: t('categories.label'), onClick: function () { return handleSelectedFilter(4); } }),
5834
8430
  React__default.createElement(SubmitButton, { onClick: handleSubmit })),
5835
8431
  selectedFilter && (React__default.createElement("div", { className: "filter-bar-container" },
5836
8432
  (selectedFilter === 1 || selectedFilter === 2) && (React__default.createElement(Calendar, { calendarRange: calendarRange, setCalendarRange: setCalendarRange })),