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