@public-ui/hydrate 2.0.13 → 2.0.14
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/dist/index.js +234 -2597
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -7987,7 +7987,7 @@ const getShield = (label, options) => {
|
|
|
7987
7987
|
return [handleClassifier(label, options?.classifier), `${LOG_STYLE};${options?.overwriteStyle || ""}`];
|
|
7988
7988
|
};
|
|
7989
7989
|
const isDevModeOrForceLog = (devMode, forceLog) => devMode() || forceLog === true;
|
|
7990
|
-
class Logger
|
|
7990
|
+
class Logger {
|
|
7991
7991
|
constructor(label, devMode) {
|
|
7992
7992
|
this.label = label;
|
|
7993
7993
|
this.devMode = devMode;
|
|
@@ -8023,7 +8023,7 @@ class Logger$1 {
|
|
|
8023
8023
|
}
|
|
8024
8024
|
}
|
|
8025
8025
|
}
|
|
8026
|
-
const Log = new Logger
|
|
8026
|
+
const Log = new Logger("KoliBri", getDevMode);
|
|
8027
8027
|
|
|
8028
8028
|
const a11yCache = /* @__PURE__ */ new Set();
|
|
8029
8029
|
const a11yHint = (msg, options) => {
|
|
@@ -10062,2574 +10062,199 @@ class KolAbbr {
|
|
|
10062
10062
|
this._tooltipAlign = 'top';
|
|
10063
10063
|
this.state = {
|
|
10064
10064
|
_label: '',
|
|
10065
|
-
_tooltipAlign: 'top',
|
|
10066
|
-
};
|
|
10067
|
-
}
|
|
10068
|
-
render() {
|
|
10069
|
-
return (hAsync(Host, { key: 'c925b5b379b596db99404d6c7d4507275d70496d', class: "kol-abbr" }, hAsync("abbr", { key: 'c7a6a3482ea02fca65278aa28ea115f7a9a11f74', "aria-labelledby": this.nonce, role: "definition", tabindex: "0", title: this.state._label }, hAsync("span", { key: '7179f3b594f6815c06c46dd465739376734ea940', title: "" }, hAsync("slot", { key: '00590edd1ae4afeb4f4f066f0a16ce54c8af28a9' }))), hAsync(KolTooltipWcTag, { key: '2c44fa51a1849dabb59d0541a0d9dcc192e52bcd', _align: this.state._tooltipAlign, _id: this.nonce, _label: this.state._label })));
|
|
10070
|
-
}
|
|
10071
|
-
validateLabel(value) {
|
|
10072
|
-
validateLabel(this, value, {
|
|
10073
|
-
required: true,
|
|
10074
|
-
});
|
|
10075
|
-
}
|
|
10076
|
-
validateTooltipAlign(value) {
|
|
10077
|
-
validateTooltipAlign(this, value);
|
|
10078
|
-
}
|
|
10079
|
-
componentWillLoad() {
|
|
10080
|
-
this.validateLabel(this._label);
|
|
10081
|
-
this.validateTooltipAlign(this._tooltipAlign);
|
|
10082
|
-
}
|
|
10083
|
-
static get watchers() { return {
|
|
10084
|
-
"_label": ["validateLabel"],
|
|
10085
|
-
"_tooltipAlign": ["validateTooltipAlign"]
|
|
10086
|
-
}; }
|
|
10087
|
-
static get style() { return {
|
|
10088
|
-
default: KolAbbrDefaultStyle0
|
|
10089
|
-
}; }
|
|
10090
|
-
static get cmpMeta() { return {
|
|
10091
|
-
"$flags$": 41,
|
|
10092
|
-
"$tagName$": "kol-abbr",
|
|
10093
|
-
"$members$": {
|
|
10094
|
-
"_label": [1],
|
|
10095
|
-
"_tooltipAlign": [1, "_tooltip-align"],
|
|
10096
|
-
"state": [32]
|
|
10097
|
-
},
|
|
10098
|
-
"$listeners$": undefined,
|
|
10099
|
-
"$lazyBundleId$": "-",
|
|
10100
|
-
"$attrsToReflect$": []
|
|
10101
|
-
}; }
|
|
10102
|
-
}
|
|
10103
|
-
|
|
10104
|
-
const watchHeadingLevel = (component, value) => {
|
|
10105
|
-
watchValidator(component, '_level', (value) => {
|
|
10106
|
-
return typeof value === 'number' && headingLevelOptions.includes(value);
|
|
10107
|
-
}, new Set([`Number {${headingLevelOptions.join(', ')}`]), value, {
|
|
10108
|
-
defaultValue: 1,
|
|
10109
|
-
required: true,
|
|
10110
|
-
});
|
|
10111
|
-
};
|
|
10112
|
-
|
|
10113
|
-
const defaultStyleCss$J = "@layer kol-global {\n .sc-kol-accordion-default-h {\n \n --a11y-min-size: 44px;\n \n background-color: white;\n color: black;\n \n font-family: Verdana;\n }\n * {\n \n hyphens: auto;\n \n letter-spacing: inherit;\n \n word-break: break-word;\n \n word-spacing: inherit;\n }\n \n \n \n \n \n [role=button],\n button:not([role=link]),\n .kol-input .input {\n min-height: var(--a11y-min-size);\n min-width: var(--a11y-min-size);\n }\n \n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n \n font-family: inherit;\n \n font-size: inherit;\n }\n}\n\n/*!@.visually-hidden*/.visually-hidden.sc-kol-accordion-default {\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n height: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n}\n\n@layer kol-global {\n \n :is(a, button) {\n background-color: transparent;\n border: none;\n margin: 0;\n padding: 0;\n width: 100%; \n }\n \n [hidden] {\n display: none !important;\n }\n}\n@layer kol-global {\n .sc-kol-accordion-default-h {\n \n max-width: 100%;\n }\n * {\n \n box-sizing: border-box;\n }\n \n .kol-span-wc {\n display: grid;\n place-items: center;\n }\n \n .kol-span-wc > span {\n display: flex;\n place-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .hidden {\n display: none;\n visibility: hidden;\n }\n \n .hide-label > .kol-span-wc > span > span {\n display: none;\n }\n \n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n cursor: not-allowed;\n opacity: 0.5;\n outline: none;\n }\n [aria-disabled=true]:focus .kol-span-wc,\n [disabled]:focus .kol-span-wc {\n outline: none !important;\n }\n}\n@layer kol-component {\n .sc-kol-accordion-default-h {\n display: block;\n }\n}\n@layer kol-component {\n \n .wrapper {\n display: grid;\n grid-template-rows: 0fr;\n overflow: hidden;\n transition: grid-template-rows 0.3s;\n }\n .accordion.open .wrapper {\n grid-template-rows: 1fr;\n }\n .animation-wrapper {\n min-height: 0;\n transition: visibility 0.3s;\n \n visibility: hidden;\n }\n .accordion.open .animation-wrapper {\n visibility: visible;\n }\n @media (prefers-reduced-motion) {\n .animation-wrapper,\n .wrapper {\n transition-duration: 0s;\n }\n }\n \n @media print {\n .accordion:not(.open) .animation-wrapper {\n display: none;\n }\n }\n \n .accordion .kol-heading-wc .kol-button-wc button .kol-span-wc {\n justify-items: start;\n }\n}";
|
|
10114
|
-
var KolAccordionDefaultStyle0 = defaultStyleCss$J;
|
|
10115
|
-
|
|
10116
|
-
featureHint(`[KolAccordion] Anfrage nach einer KolAccordionGroup bei dem immer nur ein Accordion geöffnet ist.
|
|
10117
|
-
|
|
10118
|
-
- onClick auf der KolAccordion anwenden
|
|
10119
|
-
- Click-Event prüft den _open-Status der Accordions
|
|
10120
|
-
- Logik Öffnet und Schließt entsprechend`);
|
|
10121
|
-
featureHint(`[KolAccordion] Tab-Sperre des Inhalts im geschlossenen Zustand.`);
|
|
10122
|
-
class KolAccordion {
|
|
10123
|
-
constructor(hostRef) {
|
|
10124
|
-
registerInstance(this, hostRef);
|
|
10125
|
-
this.nonce = nonce();
|
|
10126
|
-
this.catchRef = (ref) => {
|
|
10127
|
-
propagateFocus(this.host, ref);
|
|
10128
|
-
};
|
|
10129
|
-
this.onClick = (event) => {
|
|
10130
|
-
this._open = !this._open;
|
|
10131
|
-
setTimeout(() => {
|
|
10132
|
-
var _a;
|
|
10133
|
-
if (typeof ((_a = this.state._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function') {
|
|
10134
|
-
this.state._on.onClick(event, this._open === true);
|
|
10135
|
-
}
|
|
10136
|
-
});
|
|
10137
|
-
};
|
|
10138
|
-
this._disabled = false;
|
|
10139
|
-
this._label = undefined;
|
|
10140
|
-
this._level = 1;
|
|
10141
|
-
this._on = undefined;
|
|
10142
|
-
this._open = false;
|
|
10143
|
-
this.state = {
|
|
10144
|
-
_label: '',
|
|
10145
|
-
_level: 1,
|
|
10146
|
-
};
|
|
10147
|
-
}
|
|
10148
|
-
render() {
|
|
10149
|
-
return (hAsync(Host, { key: '375071dab3f67a8a9ea41166c5e5955a905ba04a', class: "kol-accordion" }, hAsync("div", { key: '44e8a90eed884c991797ea6e0e727777075d6d00', class: {
|
|
10150
|
-
accordion: true,
|
|
10151
|
-
disabled: this.state._disabled === true,
|
|
10152
|
-
open: this.state._open === true,
|
|
10153
|
-
} }, hAsync(KolHeadingWcTag, { key: '6fdf9427c74afbcc932fa05c1840e8cb6b606b9a', _label: "", _level: this.state._level, class: "accordion-heading" }, hAsync(KolButtonWcTag, { key: '4e82eb30cd0ff1fef25262dc0e34a3408b0aaad6', class: "accordion-button", ref: this.catchRef, slot: "expert", _ariaControls: this.nonce, _ariaExpanded: this.state._open, _disabled: this.state._disabled, _icons: this.state._open ? 'codicon codicon-remove' : 'codicon codicon-add', _label: this.state._label, _on: { onClick: this.onClick } })), hAsync("div", { key: '0835efe279a9deb62190997682ef0e8fe4a1edf2', class: "wrapper" }, hAsync("div", { key: 'f7244e8b9807223dd80f0b261ec1e2b730f95e85', class: "animation-wrapper" }, hAsync("div", { key: '4ef5849701c39fe7f738cd34661e5c0fc9f29efc', "aria-hidden": this.state._open === false ? 'true' : undefined, class: "content", id: this.nonce }, hAsync("slot", { key: '324bf4086448b8c5700c98d6fa7d830846e362af' })))))));
|
|
10154
|
-
}
|
|
10155
|
-
validateDisabled(value) {
|
|
10156
|
-
validateDisabled(this, value);
|
|
10157
|
-
}
|
|
10158
|
-
validateLabel(value) {
|
|
10159
|
-
validateLabel(this, value, {
|
|
10160
|
-
required: true,
|
|
10161
|
-
});
|
|
10162
|
-
}
|
|
10163
|
-
validateLevel(value) {
|
|
10164
|
-
watchHeadingLevel(this, value);
|
|
10165
|
-
}
|
|
10166
|
-
validateOn(value) {
|
|
10167
|
-
if (typeof value === 'object' && value !== null && typeof value.onClick === 'function') {
|
|
10168
|
-
setState(this, '_on', value);
|
|
10169
|
-
}
|
|
10170
|
-
}
|
|
10171
|
-
validateOpen(value) {
|
|
10172
|
-
validateOpen(this, value);
|
|
10173
|
-
}
|
|
10174
|
-
componentWillLoad() {
|
|
10175
|
-
this.validateDisabled(this._disabled);
|
|
10176
|
-
this.validateLabel(this._label);
|
|
10177
|
-
this.validateLevel(this._level);
|
|
10178
|
-
this.validateOn(this._on);
|
|
10179
|
-
this.validateOpen(this._open);
|
|
10180
|
-
}
|
|
10181
|
-
get host() { return getElement(this); }
|
|
10182
|
-
static get watchers() { return {
|
|
10183
|
-
"_disabled": ["validateDisabled"],
|
|
10184
|
-
"_label": ["validateLabel"],
|
|
10185
|
-
"_level": ["validateLevel"],
|
|
10186
|
-
"_on": ["validateOn"],
|
|
10187
|
-
"_open": ["validateOpen"]
|
|
10188
|
-
}; }
|
|
10189
|
-
static get style() { return {
|
|
10190
|
-
default: KolAccordionDefaultStyle0
|
|
10191
|
-
}; }
|
|
10192
|
-
static get cmpMeta() { return {
|
|
10193
|
-
"$flags$": 41,
|
|
10194
|
-
"$tagName$": "kol-accordion",
|
|
10195
|
-
"$members$": {
|
|
10196
|
-
"_disabled": [4],
|
|
10197
|
-
"_label": [1],
|
|
10198
|
-
"_level": [2],
|
|
10199
|
-
"_on": [16],
|
|
10200
|
-
"_open": [1540],
|
|
10201
|
-
"state": [32]
|
|
10202
|
-
},
|
|
10203
|
-
"$listeners$": undefined,
|
|
10204
|
-
"$lazyBundleId$": "-",
|
|
10205
|
-
"$attrsToReflect$": [["_open", "_open"]]
|
|
10206
|
-
}; }
|
|
10207
|
-
}
|
|
10208
|
-
|
|
10209
|
-
const defaultStyleCss$I = "@layer kol-global {\n .sc-kol-alert-default-h {\n \n --a11y-min-size: 44px;\n \n background-color: white;\n color: black;\n \n font-family: Verdana;\n }\n * {\n \n hyphens: auto;\n \n letter-spacing: inherit;\n \n word-break: break-word;\n \n word-spacing: inherit;\n }\n \n \n \n \n \n [role=button],\n button:not([role=link]),\n .kol-input .input {\n min-height: var(--a11y-min-size);\n min-width: var(--a11y-min-size);\n }\n \n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n \n font-family: inherit;\n \n font-size: inherit;\n }\n}\n\n/*!@.visually-hidden*/.visually-hidden.sc-kol-alert-default {\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n height: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n}\n\n@layer kol-global {\n \n :is(a, button) {\n background-color: transparent;\n border: none;\n margin: 0;\n padding: 0;\n width: 100%; \n }\n \n [hidden] {\n display: none !important;\n }\n}\n@layer kol-global {\n .sc-kol-alert-default-h {\n \n max-width: 100%;\n }\n * {\n \n box-sizing: border-box;\n }\n \n .kol-span-wc {\n display: grid;\n place-items: center;\n }\n \n .kol-span-wc > span {\n display: flex;\n place-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .hidden {\n display: none;\n visibility: hidden;\n }\n \n .hide-label > .kol-span-wc > span > span {\n display: none;\n }\n \n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n cursor: not-allowed;\n opacity: 0.5;\n outline: none;\n }\n [aria-disabled=true]:focus .kol-span-wc,\n [disabled]:focus .kol-span-wc {\n outline: none !important;\n }\n}\n@layer kol-component {\n .sc-kol-alert-default-h {\n display: block;\n }\n}\n@layer kol-component {\n .kol-alert-wc {\n display: grid;\n }\n .kol-alert-wc .heading {\n display: flex;\n place-items: center;\n }\n .kol-alert-wc .heading > div {\n flex-grow: 1;\n }\n .close {\n \n outline: transparent solid 1px;\n }\n}";
|
|
10210
|
-
var KolAlertDefaultStyle0 = defaultStyleCss$I;
|
|
10211
|
-
|
|
10212
|
-
class KolAlert {
|
|
10213
|
-
constructor(hostRef) {
|
|
10214
|
-
registerInstance(this, hostRef);
|
|
10215
|
-
this._alert = false;
|
|
10216
|
-
this._hasCloser = false;
|
|
10217
|
-
this._label = undefined;
|
|
10218
|
-
this._level = 1;
|
|
10219
|
-
this._on = undefined;
|
|
10220
|
-
this._type = 'default';
|
|
10221
|
-
this._variant = 'msg';
|
|
10222
|
-
this.state = {
|
|
10223
|
-
_level: 1,
|
|
10224
|
-
};
|
|
10225
|
-
}
|
|
10226
|
-
render() {
|
|
10227
|
-
return (hAsync(Host, { key: '0bc6af8580c2671652be185c0703d6863173054b', class: "kol-alert" }, hAsync(KolAlertWcTag, { key: '597bc59e70dd38fc02c75f93fd4bd0e18a2adc1c', _alert: this._alert, _hasCloser: this._hasCloser, _label: this._label, _level: this._level, _on: this._on, _type: this._type, _variant: this._variant }, hAsync("slot", { key: 'c3216b358f6a0dd8357009d7c95f3aa6101cc781' }))));
|
|
10228
|
-
}
|
|
10229
|
-
static get style() { return {
|
|
10230
|
-
default: KolAlertDefaultStyle0
|
|
10231
|
-
}; }
|
|
10232
|
-
static get cmpMeta() { return {
|
|
10233
|
-
"$flags$": 41,
|
|
10234
|
-
"$tagName$": "kol-alert",
|
|
10235
|
-
"$members$": {
|
|
10236
|
-
"_alert": [4],
|
|
10237
|
-
"_hasCloser": [4, "_has-closer"],
|
|
10238
|
-
"_label": [1],
|
|
10239
|
-
"_level": [2],
|
|
10240
|
-
"_on": [16],
|
|
10241
|
-
"_type": [1],
|
|
10242
|
-
"_variant": [1],
|
|
10243
|
-
"state": [32]
|
|
10244
|
-
},
|
|
10245
|
-
"$listeners$": undefined,
|
|
10246
|
-
"$lazyBundleId$": "-",
|
|
10247
|
-
"$attrsToReflect$": []
|
|
10248
|
-
}; }
|
|
10249
|
-
}
|
|
10250
|
-
|
|
10251
|
-
const consoleLogger = {
|
|
10252
|
-
type: 'logger',
|
|
10253
|
-
log(args) {
|
|
10254
|
-
this.output('log', args);
|
|
10255
|
-
},
|
|
10256
|
-
warn(args) {
|
|
10257
|
-
this.output('warn', args);
|
|
10258
|
-
},
|
|
10259
|
-
error(args) {
|
|
10260
|
-
this.output('error', args);
|
|
10261
|
-
},
|
|
10262
|
-
output(type, args) {
|
|
10263
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
10264
|
-
}
|
|
10265
|
-
};
|
|
10266
|
-
class Logger {
|
|
10267
|
-
constructor(concreteLogger) {
|
|
10268
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
10269
|
-
this.init(concreteLogger, options);
|
|
10270
|
-
}
|
|
10271
|
-
init(concreteLogger) {
|
|
10272
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
10273
|
-
this.prefix = options.prefix || 'i18next:';
|
|
10274
|
-
this.logger = concreteLogger || consoleLogger;
|
|
10275
|
-
this.options = options;
|
|
10276
|
-
this.debug = options.debug;
|
|
10277
|
-
}
|
|
10278
|
-
log() {
|
|
10279
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10280
|
-
args[_key] = arguments[_key];
|
|
10281
|
-
}
|
|
10282
|
-
return this.forward(args, 'log', '', true);
|
|
10283
|
-
}
|
|
10284
|
-
warn() {
|
|
10285
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
10286
|
-
args[_key2] = arguments[_key2];
|
|
10287
|
-
}
|
|
10288
|
-
return this.forward(args, 'warn', '', true);
|
|
10289
|
-
}
|
|
10290
|
-
error() {
|
|
10291
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
10292
|
-
args[_key3] = arguments[_key3];
|
|
10293
|
-
}
|
|
10294
|
-
return this.forward(args, 'error', '');
|
|
10295
|
-
}
|
|
10296
|
-
deprecate() {
|
|
10297
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
10298
|
-
args[_key4] = arguments[_key4];
|
|
10299
|
-
}
|
|
10300
|
-
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
10301
|
-
}
|
|
10302
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
10303
|
-
if (debugOnly && !this.debug) return null;
|
|
10304
|
-
if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
10305
|
-
return this.logger[lvl](args);
|
|
10306
|
-
}
|
|
10307
|
-
create(moduleName) {
|
|
10308
|
-
return new Logger(this.logger, {
|
|
10309
|
-
...{
|
|
10310
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
10311
|
-
},
|
|
10312
|
-
...this.options
|
|
10313
|
-
});
|
|
10314
|
-
}
|
|
10315
|
-
clone(options) {
|
|
10316
|
-
options = options || this.options;
|
|
10317
|
-
options.prefix = options.prefix || this.prefix;
|
|
10318
|
-
return new Logger(this.logger, options);
|
|
10319
|
-
}
|
|
10320
|
-
}
|
|
10321
|
-
var baseLogger = new Logger();
|
|
10322
|
-
|
|
10323
|
-
class EventEmitter {
|
|
10324
|
-
constructor() {
|
|
10325
|
-
this.observers = {};
|
|
10326
|
-
}
|
|
10327
|
-
on(events, listener) {
|
|
10328
|
-
events.split(' ').forEach(event => {
|
|
10329
|
-
if (!this.observers[event]) this.observers[event] = new Map();
|
|
10330
|
-
const numListeners = this.observers[event].get(listener) || 0;
|
|
10331
|
-
this.observers[event].set(listener, numListeners + 1);
|
|
10332
|
-
});
|
|
10333
|
-
return this;
|
|
10334
|
-
}
|
|
10335
|
-
off(event, listener) {
|
|
10336
|
-
if (!this.observers[event]) return;
|
|
10337
|
-
if (!listener) {
|
|
10338
|
-
delete this.observers[event];
|
|
10339
|
-
return;
|
|
10340
|
-
}
|
|
10341
|
-
this.observers[event].delete(listener);
|
|
10342
|
-
}
|
|
10343
|
-
emit(event) {
|
|
10344
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
10345
|
-
args[_key - 1] = arguments[_key];
|
|
10346
|
-
}
|
|
10347
|
-
if (this.observers[event]) {
|
|
10348
|
-
const cloned = Array.from(this.observers[event].entries());
|
|
10349
|
-
cloned.forEach(_ref => {
|
|
10350
|
-
let [observer, numTimesAdded] = _ref;
|
|
10351
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
10352
|
-
observer(...args);
|
|
10353
|
-
}
|
|
10354
|
-
});
|
|
10355
|
-
}
|
|
10356
|
-
if (this.observers['*']) {
|
|
10357
|
-
const cloned = Array.from(this.observers['*'].entries());
|
|
10358
|
-
cloned.forEach(_ref2 => {
|
|
10359
|
-
let [observer, numTimesAdded] = _ref2;
|
|
10360
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
10361
|
-
observer.apply(observer, [event, ...args]);
|
|
10362
|
-
}
|
|
10363
|
-
});
|
|
10364
|
-
}
|
|
10365
|
-
}
|
|
10366
|
-
}
|
|
10367
|
-
|
|
10368
|
-
function defer() {
|
|
10369
|
-
let res;
|
|
10370
|
-
let rej;
|
|
10371
|
-
const promise = new Promise((resolve, reject) => {
|
|
10372
|
-
res = resolve;
|
|
10373
|
-
rej = reject;
|
|
10374
|
-
});
|
|
10375
|
-
promise.resolve = res;
|
|
10376
|
-
promise.reject = rej;
|
|
10377
|
-
return promise;
|
|
10378
|
-
}
|
|
10379
|
-
function makeString(object) {
|
|
10380
|
-
if (object == null) return '';
|
|
10381
|
-
return '' + object;
|
|
10382
|
-
}
|
|
10383
|
-
function copy(a, s, t) {
|
|
10384
|
-
a.forEach(m => {
|
|
10385
|
-
if (s[m]) t[m] = s[m];
|
|
10386
|
-
});
|
|
10387
|
-
}
|
|
10388
|
-
const lastOfPathSeparatorRegExp = /###/g;
|
|
10389
|
-
function getLastOfPath(object, path, Empty) {
|
|
10390
|
-
function cleanKey(key) {
|
|
10391
|
-
return key && key.indexOf('###') > -1 ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
|
|
10392
|
-
}
|
|
10393
|
-
function canNotTraverseDeeper() {
|
|
10394
|
-
return !object || typeof object === 'string';
|
|
10395
|
-
}
|
|
10396
|
-
const stack = typeof path !== 'string' ? path : path.split('.');
|
|
10397
|
-
let stackIndex = 0;
|
|
10398
|
-
while (stackIndex < stack.length - 1) {
|
|
10399
|
-
if (canNotTraverseDeeper()) return {};
|
|
10400
|
-
const key = cleanKey(stack[stackIndex]);
|
|
10401
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
10402
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
10403
|
-
object = object[key];
|
|
10404
|
-
} else {
|
|
10405
|
-
object = {};
|
|
10406
|
-
}
|
|
10407
|
-
++stackIndex;
|
|
10408
|
-
}
|
|
10409
|
-
if (canNotTraverseDeeper()) return {};
|
|
10410
|
-
return {
|
|
10411
|
-
obj: object,
|
|
10412
|
-
k: cleanKey(stack[stackIndex])
|
|
10413
|
-
};
|
|
10414
|
-
}
|
|
10415
|
-
function setPath(object, path, newValue) {
|
|
10416
|
-
const {
|
|
10417
|
-
obj,
|
|
10418
|
-
k
|
|
10419
|
-
} = getLastOfPath(object, path, Object);
|
|
10420
|
-
if (obj !== undefined || path.length === 1) {
|
|
10421
|
-
obj[k] = newValue;
|
|
10422
|
-
return;
|
|
10423
|
-
}
|
|
10424
|
-
let e = path[path.length - 1];
|
|
10425
|
-
let p = path.slice(0, path.length - 1);
|
|
10426
|
-
let last = getLastOfPath(object, p, Object);
|
|
10427
|
-
while (last.obj === undefined && p.length) {
|
|
10428
|
-
e = `${p[p.length - 1]}.${e}`;
|
|
10429
|
-
p = p.slice(0, p.length - 1);
|
|
10430
|
-
last = getLastOfPath(object, p, Object);
|
|
10431
|
-
if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== 'undefined') {
|
|
10432
|
-
last.obj = undefined;
|
|
10433
|
-
}
|
|
10434
|
-
}
|
|
10435
|
-
last.obj[`${last.k}.${e}`] = newValue;
|
|
10436
|
-
}
|
|
10437
|
-
function pushPath(object, path, newValue, concat) {
|
|
10438
|
-
const {
|
|
10439
|
-
obj,
|
|
10440
|
-
k
|
|
10441
|
-
} = getLastOfPath(object, path, Object);
|
|
10442
|
-
obj[k] = obj[k] || [];
|
|
10443
|
-
if (concat) obj[k] = obj[k].concat(newValue);
|
|
10444
|
-
if (!concat) obj[k].push(newValue);
|
|
10445
|
-
}
|
|
10446
|
-
function getPath(object, path) {
|
|
10447
|
-
const {
|
|
10448
|
-
obj,
|
|
10449
|
-
k
|
|
10450
|
-
} = getLastOfPath(object, path);
|
|
10451
|
-
if (!obj) return undefined;
|
|
10452
|
-
return obj[k];
|
|
10453
|
-
}
|
|
10454
|
-
function getPathWithDefaults(data, defaultData, key) {
|
|
10455
|
-
const value = getPath(data, key);
|
|
10456
|
-
if (value !== undefined) {
|
|
10457
|
-
return value;
|
|
10458
|
-
}
|
|
10459
|
-
return getPath(defaultData, key);
|
|
10460
|
-
}
|
|
10461
|
-
function deepExtend(target, source, overwrite) {
|
|
10462
|
-
for (const prop in source) {
|
|
10463
|
-
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
10464
|
-
if (prop in target) {
|
|
10465
|
-
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
10466
|
-
if (overwrite) target[prop] = source[prop];
|
|
10467
|
-
} else {
|
|
10468
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
10469
|
-
}
|
|
10470
|
-
} else {
|
|
10471
|
-
target[prop] = source[prop];
|
|
10472
|
-
}
|
|
10473
|
-
}
|
|
10474
|
-
}
|
|
10475
|
-
return target;
|
|
10476
|
-
}
|
|
10477
|
-
function regexEscape(str) {
|
|
10478
|
-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
10479
|
-
}
|
|
10480
|
-
var _entityMap = {
|
|
10481
|
-
'&': '&',
|
|
10482
|
-
'<': '<',
|
|
10483
|
-
'>': '>',
|
|
10484
|
-
'"': '"',
|
|
10485
|
-
"'": ''',
|
|
10486
|
-
'/': '/'
|
|
10487
|
-
};
|
|
10488
|
-
function escape$1(data) {
|
|
10489
|
-
if (typeof data === 'string') {
|
|
10490
|
-
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
10491
|
-
}
|
|
10492
|
-
return data;
|
|
10493
|
-
}
|
|
10494
|
-
class RegExpCache {
|
|
10495
|
-
constructor(capacity) {
|
|
10496
|
-
this.capacity = capacity;
|
|
10497
|
-
this.regExpMap = new Map();
|
|
10498
|
-
this.regExpQueue = [];
|
|
10499
|
-
}
|
|
10500
|
-
getRegExp(pattern) {
|
|
10501
|
-
const regExpFromCache = this.regExpMap.get(pattern);
|
|
10502
|
-
if (regExpFromCache !== undefined) {
|
|
10503
|
-
return regExpFromCache;
|
|
10504
|
-
}
|
|
10505
|
-
const regExpNew = new RegExp(pattern);
|
|
10506
|
-
if (this.regExpQueue.length === this.capacity) {
|
|
10507
|
-
this.regExpMap.delete(this.regExpQueue.shift());
|
|
10508
|
-
}
|
|
10509
|
-
this.regExpMap.set(pattern, regExpNew);
|
|
10510
|
-
this.regExpQueue.push(pattern);
|
|
10511
|
-
return regExpNew;
|
|
10512
|
-
}
|
|
10513
|
-
}
|
|
10514
|
-
const chars = [' ', ',', '?', '!', ';'];
|
|
10515
|
-
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
10516
|
-
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
10517
|
-
nsSeparator = nsSeparator || '';
|
|
10518
|
-
keySeparator = keySeparator || '';
|
|
10519
|
-
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
10520
|
-
if (possibleChars.length === 0) return true;
|
|
10521
|
-
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
10522
|
-
let matched = !r.test(key);
|
|
10523
|
-
if (!matched) {
|
|
10524
|
-
const ki = key.indexOf(keySeparator);
|
|
10525
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
10526
|
-
matched = true;
|
|
10527
|
-
}
|
|
10528
|
-
}
|
|
10529
|
-
return matched;
|
|
10530
|
-
}
|
|
10531
|
-
function deepFind(obj, path) {
|
|
10532
|
-
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
10533
|
-
if (!obj) return undefined;
|
|
10534
|
-
if (obj[path]) return obj[path];
|
|
10535
|
-
const tokens = path.split(keySeparator);
|
|
10536
|
-
let current = obj;
|
|
10537
|
-
for (let i = 0; i < tokens.length;) {
|
|
10538
|
-
if (!current || typeof current !== 'object') {
|
|
10539
|
-
return undefined;
|
|
10540
|
-
}
|
|
10541
|
-
let next;
|
|
10542
|
-
let nextPath = '';
|
|
10543
|
-
for (let j = i; j < tokens.length; ++j) {
|
|
10544
|
-
if (j !== i) {
|
|
10545
|
-
nextPath += keySeparator;
|
|
10546
|
-
}
|
|
10547
|
-
nextPath += tokens[j];
|
|
10548
|
-
next = current[nextPath];
|
|
10549
|
-
if (next !== undefined) {
|
|
10550
|
-
if (['string', 'number', 'boolean'].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
10551
|
-
continue;
|
|
10552
|
-
}
|
|
10553
|
-
i += j - i + 1;
|
|
10554
|
-
break;
|
|
10555
|
-
}
|
|
10556
|
-
}
|
|
10557
|
-
current = next;
|
|
10558
|
-
}
|
|
10559
|
-
return current;
|
|
10560
|
-
}
|
|
10561
|
-
function getCleanedCode(code) {
|
|
10562
|
-
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
10563
|
-
return code;
|
|
10564
|
-
}
|
|
10565
|
-
|
|
10566
|
-
class ResourceStore extends EventEmitter {
|
|
10567
|
-
constructor(data) {
|
|
10568
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
10569
|
-
ns: ['translation'],
|
|
10570
|
-
defaultNS: 'translation'
|
|
10571
|
-
};
|
|
10572
|
-
super();
|
|
10573
|
-
this.data = data || {};
|
|
10574
|
-
this.options = options;
|
|
10575
|
-
if (this.options.keySeparator === undefined) {
|
|
10576
|
-
this.options.keySeparator = '.';
|
|
10577
|
-
}
|
|
10578
|
-
if (this.options.ignoreJSONStructure === undefined) {
|
|
10579
|
-
this.options.ignoreJSONStructure = true;
|
|
10580
|
-
}
|
|
10581
|
-
}
|
|
10582
|
-
addNamespaces(ns) {
|
|
10583
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
10584
|
-
this.options.ns.push(ns);
|
|
10585
|
-
}
|
|
10586
|
-
}
|
|
10587
|
-
removeNamespaces(ns) {
|
|
10588
|
-
const index = this.options.ns.indexOf(ns);
|
|
10589
|
-
if (index > -1) {
|
|
10590
|
-
this.options.ns.splice(index, 1);
|
|
10591
|
-
}
|
|
10592
|
-
}
|
|
10593
|
-
getResource(lng, ns, key) {
|
|
10594
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
10595
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
10596
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
10597
|
-
let path;
|
|
10598
|
-
if (lng.indexOf('.') > -1) {
|
|
10599
|
-
path = lng.split('.');
|
|
10600
|
-
} else {
|
|
10601
|
-
path = [lng, ns];
|
|
10602
|
-
if (key) {
|
|
10603
|
-
if (Array.isArray(key)) {
|
|
10604
|
-
path.push(...key);
|
|
10605
|
-
} else if (typeof key === 'string' && keySeparator) {
|
|
10606
|
-
path.push(...key.split(keySeparator));
|
|
10607
|
-
} else {
|
|
10608
|
-
path.push(key);
|
|
10609
|
-
}
|
|
10610
|
-
}
|
|
10611
|
-
}
|
|
10612
|
-
const result = getPath(this.data, path);
|
|
10613
|
-
if (!result && !ns && !key && lng.indexOf('.') > -1) {
|
|
10614
|
-
lng = path[0];
|
|
10615
|
-
ns = path[1];
|
|
10616
|
-
key = path.slice(2).join('.');
|
|
10617
|
-
}
|
|
10618
|
-
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
10619
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
10620
|
-
}
|
|
10621
|
-
addResource(lng, ns, key, value) {
|
|
10622
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
10623
|
-
silent: false
|
|
10624
|
-
};
|
|
10625
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
10626
|
-
let path = [lng, ns];
|
|
10627
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
10628
|
-
if (lng.indexOf('.') > -1) {
|
|
10629
|
-
path = lng.split('.');
|
|
10630
|
-
value = ns;
|
|
10631
|
-
ns = path[1];
|
|
10632
|
-
}
|
|
10633
|
-
this.addNamespaces(ns);
|
|
10634
|
-
setPath(this.data, path, value);
|
|
10635
|
-
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
10636
|
-
}
|
|
10637
|
-
addResources(lng, ns, resources) {
|
|
10638
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
10639
|
-
silent: false
|
|
10640
|
-
};
|
|
10641
|
-
for (const m in resources) {
|
|
10642
|
-
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
10643
|
-
silent: true
|
|
10644
|
-
});
|
|
10645
|
-
}
|
|
10646
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
10647
|
-
}
|
|
10648
|
-
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
10649
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
10650
|
-
silent: false,
|
|
10651
|
-
skipCopy: false
|
|
10652
|
-
};
|
|
10653
|
-
let path = [lng, ns];
|
|
10654
|
-
if (lng.indexOf('.') > -1) {
|
|
10655
|
-
path = lng.split('.');
|
|
10656
|
-
deep = resources;
|
|
10657
|
-
resources = ns;
|
|
10658
|
-
ns = path[1];
|
|
10659
|
-
}
|
|
10660
|
-
this.addNamespaces(ns);
|
|
10661
|
-
let pack = getPath(this.data, path) || {};
|
|
10662
|
-
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
10663
|
-
if (deep) {
|
|
10664
|
-
deepExtend(pack, resources, overwrite);
|
|
10665
|
-
} else {
|
|
10666
|
-
pack = {
|
|
10667
|
-
...pack,
|
|
10668
|
-
...resources
|
|
10669
|
-
};
|
|
10670
|
-
}
|
|
10671
|
-
setPath(this.data, path, pack);
|
|
10672
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
10673
|
-
}
|
|
10674
|
-
removeResourceBundle(lng, ns) {
|
|
10675
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
10676
|
-
delete this.data[lng][ns];
|
|
10677
|
-
}
|
|
10678
|
-
this.removeNamespaces(ns);
|
|
10679
|
-
this.emit('removed', lng, ns);
|
|
10680
|
-
}
|
|
10681
|
-
hasResourceBundle(lng, ns) {
|
|
10682
|
-
return this.getResource(lng, ns) !== undefined;
|
|
10683
|
-
}
|
|
10684
|
-
getResourceBundle(lng, ns) {
|
|
10685
|
-
if (!ns) ns = this.options.defaultNS;
|
|
10686
|
-
if (this.options.compatibilityAPI === 'v1') return {
|
|
10687
|
-
...{},
|
|
10688
|
-
...this.getResource(lng, ns)
|
|
10689
|
-
};
|
|
10690
|
-
return this.getResource(lng, ns);
|
|
10691
|
-
}
|
|
10692
|
-
getDataByLanguage(lng) {
|
|
10693
|
-
return this.data[lng];
|
|
10694
|
-
}
|
|
10695
|
-
hasLanguageSomeTranslations(lng) {
|
|
10696
|
-
const data = this.getDataByLanguage(lng);
|
|
10697
|
-
const n = data && Object.keys(data) || [];
|
|
10698
|
-
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
10699
|
-
}
|
|
10700
|
-
toJSON() {
|
|
10701
|
-
return this.data;
|
|
10702
|
-
}
|
|
10703
|
-
}
|
|
10704
|
-
|
|
10705
|
-
var postProcessor = {
|
|
10706
|
-
processors: {},
|
|
10707
|
-
addPostProcessor(module) {
|
|
10708
|
-
this.processors[module.name] = module;
|
|
10709
|
-
},
|
|
10710
|
-
handle(processors, value, key, options, translator) {
|
|
10711
|
-
processors.forEach(processor => {
|
|
10712
|
-
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
10713
|
-
});
|
|
10714
|
-
return value;
|
|
10715
|
-
}
|
|
10716
|
-
};
|
|
10717
|
-
|
|
10718
|
-
const checkedLoadedFor = {};
|
|
10719
|
-
class Translator extends EventEmitter {
|
|
10720
|
-
constructor(services) {
|
|
10721
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
10722
|
-
super();
|
|
10723
|
-
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
10724
|
-
this.options = options;
|
|
10725
|
-
if (this.options.keySeparator === undefined) {
|
|
10726
|
-
this.options.keySeparator = '.';
|
|
10727
|
-
}
|
|
10728
|
-
this.logger = baseLogger.create('translator');
|
|
10729
|
-
}
|
|
10730
|
-
changeLanguage(lng) {
|
|
10731
|
-
if (lng) this.language = lng;
|
|
10732
|
-
}
|
|
10733
|
-
exists(key) {
|
|
10734
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
10735
|
-
interpolation: {}
|
|
10736
|
-
};
|
|
10737
|
-
if (key === undefined || key === null) {
|
|
10738
|
-
return false;
|
|
10739
|
-
}
|
|
10740
|
-
const resolved = this.resolve(key, options);
|
|
10741
|
-
return resolved && resolved.res !== undefined;
|
|
10742
|
-
}
|
|
10743
|
-
extractFromKey(key, options) {
|
|
10744
|
-
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
10745
|
-
if (nsSeparator === undefined) nsSeparator = ':';
|
|
10746
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
10747
|
-
let namespaces = options.ns || this.options.defaultNS || [];
|
|
10748
|
-
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
10749
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
10750
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
10751
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
10752
|
-
if (m && m.length > 0) {
|
|
10753
|
-
return {
|
|
10754
|
-
key,
|
|
10755
|
-
namespaces
|
|
10756
|
-
};
|
|
10757
|
-
}
|
|
10758
|
-
const parts = key.split(nsSeparator);
|
|
10759
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
10760
|
-
key = parts.join(keySeparator);
|
|
10761
|
-
}
|
|
10762
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
10763
|
-
return {
|
|
10764
|
-
key,
|
|
10765
|
-
namespaces
|
|
10766
|
-
};
|
|
10767
|
-
}
|
|
10768
|
-
translate(keys, options, lastKey) {
|
|
10769
|
-
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
10770
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
10771
|
-
}
|
|
10772
|
-
if (typeof options === 'object') options = {
|
|
10773
|
-
...options
|
|
10774
|
-
};
|
|
10775
|
-
if (!options) options = {};
|
|
10776
|
-
if (keys === undefined || keys === null) return '';
|
|
10777
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
10778
|
-
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
10779
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
10780
|
-
const {
|
|
10781
|
-
key,
|
|
10782
|
-
namespaces
|
|
10783
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
10784
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
10785
|
-
const lng = options.lng || this.language;
|
|
10786
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
10787
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
10788
|
-
if (appendNamespaceToCIMode) {
|
|
10789
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
10790
|
-
if (returnDetails) {
|
|
10791
|
-
return {
|
|
10792
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
10793
|
-
usedKey: key,
|
|
10794
|
-
exactUsedKey: key,
|
|
10795
|
-
usedLng: lng,
|
|
10796
|
-
usedNS: namespace,
|
|
10797
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
10798
|
-
};
|
|
10799
|
-
}
|
|
10800
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
10801
|
-
}
|
|
10802
|
-
if (returnDetails) {
|
|
10803
|
-
return {
|
|
10804
|
-
res: key,
|
|
10805
|
-
usedKey: key,
|
|
10806
|
-
exactUsedKey: key,
|
|
10807
|
-
usedLng: lng,
|
|
10808
|
-
usedNS: namespace,
|
|
10809
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
10810
|
-
};
|
|
10811
|
-
}
|
|
10812
|
-
return key;
|
|
10813
|
-
}
|
|
10814
|
-
const resolved = this.resolve(keys, options);
|
|
10815
|
-
let res = resolved && resolved.res;
|
|
10816
|
-
const resUsedKey = resolved && resolved.usedKey || key;
|
|
10817
|
-
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
10818
|
-
const resType = Object.prototype.toString.apply(res);
|
|
10819
|
-
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
10820
|
-
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
10821
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
10822
|
-
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
10823
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
10824
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
10825
|
-
if (!this.options.returnedObjectHandler) {
|
|
10826
|
-
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
10827
|
-
}
|
|
10828
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
10829
|
-
...options,
|
|
10830
|
-
ns: namespaces
|
|
10831
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
10832
|
-
if (returnDetails) {
|
|
10833
|
-
resolved.res = r;
|
|
10834
|
-
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
10835
|
-
return resolved;
|
|
10836
|
-
}
|
|
10837
|
-
return r;
|
|
10838
|
-
}
|
|
10839
|
-
if (keySeparator) {
|
|
10840
|
-
const resTypeIsArray = resType === '[object Array]';
|
|
10841
|
-
const copy = resTypeIsArray ? [] : {};
|
|
10842
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
10843
|
-
for (const m in res) {
|
|
10844
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
10845
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
10846
|
-
copy[m] = this.translate(deepKey, {
|
|
10847
|
-
...options,
|
|
10848
|
-
...{
|
|
10849
|
-
joinArrays: false,
|
|
10850
|
-
ns: namespaces
|
|
10851
|
-
}
|
|
10852
|
-
});
|
|
10853
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
10854
|
-
}
|
|
10855
|
-
}
|
|
10856
|
-
res = copy;
|
|
10857
|
-
}
|
|
10858
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
10859
|
-
res = res.join(joinArrays);
|
|
10860
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
10861
|
-
} else {
|
|
10862
|
-
let usedDefault = false;
|
|
10863
|
-
let usedKey = false;
|
|
10864
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
10865
|
-
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
10866
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
10867
|
-
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
10868
|
-
ordinal: false
|
|
10869
|
-
}) : '';
|
|
10870
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
10871
|
-
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
10872
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
10873
|
-
usedDefault = true;
|
|
10874
|
-
res = defaultValue;
|
|
10875
|
-
}
|
|
10876
|
-
if (!this.isValidLookup(res)) {
|
|
10877
|
-
usedKey = true;
|
|
10878
|
-
res = key;
|
|
10879
|
-
}
|
|
10880
|
-
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
10881
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
10882
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
10883
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
10884
|
-
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
10885
|
-
if (keySeparator) {
|
|
10886
|
-
const fk = this.resolve(key, {
|
|
10887
|
-
...options,
|
|
10888
|
-
keySeparator: false
|
|
10889
|
-
});
|
|
10890
|
-
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.');
|
|
10891
|
-
}
|
|
10892
|
-
let lngs = [];
|
|
10893
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
10894
|
-
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
10895
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
10896
|
-
lngs.push(fallbackLngs[i]);
|
|
10897
|
-
}
|
|
10898
|
-
} else if (this.options.saveMissingTo === 'all') {
|
|
10899
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
10900
|
-
} else {
|
|
10901
|
-
lngs.push(options.lng || this.language);
|
|
10902
|
-
}
|
|
10903
|
-
const send = (l, k, specificDefaultValue) => {
|
|
10904
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
10905
|
-
if (this.options.missingKeyHandler) {
|
|
10906
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
10907
|
-
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
10908
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
10909
|
-
}
|
|
10910
|
-
this.emit('missingKey', l, namespace, k, res);
|
|
10911
|
-
};
|
|
10912
|
-
if (this.options.saveMissing) {
|
|
10913
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
10914
|
-
lngs.forEach(language => {
|
|
10915
|
-
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
10916
|
-
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
10917
|
-
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
10918
|
-
}
|
|
10919
|
-
suffixes.forEach(suffix => {
|
|
10920
|
-
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
10921
|
-
});
|
|
10922
|
-
});
|
|
10923
|
-
} else {
|
|
10924
|
-
send(lngs, key, defaultValue);
|
|
10925
|
-
}
|
|
10926
|
-
}
|
|
10927
|
-
}
|
|
10928
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
10929
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
10930
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
10931
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
10932
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
10933
|
-
} else {
|
|
10934
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
10935
|
-
}
|
|
10936
|
-
}
|
|
10937
|
-
}
|
|
10938
|
-
if (returnDetails) {
|
|
10939
|
-
resolved.res = res;
|
|
10940
|
-
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
10941
|
-
return resolved;
|
|
10942
|
-
}
|
|
10943
|
-
return res;
|
|
10944
|
-
}
|
|
10945
|
-
extendTranslation(res, key, options, resolved, lastKey) {
|
|
10946
|
-
var _this = this;
|
|
10947
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
10948
|
-
res = this.i18nFormat.parse(res, {
|
|
10949
|
-
...this.options.interpolation.defaultVariables,
|
|
10950
|
-
...options
|
|
10951
|
-
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
10952
|
-
resolved
|
|
10953
|
-
});
|
|
10954
|
-
} else if (!options.skipInterpolation) {
|
|
10955
|
-
if (options.interpolation) this.interpolator.init({
|
|
10956
|
-
...options,
|
|
10957
|
-
...{
|
|
10958
|
-
interpolation: {
|
|
10959
|
-
...this.options.interpolation,
|
|
10960
|
-
...options.interpolation
|
|
10961
|
-
}
|
|
10962
|
-
}
|
|
10963
|
-
});
|
|
10964
|
-
const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
10965
|
-
let nestBef;
|
|
10966
|
-
if (skipOnVariables) {
|
|
10967
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
10968
|
-
nestBef = nb && nb.length;
|
|
10969
|
-
}
|
|
10970
|
-
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
10971
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
10972
|
-
...this.options.interpolation.defaultVariables,
|
|
10973
|
-
...data
|
|
10974
|
-
};
|
|
10975
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
10976
|
-
if (skipOnVariables) {
|
|
10977
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
10978
|
-
const nestAft = na && na.length;
|
|
10979
|
-
if (nestBef < nestAft) options.nest = false;
|
|
10980
|
-
}
|
|
10981
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
10982
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
10983
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10984
|
-
args[_key] = arguments[_key];
|
|
10985
|
-
}
|
|
10986
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
10987
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
10988
|
-
return null;
|
|
10989
|
-
}
|
|
10990
|
-
return _this.translate(...args, key);
|
|
10991
|
-
}, options);
|
|
10992
|
-
if (options.interpolation) this.interpolator.reset();
|
|
10993
|
-
}
|
|
10994
|
-
const postProcess = options.postProcess || this.options.postProcess;
|
|
10995
|
-
const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
10996
|
-
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
10997
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
10998
|
-
i18nResolved: {
|
|
10999
|
-
...resolved,
|
|
11000
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
11001
|
-
},
|
|
11002
|
-
...options
|
|
11003
|
-
} : options, this);
|
|
11004
|
-
}
|
|
11005
|
-
return res;
|
|
11006
|
-
}
|
|
11007
|
-
resolve(keys) {
|
|
11008
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11009
|
-
let found;
|
|
11010
|
-
let usedKey;
|
|
11011
|
-
let exactUsedKey;
|
|
11012
|
-
let usedLng;
|
|
11013
|
-
let usedNS;
|
|
11014
|
-
if (typeof keys === 'string') keys = [keys];
|
|
11015
|
-
keys.forEach(k => {
|
|
11016
|
-
if (this.isValidLookup(found)) return;
|
|
11017
|
-
const extracted = this.extractFromKey(k, options);
|
|
11018
|
-
const key = extracted.key;
|
|
11019
|
-
usedKey = key;
|
|
11020
|
-
let namespaces = extracted.namespaces;
|
|
11021
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
11022
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
11023
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
11024
|
-
const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
11025
|
-
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
11026
|
-
namespaces.forEach(ns => {
|
|
11027
|
-
if (this.isValidLookup(found)) return;
|
|
11028
|
-
usedNS = ns;
|
|
11029
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
11030
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
11031
|
-
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!!!');
|
|
11032
|
-
}
|
|
11033
|
-
codes.forEach(code => {
|
|
11034
|
-
if (this.isValidLookup(found)) return;
|
|
11035
|
-
usedLng = code;
|
|
11036
|
-
const finalKeys = [key];
|
|
11037
|
-
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
11038
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
11039
|
-
} else {
|
|
11040
|
-
let pluralSuffix;
|
|
11041
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
11042
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
11043
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
11044
|
-
if (needsPluralHandling) {
|
|
11045
|
-
finalKeys.push(key + pluralSuffix);
|
|
11046
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
11047
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
11048
|
-
}
|
|
11049
|
-
if (needsZeroSuffixLookup) {
|
|
11050
|
-
finalKeys.push(key + zeroSuffix);
|
|
11051
|
-
}
|
|
11052
|
-
}
|
|
11053
|
-
if (needsContextHandling) {
|
|
11054
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
11055
|
-
finalKeys.push(contextKey);
|
|
11056
|
-
if (needsPluralHandling) {
|
|
11057
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
11058
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
11059
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
11060
|
-
}
|
|
11061
|
-
if (needsZeroSuffixLookup) {
|
|
11062
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
11063
|
-
}
|
|
11064
|
-
}
|
|
11065
|
-
}
|
|
11066
|
-
}
|
|
11067
|
-
let possibleKey;
|
|
11068
|
-
while (possibleKey = finalKeys.pop()) {
|
|
11069
|
-
if (!this.isValidLookup(found)) {
|
|
11070
|
-
exactUsedKey = possibleKey;
|
|
11071
|
-
found = this.getResource(code, ns, possibleKey, options);
|
|
11072
|
-
}
|
|
11073
|
-
}
|
|
11074
|
-
});
|
|
11075
|
-
});
|
|
11076
|
-
});
|
|
11077
|
-
return {
|
|
11078
|
-
res: found,
|
|
11079
|
-
usedKey,
|
|
11080
|
-
exactUsedKey,
|
|
11081
|
-
usedLng,
|
|
11082
|
-
usedNS
|
|
11083
|
-
};
|
|
11084
|
-
}
|
|
11085
|
-
isValidLookup(res) {
|
|
11086
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
11087
|
-
}
|
|
11088
|
-
getResource(code, ns, key) {
|
|
11089
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
11090
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
11091
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
11092
|
-
}
|
|
11093
|
-
getUsedParamsDetails() {
|
|
11094
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11095
|
-
const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
|
|
11096
|
-
const useOptionsReplaceForData = options.replace && typeof options.replace !== 'string';
|
|
11097
|
-
let data = useOptionsReplaceForData ? options.replace : options;
|
|
11098
|
-
if (useOptionsReplaceForData && typeof options.count !== 'undefined') {
|
|
11099
|
-
data.count = options.count;
|
|
11100
|
-
}
|
|
11101
|
-
if (this.options.interpolation.defaultVariables) {
|
|
11102
|
-
data = {
|
|
11103
|
-
...this.options.interpolation.defaultVariables,
|
|
11104
|
-
...data
|
|
11105
|
-
};
|
|
11106
|
-
}
|
|
11107
|
-
if (!useOptionsReplaceForData) {
|
|
11108
|
-
data = {
|
|
11109
|
-
...data
|
|
11110
|
-
};
|
|
11111
|
-
for (const key of optionsKeys) {
|
|
11112
|
-
delete data[key];
|
|
11113
|
-
}
|
|
11114
|
-
}
|
|
11115
|
-
return data;
|
|
11116
|
-
}
|
|
11117
|
-
static hasDefaultValue(options) {
|
|
11118
|
-
const prefix = 'defaultValue';
|
|
11119
|
-
for (const option in options) {
|
|
11120
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
11121
|
-
return true;
|
|
11122
|
-
}
|
|
11123
|
-
}
|
|
11124
|
-
return false;
|
|
11125
|
-
}
|
|
11126
|
-
}
|
|
11127
|
-
|
|
11128
|
-
function capitalize(string) {
|
|
11129
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
11130
|
-
}
|
|
11131
|
-
class LanguageUtil {
|
|
11132
|
-
constructor(options) {
|
|
11133
|
-
this.options = options;
|
|
11134
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
11135
|
-
this.logger = baseLogger.create('languageUtils');
|
|
11136
|
-
}
|
|
11137
|
-
getScriptPartFromCode(code) {
|
|
11138
|
-
code = getCleanedCode(code);
|
|
11139
|
-
if (!code || code.indexOf('-') < 0) return null;
|
|
11140
|
-
const p = code.split('-');
|
|
11141
|
-
if (p.length === 2) return null;
|
|
11142
|
-
p.pop();
|
|
11143
|
-
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
11144
|
-
return this.formatLanguageCode(p.join('-'));
|
|
11145
|
-
}
|
|
11146
|
-
getLanguagePartFromCode(code) {
|
|
11147
|
-
code = getCleanedCode(code);
|
|
11148
|
-
if (!code || code.indexOf('-') < 0) return code;
|
|
11149
|
-
const p = code.split('-');
|
|
11150
|
-
return this.formatLanguageCode(p[0]);
|
|
11151
|
-
}
|
|
11152
|
-
formatLanguageCode(code) {
|
|
11153
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
11154
|
-
const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
11155
|
-
let p = code.split('-');
|
|
11156
|
-
if (this.options.lowerCaseLng) {
|
|
11157
|
-
p = p.map(part => part.toLowerCase());
|
|
11158
|
-
} else if (p.length === 2) {
|
|
11159
|
-
p[0] = p[0].toLowerCase();
|
|
11160
|
-
p[1] = p[1].toUpperCase();
|
|
11161
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
11162
|
-
} else if (p.length === 3) {
|
|
11163
|
-
p[0] = p[0].toLowerCase();
|
|
11164
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
11165
|
-
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
11166
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
11167
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
11168
|
-
}
|
|
11169
|
-
return p.join('-');
|
|
11170
|
-
}
|
|
11171
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
11172
|
-
}
|
|
11173
|
-
isSupportedCode(code) {
|
|
11174
|
-
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
11175
|
-
code = this.getLanguagePartFromCode(code);
|
|
11176
|
-
}
|
|
11177
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
11178
|
-
}
|
|
11179
|
-
getBestMatchFromCodes(codes) {
|
|
11180
|
-
if (!codes) return null;
|
|
11181
|
-
let found;
|
|
11182
|
-
codes.forEach(code => {
|
|
11183
|
-
if (found) return;
|
|
11184
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
11185
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
11186
|
-
});
|
|
11187
|
-
if (!found && this.options.supportedLngs) {
|
|
11188
|
-
codes.forEach(code => {
|
|
11189
|
-
if (found) return;
|
|
11190
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
11191
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
11192
|
-
found = this.options.supportedLngs.find(supportedLng => {
|
|
11193
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
11194
|
-
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
11195
|
-
if (supportedLng.indexOf('-') > 0 && lngOnly.indexOf('-') < 0 && supportedLng.substring(0, supportedLng.indexOf('-')) === lngOnly) return supportedLng;
|
|
11196
|
-
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
11197
|
-
});
|
|
11198
|
-
});
|
|
11199
|
-
}
|
|
11200
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
11201
|
-
return found;
|
|
11202
|
-
}
|
|
11203
|
-
getFallbackCodes(fallbacks, code) {
|
|
11204
|
-
if (!fallbacks) return [];
|
|
11205
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
11206
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
11207
|
-
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
11208
|
-
if (!code) return fallbacks.default || [];
|
|
11209
|
-
let found = fallbacks[code];
|
|
11210
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
11211
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
11212
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
11213
|
-
if (!found) found = fallbacks.default;
|
|
11214
|
-
return found || [];
|
|
11215
|
-
}
|
|
11216
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
11217
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
11218
|
-
const codes = [];
|
|
11219
|
-
const addCode = c => {
|
|
11220
|
-
if (!c) return;
|
|
11221
|
-
if (this.isSupportedCode(c)) {
|
|
11222
|
-
codes.push(c);
|
|
11223
|
-
} else {
|
|
11224
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
11225
|
-
}
|
|
11226
|
-
};
|
|
11227
|
-
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
11228
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
11229
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
11230
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
11231
|
-
} else if (typeof code === 'string') {
|
|
11232
|
-
addCode(this.formatLanguageCode(code));
|
|
11233
|
-
}
|
|
11234
|
-
fallbackCodes.forEach(fc => {
|
|
11235
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
11236
|
-
});
|
|
11237
|
-
return codes;
|
|
11238
|
-
}
|
|
11239
|
-
}
|
|
11240
|
-
|
|
11241
|
-
let sets = [{
|
|
11242
|
-
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
11243
|
-
nr: [1, 2],
|
|
11244
|
-
fc: 1
|
|
11245
|
-
}, {
|
|
11246
|
-
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'],
|
|
11247
|
-
nr: [1, 2],
|
|
11248
|
-
fc: 2
|
|
11249
|
-
}, {
|
|
11250
|
-
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
11251
|
-
nr: [1],
|
|
11252
|
-
fc: 3
|
|
11253
|
-
}, {
|
|
11254
|
-
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
11255
|
-
nr: [1, 2, 5],
|
|
11256
|
-
fc: 4
|
|
11257
|
-
}, {
|
|
11258
|
-
lngs: ['ar'],
|
|
11259
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
11260
|
-
fc: 5
|
|
11261
|
-
}, {
|
|
11262
|
-
lngs: ['cs', 'sk'],
|
|
11263
|
-
nr: [1, 2, 5],
|
|
11264
|
-
fc: 6
|
|
11265
|
-
}, {
|
|
11266
|
-
lngs: ['csb', 'pl'],
|
|
11267
|
-
nr: [1, 2, 5],
|
|
11268
|
-
fc: 7
|
|
11269
|
-
}, {
|
|
11270
|
-
lngs: ['cy'],
|
|
11271
|
-
nr: [1, 2, 3, 8],
|
|
11272
|
-
fc: 8
|
|
11273
|
-
}, {
|
|
11274
|
-
lngs: ['fr'],
|
|
11275
|
-
nr: [1, 2],
|
|
11276
|
-
fc: 9
|
|
11277
|
-
}, {
|
|
11278
|
-
lngs: ['ga'],
|
|
11279
|
-
nr: [1, 2, 3, 7, 11],
|
|
11280
|
-
fc: 10
|
|
11281
|
-
}, {
|
|
11282
|
-
lngs: ['gd'],
|
|
11283
|
-
nr: [1, 2, 3, 20],
|
|
11284
|
-
fc: 11
|
|
11285
|
-
}, {
|
|
11286
|
-
lngs: ['is'],
|
|
11287
|
-
nr: [1, 2],
|
|
11288
|
-
fc: 12
|
|
11289
|
-
}, {
|
|
11290
|
-
lngs: ['jv'],
|
|
11291
|
-
nr: [0, 1],
|
|
11292
|
-
fc: 13
|
|
11293
|
-
}, {
|
|
11294
|
-
lngs: ['kw'],
|
|
11295
|
-
nr: [1, 2, 3, 4],
|
|
11296
|
-
fc: 14
|
|
11297
|
-
}, {
|
|
11298
|
-
lngs: ['lt'],
|
|
11299
|
-
nr: [1, 2, 10],
|
|
11300
|
-
fc: 15
|
|
11301
|
-
}, {
|
|
11302
|
-
lngs: ['lv'],
|
|
11303
|
-
nr: [1, 2, 0],
|
|
11304
|
-
fc: 16
|
|
11305
|
-
}, {
|
|
11306
|
-
lngs: ['mk'],
|
|
11307
|
-
nr: [1, 2],
|
|
11308
|
-
fc: 17
|
|
11309
|
-
}, {
|
|
11310
|
-
lngs: ['mnk'],
|
|
11311
|
-
nr: [0, 1, 2],
|
|
11312
|
-
fc: 18
|
|
11313
|
-
}, {
|
|
11314
|
-
lngs: ['mt'],
|
|
11315
|
-
nr: [1, 2, 11, 20],
|
|
11316
|
-
fc: 19
|
|
11317
|
-
}, {
|
|
11318
|
-
lngs: ['or'],
|
|
11319
|
-
nr: [2, 1],
|
|
11320
|
-
fc: 2
|
|
11321
|
-
}, {
|
|
11322
|
-
lngs: ['ro'],
|
|
11323
|
-
nr: [1, 2, 20],
|
|
11324
|
-
fc: 20
|
|
11325
|
-
}, {
|
|
11326
|
-
lngs: ['sl'],
|
|
11327
|
-
nr: [5, 1, 2, 3],
|
|
11328
|
-
fc: 21
|
|
11329
|
-
}, {
|
|
11330
|
-
lngs: ['he', 'iw'],
|
|
11331
|
-
nr: [1, 2, 20, 21],
|
|
11332
|
-
fc: 22
|
|
11333
|
-
}];
|
|
11334
|
-
let _rulesPluralsTypes = {
|
|
11335
|
-
1: function (n) {
|
|
11336
|
-
return Number(n > 1);
|
|
11337
|
-
},
|
|
11338
|
-
2: function (n) {
|
|
11339
|
-
return Number(n != 1);
|
|
11340
|
-
},
|
|
11341
|
-
3: function (n) {
|
|
11342
|
-
return 0;
|
|
11343
|
-
},
|
|
11344
|
-
4: function (n) {
|
|
11345
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
11346
|
-
},
|
|
11347
|
-
5: function (n) {
|
|
11348
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
11349
|
-
},
|
|
11350
|
-
6: function (n) {
|
|
11351
|
-
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
11352
|
-
},
|
|
11353
|
-
7: function (n) {
|
|
11354
|
-
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
11355
|
-
},
|
|
11356
|
-
8: function (n) {
|
|
11357
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
11358
|
-
},
|
|
11359
|
-
9: function (n) {
|
|
11360
|
-
return Number(n >= 2);
|
|
11361
|
-
},
|
|
11362
|
-
10: function (n) {
|
|
11363
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
11364
|
-
},
|
|
11365
|
-
11: function (n) {
|
|
11366
|
-
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
11367
|
-
},
|
|
11368
|
-
12: function (n) {
|
|
11369
|
-
return Number(n % 10 != 1 || n % 100 == 11);
|
|
11370
|
-
},
|
|
11371
|
-
13: function (n) {
|
|
11372
|
-
return Number(n !== 0);
|
|
11373
|
-
},
|
|
11374
|
-
14: function (n) {
|
|
11375
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
11376
|
-
},
|
|
11377
|
-
15: function (n) {
|
|
11378
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
11379
|
-
},
|
|
11380
|
-
16: function (n) {
|
|
11381
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
11382
|
-
},
|
|
11383
|
-
17: function (n) {
|
|
11384
|
-
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
11385
|
-
},
|
|
11386
|
-
18: function (n) {
|
|
11387
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
11388
|
-
},
|
|
11389
|
-
19: function (n) {
|
|
11390
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
11391
|
-
},
|
|
11392
|
-
20: function (n) {
|
|
11393
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
11394
|
-
},
|
|
11395
|
-
21: function (n) {
|
|
11396
|
-
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
11397
|
-
},
|
|
11398
|
-
22: function (n) {
|
|
11399
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
11400
|
-
}
|
|
11401
|
-
};
|
|
11402
|
-
const nonIntlVersions = ['v1', 'v2', 'v3'];
|
|
11403
|
-
const intlVersions = ['v4'];
|
|
11404
|
-
const suffixesOrder = {
|
|
11405
|
-
zero: 0,
|
|
11406
|
-
one: 1,
|
|
11407
|
-
two: 2,
|
|
11408
|
-
few: 3,
|
|
11409
|
-
many: 4,
|
|
11410
|
-
other: 5
|
|
11411
|
-
};
|
|
11412
|
-
function createRules() {
|
|
11413
|
-
const rules = {};
|
|
11414
|
-
sets.forEach(set => {
|
|
11415
|
-
set.lngs.forEach(l => {
|
|
11416
|
-
rules[l] = {
|
|
11417
|
-
numbers: set.nr,
|
|
11418
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
11419
|
-
};
|
|
11420
|
-
});
|
|
11421
|
-
});
|
|
11422
|
-
return rules;
|
|
11423
|
-
}
|
|
11424
|
-
class PluralResolver {
|
|
11425
|
-
constructor(languageUtils) {
|
|
11426
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11427
|
-
this.languageUtils = languageUtils;
|
|
11428
|
-
this.options = options;
|
|
11429
|
-
this.logger = baseLogger.create('pluralResolver');
|
|
11430
|
-
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
11431
|
-
this.options.compatibilityJSON = 'v3';
|
|
11432
|
-
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.');
|
|
11433
|
-
}
|
|
11434
|
-
this.rules = createRules();
|
|
11435
|
-
}
|
|
11436
|
-
addRule(lng, obj) {
|
|
11437
|
-
this.rules[lng] = obj;
|
|
11438
|
-
}
|
|
11439
|
-
getRule(code) {
|
|
11440
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11441
|
-
if (this.shouldUseIntlApi()) {
|
|
11442
|
-
try {
|
|
11443
|
-
return new Intl.PluralRules(getCleanedCode(code === 'dev' ? 'en' : code), {
|
|
11444
|
-
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
11445
|
-
});
|
|
11446
|
-
} catch (err) {
|
|
11447
|
-
return;
|
|
11448
|
-
}
|
|
11449
|
-
}
|
|
11450
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
11451
|
-
}
|
|
11452
|
-
needsPlural(code) {
|
|
11453
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11454
|
-
const rule = this.getRule(code, options);
|
|
11455
|
-
if (this.shouldUseIntlApi()) {
|
|
11456
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
11457
|
-
}
|
|
11458
|
-
return rule && rule.numbers.length > 1;
|
|
11459
|
-
}
|
|
11460
|
-
getPluralFormsOfKey(code, key) {
|
|
11461
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11462
|
-
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
11463
|
-
}
|
|
11464
|
-
getSuffixes(code) {
|
|
11465
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11466
|
-
const rule = this.getRule(code, options);
|
|
11467
|
-
if (!rule) {
|
|
11468
|
-
return [];
|
|
11469
|
-
}
|
|
11470
|
-
if (this.shouldUseIntlApi()) {
|
|
11471
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
11472
|
-
}
|
|
11473
|
-
return rule.numbers.map(number => this.getSuffix(code, number, options));
|
|
11474
|
-
}
|
|
11475
|
-
getSuffix(code, count) {
|
|
11476
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11477
|
-
const rule = this.getRule(code, options);
|
|
11478
|
-
if (rule) {
|
|
11479
|
-
if (this.shouldUseIntlApi()) {
|
|
11480
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
11481
|
-
}
|
|
11482
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
11483
|
-
}
|
|
11484
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
11485
|
-
return '';
|
|
11486
|
-
}
|
|
11487
|
-
getSuffixRetroCompatible(rule, count) {
|
|
11488
|
-
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
11489
|
-
let suffix = rule.numbers[idx];
|
|
11490
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
11491
|
-
if (suffix === 2) {
|
|
11492
|
-
suffix = 'plural';
|
|
11493
|
-
} else if (suffix === 1) {
|
|
11494
|
-
suffix = '';
|
|
11495
|
-
}
|
|
11496
|
-
}
|
|
11497
|
-
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
11498
|
-
if (this.options.compatibilityJSON === 'v1') {
|
|
11499
|
-
if (suffix === 1) return '';
|
|
11500
|
-
if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
|
|
11501
|
-
return returnSuffix();
|
|
11502
|
-
} else if (this.options.compatibilityJSON === 'v2') {
|
|
11503
|
-
return returnSuffix();
|
|
11504
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
11505
|
-
return returnSuffix();
|
|
11506
|
-
}
|
|
11507
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
11508
|
-
}
|
|
11509
|
-
shouldUseIntlApi() {
|
|
11510
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
11511
|
-
}
|
|
11512
|
-
}
|
|
11513
|
-
|
|
11514
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
11515
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
11516
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
11517
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
11518
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
11519
|
-
path = deepFind(data, key, keySeparator);
|
|
11520
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
11521
|
-
}
|
|
11522
|
-
return path;
|
|
11523
|
-
}
|
|
11524
|
-
class Interpolator {
|
|
11525
|
-
constructor() {
|
|
11526
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11527
|
-
this.logger = baseLogger.create('interpolator');
|
|
11528
|
-
this.options = options;
|
|
11529
|
-
this.format = options.interpolation && options.interpolation.format || (value => value);
|
|
11530
|
-
this.init(options);
|
|
11531
|
-
}
|
|
11532
|
-
init() {
|
|
11533
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11534
|
-
if (!options.interpolation) options.interpolation = {
|
|
11535
|
-
escapeValue: true
|
|
11536
|
-
};
|
|
11537
|
-
const iOpts = options.interpolation;
|
|
11538
|
-
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape$1;
|
|
11539
|
-
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
11540
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
11541
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
11542
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
11543
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
11544
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
11545
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
11546
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
11547
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
11548
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
11549
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
11550
|
-
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
11551
|
-
this.resetRegExp();
|
|
11552
|
-
}
|
|
11553
|
-
reset() {
|
|
11554
|
-
if (this.options) this.init(this.options);
|
|
11555
|
-
}
|
|
11556
|
-
resetRegExp() {
|
|
11557
|
-
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
11558
|
-
if (existingRegExp && existingRegExp.source === pattern) {
|
|
11559
|
-
existingRegExp.lastIndex = 0;
|
|
11560
|
-
return existingRegExp;
|
|
11561
|
-
}
|
|
11562
|
-
return new RegExp(pattern, 'g');
|
|
11563
|
-
};
|
|
11564
|
-
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
11565
|
-
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
11566
|
-
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
11567
|
-
}
|
|
11568
|
-
interpolate(str, data, lng, options) {
|
|
11569
|
-
let match;
|
|
11570
|
-
let value;
|
|
11571
|
-
let replaces;
|
|
11572
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
11573
|
-
function regexSafe(val) {
|
|
11574
|
-
return val.replace(/\$/g, '$$$$');
|
|
11575
|
-
}
|
|
11576
|
-
const handleFormat = key => {
|
|
11577
|
-
if (key.indexOf(this.formatSeparator) < 0) {
|
|
11578
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
11579
|
-
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
11580
|
-
...options,
|
|
11581
|
-
...data,
|
|
11582
|
-
interpolationkey: key
|
|
11583
|
-
}) : path;
|
|
11584
|
-
}
|
|
11585
|
-
const p = key.split(this.formatSeparator);
|
|
11586
|
-
const k = p.shift().trim();
|
|
11587
|
-
const f = p.join(this.formatSeparator).trim();
|
|
11588
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
11589
|
-
...options,
|
|
11590
|
-
...data,
|
|
11591
|
-
interpolationkey: k
|
|
11592
|
-
});
|
|
11593
|
-
};
|
|
11594
|
-
this.resetRegExp();
|
|
11595
|
-
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
11596
|
-
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
11597
|
-
const todos = [{
|
|
11598
|
-
regex: this.regexpUnescape,
|
|
11599
|
-
safeValue: val => regexSafe(val)
|
|
11600
|
-
}, {
|
|
11601
|
-
regex: this.regexp,
|
|
11602
|
-
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
11603
|
-
}];
|
|
11604
|
-
todos.forEach(todo => {
|
|
11605
|
-
replaces = 0;
|
|
11606
|
-
while (match = todo.regex.exec(str)) {
|
|
11607
|
-
const matchedVar = match[1].trim();
|
|
11608
|
-
value = handleFormat(matchedVar);
|
|
11609
|
-
if (value === undefined) {
|
|
11610
|
-
if (typeof missingInterpolationHandler === 'function') {
|
|
11611
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
11612
|
-
value = typeof temp === 'string' ? temp : '';
|
|
11613
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
11614
|
-
value = '';
|
|
11615
|
-
} else if (skipOnVariables) {
|
|
11616
|
-
value = match[0];
|
|
11617
|
-
continue;
|
|
11618
|
-
} else {
|
|
11619
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
11620
|
-
value = '';
|
|
11621
|
-
}
|
|
11622
|
-
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
11623
|
-
value = makeString(value);
|
|
11624
|
-
}
|
|
11625
|
-
const safeValue = todo.safeValue(value);
|
|
11626
|
-
str = str.replace(match[0], safeValue);
|
|
11627
|
-
if (skipOnVariables) {
|
|
11628
|
-
todo.regex.lastIndex += value.length;
|
|
11629
|
-
todo.regex.lastIndex -= match[0].length;
|
|
11630
|
-
} else {
|
|
11631
|
-
todo.regex.lastIndex = 0;
|
|
11632
|
-
}
|
|
11633
|
-
replaces++;
|
|
11634
|
-
if (replaces >= this.maxReplaces) {
|
|
11635
|
-
break;
|
|
11636
|
-
}
|
|
11637
|
-
}
|
|
11638
|
-
});
|
|
11639
|
-
return str;
|
|
11640
|
-
}
|
|
11641
|
-
nest(str, fc) {
|
|
11642
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11643
|
-
let match;
|
|
11644
|
-
let value;
|
|
11645
|
-
let clonedOptions;
|
|
11646
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
11647
|
-
const sep = this.nestingOptionsSeparator;
|
|
11648
|
-
if (key.indexOf(sep) < 0) return key;
|
|
11649
|
-
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
11650
|
-
let optionsString = `{${c[1]}`;
|
|
11651
|
-
key = c[0];
|
|
11652
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
11653
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
11654
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
11655
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
11656
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
11657
|
-
}
|
|
11658
|
-
try {
|
|
11659
|
-
clonedOptions = JSON.parse(optionsString);
|
|
11660
|
-
if (inheritedOptions) clonedOptions = {
|
|
11661
|
-
...inheritedOptions,
|
|
11662
|
-
...clonedOptions
|
|
11663
|
-
};
|
|
11664
|
-
} catch (e) {
|
|
11665
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
11666
|
-
return `${key}${sep}${optionsString}`;
|
|
11667
|
-
}
|
|
11668
|
-
delete clonedOptions.defaultValue;
|
|
11669
|
-
return key;
|
|
11670
|
-
}
|
|
11671
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
11672
|
-
let formatters = [];
|
|
11673
|
-
clonedOptions = {
|
|
11674
|
-
...options
|
|
11675
|
-
};
|
|
11676
|
-
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
11677
|
-
clonedOptions.applyPostProcessor = false;
|
|
11678
|
-
delete clonedOptions.defaultValue;
|
|
11679
|
-
let doReduce = false;
|
|
11680
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
11681
|
-
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
11682
|
-
match[1] = r.shift();
|
|
11683
|
-
formatters = r;
|
|
11684
|
-
doReduce = true;
|
|
11685
|
-
}
|
|
11686
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
11687
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
11688
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
11689
|
-
if (!value) {
|
|
11690
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
11691
|
-
value = '';
|
|
11692
|
-
}
|
|
11693
|
-
if (doReduce) {
|
|
11694
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
11695
|
-
...options,
|
|
11696
|
-
interpolationkey: match[1].trim()
|
|
11697
|
-
}), value.trim());
|
|
11698
|
-
}
|
|
11699
|
-
str = str.replace(match[0], value);
|
|
11700
|
-
this.regexp.lastIndex = 0;
|
|
11701
|
-
}
|
|
11702
|
-
return str;
|
|
11703
|
-
}
|
|
11704
|
-
}
|
|
11705
|
-
|
|
11706
|
-
function parseFormatStr(formatStr) {
|
|
11707
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
11708
|
-
const formatOptions = {};
|
|
11709
|
-
if (formatStr.indexOf('(') > -1) {
|
|
11710
|
-
const p = formatStr.split('(');
|
|
11711
|
-
formatName = p[0].toLowerCase().trim();
|
|
11712
|
-
const optStr = p[1].substring(0, p[1].length - 1);
|
|
11713
|
-
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
11714
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
11715
|
-
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
11716
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
11717
|
-
} else {
|
|
11718
|
-
const opts = optStr.split(';');
|
|
11719
|
-
opts.forEach(opt => {
|
|
11720
|
-
if (!opt) return;
|
|
11721
|
-
const [key, ...rest] = opt.split(':');
|
|
11722
|
-
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
11723
|
-
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
11724
|
-
if (val === 'false') formatOptions[key.trim()] = false;
|
|
11725
|
-
if (val === 'true') formatOptions[key.trim()] = true;
|
|
11726
|
-
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
11727
|
-
});
|
|
11728
|
-
}
|
|
11729
|
-
}
|
|
11730
|
-
return {
|
|
11731
|
-
formatName,
|
|
11732
|
-
formatOptions
|
|
11733
|
-
};
|
|
11734
|
-
}
|
|
11735
|
-
function createCachedFormatter(fn) {
|
|
11736
|
-
const cache = {};
|
|
11737
|
-
return function invokeFormatter(val, lng, options) {
|
|
11738
|
-
const key = lng + JSON.stringify(options);
|
|
11739
|
-
let formatter = cache[key];
|
|
11740
|
-
if (!formatter) {
|
|
11741
|
-
formatter = fn(getCleanedCode(lng), options);
|
|
11742
|
-
cache[key] = formatter;
|
|
11743
|
-
}
|
|
11744
|
-
return formatter(val);
|
|
11745
|
-
};
|
|
11746
|
-
}
|
|
11747
|
-
class Formatter {
|
|
11748
|
-
constructor() {
|
|
11749
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11750
|
-
this.logger = baseLogger.create('formatter');
|
|
11751
|
-
this.options = options;
|
|
11752
|
-
this.formats = {
|
|
11753
|
-
number: createCachedFormatter((lng, opt) => {
|
|
11754
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
11755
|
-
...opt
|
|
11756
|
-
});
|
|
11757
|
-
return val => formatter.format(val);
|
|
11758
|
-
}),
|
|
11759
|
-
currency: createCachedFormatter((lng, opt) => {
|
|
11760
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
11761
|
-
...opt,
|
|
11762
|
-
style: 'currency'
|
|
11763
|
-
});
|
|
11764
|
-
return val => formatter.format(val);
|
|
11765
|
-
}),
|
|
11766
|
-
datetime: createCachedFormatter((lng, opt) => {
|
|
11767
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
11768
|
-
...opt
|
|
11769
|
-
});
|
|
11770
|
-
return val => formatter.format(val);
|
|
11771
|
-
}),
|
|
11772
|
-
relativetime: createCachedFormatter((lng, opt) => {
|
|
11773
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
11774
|
-
...opt
|
|
11775
|
-
});
|
|
11776
|
-
return val => formatter.format(val, opt.range || 'day');
|
|
11777
|
-
}),
|
|
11778
|
-
list: createCachedFormatter((lng, opt) => {
|
|
11779
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
11780
|
-
...opt
|
|
11781
|
-
});
|
|
11782
|
-
return val => formatter.format(val);
|
|
11783
|
-
})
|
|
11784
|
-
};
|
|
11785
|
-
this.init(options);
|
|
11786
|
-
}
|
|
11787
|
-
init(services) {
|
|
11788
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
11789
|
-
interpolation: {}
|
|
11790
|
-
};
|
|
11791
|
-
const iOpts = options.interpolation;
|
|
11792
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
11793
|
-
}
|
|
11794
|
-
add(name, fc) {
|
|
11795
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
11796
|
-
}
|
|
11797
|
-
addCached(name, fc) {
|
|
11798
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
11799
|
-
}
|
|
11800
|
-
format(value, format, lng) {
|
|
11801
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
11802
|
-
const formats = format.split(this.formatSeparator);
|
|
11803
|
-
const result = formats.reduce((mem, f) => {
|
|
11804
|
-
const {
|
|
11805
|
-
formatName,
|
|
11806
|
-
formatOptions
|
|
11807
|
-
} = parseFormatStr(f);
|
|
11808
|
-
if (this.formats[formatName]) {
|
|
11809
|
-
let formatted = mem;
|
|
11810
|
-
try {
|
|
11811
|
-
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
11812
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
11813
|
-
formatted = this.formats[formatName](mem, l, {
|
|
11814
|
-
...formatOptions,
|
|
11815
|
-
...options,
|
|
11816
|
-
...valOptions
|
|
11817
|
-
});
|
|
11818
|
-
} catch (error) {
|
|
11819
|
-
this.logger.warn(error);
|
|
11820
|
-
}
|
|
11821
|
-
return formatted;
|
|
11822
|
-
} else {
|
|
11823
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
11824
|
-
}
|
|
11825
|
-
return mem;
|
|
11826
|
-
}, value);
|
|
11827
|
-
return result;
|
|
11828
|
-
}
|
|
11829
|
-
}
|
|
11830
|
-
|
|
11831
|
-
function removePending(q, name) {
|
|
11832
|
-
if (q.pending[name] !== undefined) {
|
|
11833
|
-
delete q.pending[name];
|
|
11834
|
-
q.pendingCount--;
|
|
11835
|
-
}
|
|
11836
|
-
}
|
|
11837
|
-
class Connector extends EventEmitter {
|
|
11838
|
-
constructor(backend, store, services) {
|
|
11839
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
11840
|
-
super();
|
|
11841
|
-
this.backend = backend;
|
|
11842
|
-
this.store = store;
|
|
11843
|
-
this.services = services;
|
|
11844
|
-
this.languageUtils = services.languageUtils;
|
|
11845
|
-
this.options = options;
|
|
11846
|
-
this.logger = baseLogger.create('backendConnector');
|
|
11847
|
-
this.waitingReads = [];
|
|
11848
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
11849
|
-
this.readingCalls = 0;
|
|
11850
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
11851
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
11852
|
-
this.state = {};
|
|
11853
|
-
this.queue = [];
|
|
11854
|
-
if (this.backend && this.backend.init) {
|
|
11855
|
-
this.backend.init(services, options.backend, options);
|
|
11856
|
-
}
|
|
11857
|
-
}
|
|
11858
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
11859
|
-
const toLoad = {};
|
|
11860
|
-
const pending = {};
|
|
11861
|
-
const toLoadLanguages = {};
|
|
11862
|
-
const toLoadNamespaces = {};
|
|
11863
|
-
languages.forEach(lng => {
|
|
11864
|
-
let hasAllNamespaces = true;
|
|
11865
|
-
namespaces.forEach(ns => {
|
|
11866
|
-
const name = `${lng}|${ns}`;
|
|
11867
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
11868
|
-
this.state[name] = 2;
|
|
11869
|
-
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
11870
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
11871
|
-
} else {
|
|
11872
|
-
this.state[name] = 1;
|
|
11873
|
-
hasAllNamespaces = false;
|
|
11874
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
11875
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
11876
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
11877
|
-
}
|
|
11878
|
-
});
|
|
11879
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
11880
|
-
});
|
|
11881
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
11882
|
-
this.queue.push({
|
|
11883
|
-
pending,
|
|
11884
|
-
pendingCount: Object.keys(pending).length,
|
|
11885
|
-
loaded: {},
|
|
11886
|
-
errors: [],
|
|
11887
|
-
callback
|
|
11888
|
-
});
|
|
11889
|
-
}
|
|
11890
|
-
return {
|
|
11891
|
-
toLoad: Object.keys(toLoad),
|
|
11892
|
-
pending: Object.keys(pending),
|
|
11893
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
11894
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
11895
|
-
};
|
|
11896
|
-
}
|
|
11897
|
-
loaded(name, err, data) {
|
|
11898
|
-
const s = name.split('|');
|
|
11899
|
-
const lng = s[0];
|
|
11900
|
-
const ns = s[1];
|
|
11901
|
-
if (err) this.emit('failedLoading', lng, ns, err);
|
|
11902
|
-
if (data) {
|
|
11903
|
-
this.store.addResourceBundle(lng, ns, data, undefined, undefined, {
|
|
11904
|
-
skipCopy: true
|
|
11905
|
-
});
|
|
11906
|
-
}
|
|
11907
|
-
this.state[name] = err ? -1 : 2;
|
|
11908
|
-
const loaded = {};
|
|
11909
|
-
this.queue.forEach(q => {
|
|
11910
|
-
pushPath(q.loaded, [lng], ns);
|
|
11911
|
-
removePending(q, name);
|
|
11912
|
-
if (err) q.errors.push(err);
|
|
11913
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
11914
|
-
Object.keys(q.loaded).forEach(l => {
|
|
11915
|
-
if (!loaded[l]) loaded[l] = {};
|
|
11916
|
-
const loadedKeys = q.loaded[l];
|
|
11917
|
-
if (loadedKeys.length) {
|
|
11918
|
-
loadedKeys.forEach(n => {
|
|
11919
|
-
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
11920
|
-
});
|
|
11921
|
-
}
|
|
11922
|
-
});
|
|
11923
|
-
q.done = true;
|
|
11924
|
-
if (q.errors.length) {
|
|
11925
|
-
q.callback(q.errors);
|
|
11926
|
-
} else {
|
|
11927
|
-
q.callback();
|
|
11928
|
-
}
|
|
11929
|
-
}
|
|
11930
|
-
});
|
|
11931
|
-
this.emit('loaded', loaded);
|
|
11932
|
-
this.queue = this.queue.filter(q => !q.done);
|
|
11933
|
-
}
|
|
11934
|
-
read(lng, ns, fcName) {
|
|
11935
|
-
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
11936
|
-
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
11937
|
-
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
11938
|
-
if (!lng.length) return callback(null, {});
|
|
11939
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
11940
|
-
this.waitingReads.push({
|
|
11941
|
-
lng,
|
|
11942
|
-
ns,
|
|
11943
|
-
fcName,
|
|
11944
|
-
tried,
|
|
11945
|
-
wait,
|
|
11946
|
-
callback
|
|
11947
|
-
});
|
|
11948
|
-
return;
|
|
11949
|
-
}
|
|
11950
|
-
this.readingCalls++;
|
|
11951
|
-
const resolver = (err, data) => {
|
|
11952
|
-
this.readingCalls--;
|
|
11953
|
-
if (this.waitingReads.length > 0) {
|
|
11954
|
-
const next = this.waitingReads.shift();
|
|
11955
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
11956
|
-
}
|
|
11957
|
-
if (err && data && tried < this.maxRetries) {
|
|
11958
|
-
setTimeout(() => {
|
|
11959
|
-
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
11960
|
-
}, wait);
|
|
11961
|
-
return;
|
|
11962
|
-
}
|
|
11963
|
-
callback(err, data);
|
|
11964
|
-
};
|
|
11965
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
11966
|
-
if (fc.length === 2) {
|
|
11967
|
-
try {
|
|
11968
|
-
const r = fc(lng, ns);
|
|
11969
|
-
if (r && typeof r.then === 'function') {
|
|
11970
|
-
r.then(data => resolver(null, data)).catch(resolver);
|
|
11971
|
-
} else {
|
|
11972
|
-
resolver(null, r);
|
|
11973
|
-
}
|
|
11974
|
-
} catch (err) {
|
|
11975
|
-
resolver(err);
|
|
11976
|
-
}
|
|
11977
|
-
return;
|
|
11978
|
-
}
|
|
11979
|
-
return fc(lng, ns, resolver);
|
|
11980
|
-
}
|
|
11981
|
-
prepareLoading(languages, namespaces) {
|
|
11982
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11983
|
-
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
11984
|
-
if (!this.backend) {
|
|
11985
|
-
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
11986
|
-
return callback && callback();
|
|
11987
|
-
}
|
|
11988
|
-
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
11989
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
11990
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
11991
|
-
if (!toLoad.toLoad.length) {
|
|
11992
|
-
if (!toLoad.pending.length) callback();
|
|
11993
|
-
return null;
|
|
11994
|
-
}
|
|
11995
|
-
toLoad.toLoad.forEach(name => {
|
|
11996
|
-
this.loadOne(name);
|
|
11997
|
-
});
|
|
11998
|
-
}
|
|
11999
|
-
load(languages, namespaces, callback) {
|
|
12000
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
12001
|
-
}
|
|
12002
|
-
reload(languages, namespaces, callback) {
|
|
12003
|
-
this.prepareLoading(languages, namespaces, {
|
|
12004
|
-
reload: true
|
|
12005
|
-
}, callback);
|
|
12006
|
-
}
|
|
12007
|
-
loadOne(name) {
|
|
12008
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
12009
|
-
const s = name.split('|');
|
|
12010
|
-
const lng = s[0];
|
|
12011
|
-
const ns = s[1];
|
|
12012
|
-
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
12013
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
12014
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
12015
|
-
this.loaded(name, err, data);
|
|
12016
|
-
});
|
|
12017
|
-
}
|
|
12018
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
12019
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
12020
|
-
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
12021
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
12022
|
-
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!!!');
|
|
12023
|
-
return;
|
|
12024
|
-
}
|
|
12025
|
-
if (key === undefined || key === null || key === '') return;
|
|
12026
|
-
if (this.backend && this.backend.create) {
|
|
12027
|
-
const opts = {
|
|
12028
|
-
...options,
|
|
12029
|
-
isUpdate
|
|
12030
|
-
};
|
|
12031
|
-
const fc = this.backend.create.bind(this.backend);
|
|
12032
|
-
if (fc.length < 6) {
|
|
12033
|
-
try {
|
|
12034
|
-
let r;
|
|
12035
|
-
if (fc.length === 5) {
|
|
12036
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
12037
|
-
} else {
|
|
12038
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
12039
|
-
}
|
|
12040
|
-
if (r && typeof r.then === 'function') {
|
|
12041
|
-
r.then(data => clb(null, data)).catch(clb);
|
|
12042
|
-
} else {
|
|
12043
|
-
clb(null, r);
|
|
12044
|
-
}
|
|
12045
|
-
} catch (err) {
|
|
12046
|
-
clb(err);
|
|
12047
|
-
}
|
|
12048
|
-
} else {
|
|
12049
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
12050
|
-
}
|
|
12051
|
-
}
|
|
12052
|
-
if (!languages || !languages[0]) return;
|
|
12053
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
12054
|
-
}
|
|
12055
|
-
}
|
|
12056
|
-
|
|
12057
|
-
function get() {
|
|
12058
|
-
return {
|
|
12059
|
-
debug: false,
|
|
12060
|
-
initImmediate: true,
|
|
12061
|
-
ns: ['translation'],
|
|
12062
|
-
defaultNS: ['translation'],
|
|
12063
|
-
fallbackLng: ['dev'],
|
|
12064
|
-
fallbackNS: false,
|
|
12065
|
-
supportedLngs: false,
|
|
12066
|
-
nonExplicitSupportedLngs: false,
|
|
12067
|
-
load: 'all',
|
|
12068
|
-
preload: false,
|
|
12069
|
-
simplifyPluralSuffix: true,
|
|
12070
|
-
keySeparator: '.',
|
|
12071
|
-
nsSeparator: ':',
|
|
12072
|
-
pluralSeparator: '_',
|
|
12073
|
-
contextSeparator: '_',
|
|
12074
|
-
partialBundledLanguages: false,
|
|
12075
|
-
saveMissing: false,
|
|
12076
|
-
updateMissing: false,
|
|
12077
|
-
saveMissingTo: 'fallback',
|
|
12078
|
-
saveMissingPlurals: true,
|
|
12079
|
-
missingKeyHandler: false,
|
|
12080
|
-
missingInterpolationHandler: false,
|
|
12081
|
-
postProcess: false,
|
|
12082
|
-
postProcessPassResolved: false,
|
|
12083
|
-
returnNull: false,
|
|
12084
|
-
returnEmptyString: true,
|
|
12085
|
-
returnObjects: false,
|
|
12086
|
-
joinArrays: false,
|
|
12087
|
-
returnedObjectHandler: false,
|
|
12088
|
-
parseMissingKeyHandler: false,
|
|
12089
|
-
appendNamespaceToMissingKey: false,
|
|
12090
|
-
appendNamespaceToCIMode: false,
|
|
12091
|
-
overloadTranslationOptionHandler: function handle(args) {
|
|
12092
|
-
let ret = {};
|
|
12093
|
-
if (typeof args[1] === 'object') ret = args[1];
|
|
12094
|
-
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
12095
|
-
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
12096
|
-
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
12097
|
-
const options = args[3] || args[2];
|
|
12098
|
-
Object.keys(options).forEach(key => {
|
|
12099
|
-
ret[key] = options[key];
|
|
12100
|
-
});
|
|
12101
|
-
}
|
|
12102
|
-
return ret;
|
|
12103
|
-
},
|
|
12104
|
-
interpolation: {
|
|
12105
|
-
escapeValue: true,
|
|
12106
|
-
format: value => value,
|
|
12107
|
-
prefix: '{{',
|
|
12108
|
-
suffix: '}}',
|
|
12109
|
-
formatSeparator: ',',
|
|
12110
|
-
unescapePrefix: '-',
|
|
12111
|
-
nestingPrefix: '$t(',
|
|
12112
|
-
nestingSuffix: ')',
|
|
12113
|
-
nestingOptionsSeparator: ',',
|
|
12114
|
-
maxReplaces: 1000,
|
|
12115
|
-
skipOnVariables: true
|
|
12116
|
-
}
|
|
12117
|
-
};
|
|
12118
|
-
}
|
|
12119
|
-
function transformOptions(options) {
|
|
12120
|
-
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
12121
|
-
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
12122
|
-
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
12123
|
-
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
12124
|
-
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
12125
|
-
}
|
|
12126
|
-
return options;
|
|
12127
|
-
}
|
|
12128
|
-
|
|
12129
|
-
function noop() {}
|
|
12130
|
-
function bindMemberFunctions(inst) {
|
|
12131
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
12132
|
-
mems.forEach(mem => {
|
|
12133
|
-
if (typeof inst[mem] === 'function') {
|
|
12134
|
-
inst[mem] = inst[mem].bind(inst);
|
|
12135
|
-
}
|
|
12136
|
-
});
|
|
12137
|
-
}
|
|
12138
|
-
class I18n extends EventEmitter {
|
|
12139
|
-
constructor() {
|
|
12140
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12141
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
12142
|
-
super();
|
|
12143
|
-
this.options = transformOptions(options);
|
|
12144
|
-
this.services = {};
|
|
12145
|
-
this.logger = baseLogger;
|
|
12146
|
-
this.modules = {
|
|
12147
|
-
external: []
|
|
12148
|
-
};
|
|
12149
|
-
bindMemberFunctions(this);
|
|
12150
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
12151
|
-
if (!this.options.initImmediate) {
|
|
12152
|
-
this.init(options, callback);
|
|
12153
|
-
return this;
|
|
12154
|
-
}
|
|
12155
|
-
setTimeout(() => {
|
|
12156
|
-
this.init(options, callback);
|
|
12157
|
-
}, 0);
|
|
12158
|
-
}
|
|
12159
|
-
}
|
|
12160
|
-
init() {
|
|
12161
|
-
var _this = this;
|
|
12162
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12163
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
12164
|
-
this.isInitializing = true;
|
|
12165
|
-
if (typeof options === 'function') {
|
|
12166
|
-
callback = options;
|
|
12167
|
-
options = {};
|
|
12168
|
-
}
|
|
12169
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
12170
|
-
if (typeof options.ns === 'string') {
|
|
12171
|
-
options.defaultNS = options.ns;
|
|
12172
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
12173
|
-
options.defaultNS = options.ns[0];
|
|
12174
|
-
}
|
|
12175
|
-
}
|
|
12176
|
-
const defOpts = get();
|
|
12177
|
-
this.options = {
|
|
12178
|
-
...defOpts,
|
|
12179
|
-
...this.options,
|
|
12180
|
-
...transformOptions(options)
|
|
12181
|
-
};
|
|
12182
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
12183
|
-
this.options.interpolation = {
|
|
12184
|
-
...defOpts.interpolation,
|
|
12185
|
-
...this.options.interpolation
|
|
12186
|
-
};
|
|
12187
|
-
}
|
|
12188
|
-
if (options.keySeparator !== undefined) {
|
|
12189
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
12190
|
-
}
|
|
12191
|
-
if (options.nsSeparator !== undefined) {
|
|
12192
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
12193
|
-
}
|
|
12194
|
-
function createClassOnDemand(ClassOrObject) {
|
|
12195
|
-
if (!ClassOrObject) return null;
|
|
12196
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
12197
|
-
return ClassOrObject;
|
|
12198
|
-
}
|
|
12199
|
-
if (!this.options.isClone) {
|
|
12200
|
-
if (this.modules.logger) {
|
|
12201
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
12202
|
-
} else {
|
|
12203
|
-
baseLogger.init(null, this.options);
|
|
12204
|
-
}
|
|
12205
|
-
let formatter;
|
|
12206
|
-
if (this.modules.formatter) {
|
|
12207
|
-
formatter = this.modules.formatter;
|
|
12208
|
-
} else if (typeof Intl !== 'undefined') {
|
|
12209
|
-
formatter = Formatter;
|
|
12210
|
-
}
|
|
12211
|
-
const lu = new LanguageUtil(this.options);
|
|
12212
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
12213
|
-
const s = this.services;
|
|
12214
|
-
s.logger = baseLogger;
|
|
12215
|
-
s.resourceStore = this.store;
|
|
12216
|
-
s.languageUtils = lu;
|
|
12217
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
12218
|
-
prepend: this.options.pluralSeparator,
|
|
12219
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
12220
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
12221
|
-
});
|
|
12222
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
12223
|
-
s.formatter = createClassOnDemand(formatter);
|
|
12224
|
-
s.formatter.init(s, this.options);
|
|
12225
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
12226
|
-
}
|
|
12227
|
-
s.interpolator = new Interpolator(this.options);
|
|
12228
|
-
s.utils = {
|
|
12229
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
12230
|
-
};
|
|
12231
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
12232
|
-
s.backendConnector.on('*', function (event) {
|
|
12233
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
12234
|
-
args[_key - 1] = arguments[_key];
|
|
12235
|
-
}
|
|
12236
|
-
_this.emit(event, ...args);
|
|
12237
|
-
});
|
|
12238
|
-
if (this.modules.languageDetector) {
|
|
12239
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
12240
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
12241
|
-
}
|
|
12242
|
-
if (this.modules.i18nFormat) {
|
|
12243
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
12244
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
12245
|
-
}
|
|
12246
|
-
this.translator = new Translator(this.services, this.options);
|
|
12247
|
-
this.translator.on('*', function (event) {
|
|
12248
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
12249
|
-
args[_key2 - 1] = arguments[_key2];
|
|
12250
|
-
}
|
|
12251
|
-
_this.emit(event, ...args);
|
|
12252
|
-
});
|
|
12253
|
-
this.modules.external.forEach(m => {
|
|
12254
|
-
if (m.init) m.init(this);
|
|
12255
|
-
});
|
|
12256
|
-
}
|
|
12257
|
-
this.format = this.options.interpolation.format;
|
|
12258
|
-
if (!callback) callback = noop;
|
|
12259
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
12260
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
12261
|
-
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
12262
|
-
}
|
|
12263
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
12264
|
-
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
12265
|
-
}
|
|
12266
|
-
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
12267
|
-
storeApi.forEach(fcName => {
|
|
12268
|
-
this[fcName] = function () {
|
|
12269
|
-
return _this.store[fcName](...arguments);
|
|
12270
|
-
};
|
|
12271
|
-
});
|
|
12272
|
-
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
12273
|
-
storeApiChained.forEach(fcName => {
|
|
12274
|
-
this[fcName] = function () {
|
|
12275
|
-
_this.store[fcName](...arguments);
|
|
12276
|
-
return _this;
|
|
12277
|
-
};
|
|
12278
|
-
});
|
|
12279
|
-
const deferred = defer();
|
|
12280
|
-
const load = () => {
|
|
12281
|
-
const finish = (err, t) => {
|
|
12282
|
-
this.isInitializing = false;
|
|
12283
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
12284
|
-
this.isInitialized = true;
|
|
12285
|
-
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
12286
|
-
this.emit('initialized', this.options);
|
|
12287
|
-
deferred.resolve(t);
|
|
12288
|
-
callback(err, t);
|
|
12289
|
-
};
|
|
12290
|
-
if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
12291
|
-
this.changeLanguage(this.options.lng, finish);
|
|
12292
|
-
};
|
|
12293
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
12294
|
-
load();
|
|
12295
|
-
} else {
|
|
12296
|
-
setTimeout(load, 0);
|
|
12297
|
-
}
|
|
12298
|
-
return deferred;
|
|
12299
|
-
}
|
|
12300
|
-
loadResources(language) {
|
|
12301
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
12302
|
-
let usedCallback = callback;
|
|
12303
|
-
const usedLng = typeof language === 'string' ? language : this.language;
|
|
12304
|
-
if (typeof language === 'function') usedCallback = language;
|
|
12305
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
12306
|
-
if (usedLng && usedLng.toLowerCase() === 'cimode' && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
12307
|
-
const toLoad = [];
|
|
12308
|
-
const append = lng => {
|
|
12309
|
-
if (!lng) return;
|
|
12310
|
-
if (lng === 'cimode') return;
|
|
12311
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
12312
|
-
lngs.forEach(l => {
|
|
12313
|
-
if (l === 'cimode') return;
|
|
12314
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
12315
|
-
});
|
|
12316
|
-
};
|
|
12317
|
-
if (!usedLng) {
|
|
12318
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
12319
|
-
fallbacks.forEach(l => append(l));
|
|
12320
|
-
} else {
|
|
12321
|
-
append(usedLng);
|
|
12322
|
-
}
|
|
12323
|
-
if (this.options.preload) {
|
|
12324
|
-
this.options.preload.forEach(l => append(l));
|
|
12325
|
-
}
|
|
12326
|
-
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
12327
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
12328
|
-
usedCallback(e);
|
|
12329
|
-
});
|
|
12330
|
-
} else {
|
|
12331
|
-
usedCallback(null);
|
|
10065
|
+
_tooltipAlign: 'top',
|
|
10066
|
+
};
|
|
12332
10067
|
}
|
|
12333
|
-
|
|
12334
|
-
|
|
12335
|
-
const deferred = defer();
|
|
12336
|
-
if (!lngs) lngs = this.languages;
|
|
12337
|
-
if (!ns) ns = this.options.ns;
|
|
12338
|
-
if (!callback) callback = noop;
|
|
12339
|
-
this.services.backendConnector.reload(lngs, ns, err => {
|
|
12340
|
-
deferred.resolve();
|
|
12341
|
-
callback(err);
|
|
12342
|
-
});
|
|
12343
|
-
return deferred;
|
|
12344
|
-
}
|
|
12345
|
-
use(module) {
|
|
12346
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
12347
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
12348
|
-
if (module.type === 'backend') {
|
|
12349
|
-
this.modules.backend = module;
|
|
10068
|
+
render() {
|
|
10069
|
+
return (hAsync(Host, { key: 'c925b5b379b596db99404d6c7d4507275d70496d', class: "kol-abbr" }, hAsync("abbr", { key: 'c7a6a3482ea02fca65278aa28ea115f7a9a11f74', "aria-labelledby": this.nonce, role: "definition", tabindex: "0", title: this.state._label }, hAsync("span", { key: '7179f3b594f6815c06c46dd465739376734ea940', title: "" }, hAsync("slot", { key: '00590edd1ae4afeb4f4f066f0a16ce54c8af28a9' }))), hAsync(KolTooltipWcTag, { key: '2c44fa51a1849dabb59d0541a0d9dcc192e52bcd', _align: this.state._tooltipAlign, _id: this.nonce, _label: this.state._label })));
|
|
12350
10070
|
}
|
|
12351
|
-
|
|
12352
|
-
|
|
10071
|
+
validateLabel(value) {
|
|
10072
|
+
validateLabel(this, value, {
|
|
10073
|
+
required: true,
|
|
10074
|
+
});
|
|
12353
10075
|
}
|
|
12354
|
-
|
|
12355
|
-
|
|
10076
|
+
validateTooltipAlign(value) {
|
|
10077
|
+
validateTooltipAlign(this, value);
|
|
12356
10078
|
}
|
|
12357
|
-
|
|
12358
|
-
|
|
10079
|
+
componentWillLoad() {
|
|
10080
|
+
this.validateLabel(this._label);
|
|
10081
|
+
this.validateTooltipAlign(this._tooltipAlign);
|
|
12359
10082
|
}
|
|
12360
|
-
|
|
12361
|
-
|
|
10083
|
+
static get watchers() { return {
|
|
10084
|
+
"_label": ["validateLabel"],
|
|
10085
|
+
"_tooltipAlign": ["validateTooltipAlign"]
|
|
10086
|
+
}; }
|
|
10087
|
+
static get style() { return {
|
|
10088
|
+
default: KolAbbrDefaultStyle0
|
|
10089
|
+
}; }
|
|
10090
|
+
static get cmpMeta() { return {
|
|
10091
|
+
"$flags$": 41,
|
|
10092
|
+
"$tagName$": "kol-abbr",
|
|
10093
|
+
"$members$": {
|
|
10094
|
+
"_label": [1],
|
|
10095
|
+
"_tooltipAlign": [1, "_tooltip-align"],
|
|
10096
|
+
"state": [32]
|
|
10097
|
+
},
|
|
10098
|
+
"$listeners$": undefined,
|
|
10099
|
+
"$lazyBundleId$": "-",
|
|
10100
|
+
"$attrsToReflect$": []
|
|
10101
|
+
}; }
|
|
10102
|
+
}
|
|
10103
|
+
|
|
10104
|
+
const watchHeadingLevel = (component, value) => {
|
|
10105
|
+
watchValidator(component, '_level', (value) => {
|
|
10106
|
+
return typeof value === 'number' && headingLevelOptions.includes(value);
|
|
10107
|
+
}, new Set([`Number {${headingLevelOptions.join(', ')}`]), value, {
|
|
10108
|
+
defaultValue: 1,
|
|
10109
|
+
required: true,
|
|
10110
|
+
});
|
|
10111
|
+
};
|
|
10112
|
+
|
|
10113
|
+
const defaultStyleCss$J = "@layer kol-global {\n .sc-kol-accordion-default-h {\n \n --a11y-min-size: 44px;\n \n background-color: white;\n color: black;\n \n font-family: Verdana;\n }\n * {\n \n hyphens: auto;\n \n letter-spacing: inherit;\n \n word-break: break-word;\n \n word-spacing: inherit;\n }\n \n \n \n \n \n [role=button],\n button:not([role=link]),\n .kol-input .input {\n min-height: var(--a11y-min-size);\n min-width: var(--a11y-min-size);\n }\n \n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n \n font-family: inherit;\n \n font-size: inherit;\n }\n}\n\n/*!@.visually-hidden*/.visually-hidden.sc-kol-accordion-default {\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n height: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n}\n\n@layer kol-global {\n \n :is(a, button) {\n background-color: transparent;\n border: none;\n margin: 0;\n padding: 0;\n width: 100%; \n }\n \n [hidden] {\n display: none !important;\n }\n}\n@layer kol-global {\n .sc-kol-accordion-default-h {\n \n max-width: 100%;\n }\n * {\n \n box-sizing: border-box;\n }\n \n .kol-span-wc {\n display: grid;\n place-items: center;\n }\n \n .kol-span-wc > span {\n display: flex;\n place-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .hidden {\n display: none;\n visibility: hidden;\n }\n \n .hide-label > .kol-span-wc > span > span {\n display: none;\n }\n \n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n cursor: not-allowed;\n opacity: 0.5;\n outline: none;\n }\n [aria-disabled=true]:focus .kol-span-wc,\n [disabled]:focus .kol-span-wc {\n outline: none !important;\n }\n}\n@layer kol-component {\n .sc-kol-accordion-default-h {\n display: block;\n }\n}\n@layer kol-component {\n \n .wrapper {\n display: grid;\n grid-template-rows: 0fr;\n overflow: hidden;\n transition: grid-template-rows 0.3s;\n }\n .accordion.open .wrapper {\n grid-template-rows: 1fr;\n }\n .animation-wrapper {\n min-height: 0;\n transition: visibility 0.3s;\n \n visibility: hidden;\n }\n .accordion.open .animation-wrapper {\n visibility: visible;\n }\n @media (prefers-reduced-motion) {\n .animation-wrapper,\n .wrapper {\n transition-duration: 0s;\n }\n }\n \n @media print {\n .accordion:not(.open) .animation-wrapper {\n display: none;\n }\n }\n \n .accordion .kol-heading-wc .kol-button-wc button .kol-span-wc {\n justify-items: start;\n }\n}";
|
|
10114
|
+
var KolAccordionDefaultStyle0 = defaultStyleCss$J;
|
|
10115
|
+
|
|
10116
|
+
featureHint(`[KolAccordion] Anfrage nach einer KolAccordionGroup bei dem immer nur ein Accordion geöffnet ist.
|
|
10117
|
+
|
|
10118
|
+
- onClick auf der KolAccordion anwenden
|
|
10119
|
+
- Click-Event prüft den _open-Status der Accordions
|
|
10120
|
+
- Logik Öffnet und Schließt entsprechend`);
|
|
10121
|
+
featureHint(`[KolAccordion] Tab-Sperre des Inhalts im geschlossenen Zustand.`);
|
|
10122
|
+
class KolAccordion {
|
|
10123
|
+
constructor(hostRef) {
|
|
10124
|
+
registerInstance(this, hostRef);
|
|
10125
|
+
this.nonce = nonce();
|
|
10126
|
+
this.catchRef = (ref) => {
|
|
10127
|
+
propagateFocus(this.host, ref);
|
|
10128
|
+
};
|
|
10129
|
+
this.onClick = (event) => {
|
|
10130
|
+
this._open = !this._open;
|
|
10131
|
+
setTimeout(() => {
|
|
10132
|
+
var _a;
|
|
10133
|
+
if (typeof ((_a = this.state._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function') {
|
|
10134
|
+
this.state._on.onClick(event, this._open === true);
|
|
10135
|
+
}
|
|
10136
|
+
});
|
|
10137
|
+
};
|
|
10138
|
+
this._disabled = false;
|
|
10139
|
+
this._label = undefined;
|
|
10140
|
+
this._level = 1;
|
|
10141
|
+
this._on = undefined;
|
|
10142
|
+
this._open = false;
|
|
10143
|
+
this.state = {
|
|
10144
|
+
_label: '',
|
|
10145
|
+
_level: 1,
|
|
10146
|
+
};
|
|
12362
10147
|
}
|
|
12363
|
-
|
|
12364
|
-
|
|
10148
|
+
render() {
|
|
10149
|
+
return (hAsync(Host, { key: '375071dab3f67a8a9ea41166c5e5955a905ba04a', class: "kol-accordion" }, hAsync("div", { key: '44e8a90eed884c991797ea6e0e727777075d6d00', class: {
|
|
10150
|
+
accordion: true,
|
|
10151
|
+
disabled: this.state._disabled === true,
|
|
10152
|
+
open: this.state._open === true,
|
|
10153
|
+
} }, hAsync(KolHeadingWcTag, { key: '6fdf9427c74afbcc932fa05c1840e8cb6b606b9a', _label: "", _level: this.state._level, class: "accordion-heading" }, hAsync(KolButtonWcTag, { key: '4e82eb30cd0ff1fef25262dc0e34a3408b0aaad6', class: "accordion-button", ref: this.catchRef, slot: "expert", _ariaControls: this.nonce, _ariaExpanded: this.state._open, _disabled: this.state._disabled, _icons: this.state._open ? 'codicon codicon-remove' : 'codicon codicon-add', _label: this.state._label, _on: { onClick: this.onClick } })), hAsync("div", { key: '0835efe279a9deb62190997682ef0e8fe4a1edf2', class: "wrapper" }, hAsync("div", { key: 'f7244e8b9807223dd80f0b261ec1e2b730f95e85', class: "animation-wrapper" }, hAsync("div", { key: '4ef5849701c39fe7f738cd34661e5c0fc9f29efc', "aria-hidden": this.state._open === false ? 'true' : undefined, class: "content", id: this.nonce }, hAsync("slot", { key: '324bf4086448b8c5700c98d6fa7d830846e362af' })))))));
|
|
12365
10154
|
}
|
|
12366
|
-
|
|
12367
|
-
|
|
10155
|
+
validateDisabled(value) {
|
|
10156
|
+
validateDisabled(this, value);
|
|
12368
10157
|
}
|
|
12369
|
-
|
|
12370
|
-
|
|
12371
|
-
|
|
12372
|
-
|
|
12373
|
-
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
12374
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
12375
|
-
const lngInLngs = this.languages[li];
|
|
12376
|
-
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
12377
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
12378
|
-
this.resolvedLanguage = lngInLngs;
|
|
12379
|
-
break;
|
|
12380
|
-
}
|
|
10158
|
+
validateLabel(value) {
|
|
10159
|
+
validateLabel(this, value, {
|
|
10160
|
+
required: true,
|
|
10161
|
+
});
|
|
12381
10162
|
}
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
var _this2 = this;
|
|
12385
|
-
this.isLanguageChangingTo = lng;
|
|
12386
|
-
const deferred = defer();
|
|
12387
|
-
this.emit('languageChanging', lng);
|
|
12388
|
-
const setLngProps = l => {
|
|
12389
|
-
this.language = l;
|
|
12390
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
12391
|
-
this.resolvedLanguage = undefined;
|
|
12392
|
-
this.setResolvedLanguage(l);
|
|
12393
|
-
};
|
|
12394
|
-
const done = (err, l) => {
|
|
12395
|
-
if (l) {
|
|
12396
|
-
setLngProps(l);
|
|
12397
|
-
this.translator.changeLanguage(l);
|
|
12398
|
-
this.isLanguageChangingTo = undefined;
|
|
12399
|
-
this.emit('languageChanged', l);
|
|
12400
|
-
this.logger.log('languageChanged', l);
|
|
12401
|
-
} else {
|
|
12402
|
-
this.isLanguageChangingTo = undefined;
|
|
12403
|
-
}
|
|
12404
|
-
deferred.resolve(function () {
|
|
12405
|
-
return _this2.t(...arguments);
|
|
12406
|
-
});
|
|
12407
|
-
if (callback) callback(err, function () {
|
|
12408
|
-
return _this2.t(...arguments);
|
|
12409
|
-
});
|
|
12410
|
-
};
|
|
12411
|
-
const setLng = lngs => {
|
|
12412
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
12413
|
-
const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
12414
|
-
if (l) {
|
|
12415
|
-
if (!this.language) {
|
|
12416
|
-
setLngProps(l);
|
|
12417
|
-
}
|
|
12418
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
12419
|
-
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
12420
|
-
}
|
|
12421
|
-
this.loadResources(l, err => {
|
|
12422
|
-
done(err, l);
|
|
12423
|
-
});
|
|
12424
|
-
};
|
|
12425
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
12426
|
-
setLng(this.services.languageDetector.detect());
|
|
12427
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
12428
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
12429
|
-
this.services.languageDetector.detect().then(setLng);
|
|
12430
|
-
} else {
|
|
12431
|
-
this.services.languageDetector.detect(setLng);
|
|
12432
|
-
}
|
|
12433
|
-
} else {
|
|
12434
|
-
setLng(lng);
|
|
10163
|
+
validateLevel(value) {
|
|
10164
|
+
watchHeadingLevel(this, value);
|
|
12435
10165
|
}
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
var _this3 = this;
|
|
12440
|
-
const fixedT = function (key, opts) {
|
|
12441
|
-
let options;
|
|
12442
|
-
if (typeof opts !== 'object') {
|
|
12443
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
12444
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
10166
|
+
validateOn(value) {
|
|
10167
|
+
if (typeof value === 'object' && value !== null && typeof value.onClick === 'function') {
|
|
10168
|
+
setState(this, '_on', value);
|
|
12445
10169
|
}
|
|
12446
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
12447
|
-
} else {
|
|
12448
|
-
options = {
|
|
12449
|
-
...opts
|
|
12450
|
-
};
|
|
12451
|
-
}
|
|
12452
|
-
options.lng = options.lng || fixedT.lng;
|
|
12453
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
12454
|
-
options.ns = options.ns || fixedT.ns;
|
|
12455
|
-
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
12456
|
-
const keySeparator = _this3.options.keySeparator || '.';
|
|
12457
|
-
let resultKey;
|
|
12458
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
12459
|
-
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
12460
|
-
} else {
|
|
12461
|
-
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
12462
|
-
}
|
|
12463
|
-
return _this3.t(resultKey, options);
|
|
12464
|
-
};
|
|
12465
|
-
if (typeof lng === 'string') {
|
|
12466
|
-
fixedT.lng = lng;
|
|
12467
|
-
} else {
|
|
12468
|
-
fixedT.lngs = lng;
|
|
12469
|
-
}
|
|
12470
|
-
fixedT.ns = ns;
|
|
12471
|
-
fixedT.keyPrefix = keyPrefix;
|
|
12472
|
-
return fixedT;
|
|
12473
|
-
}
|
|
12474
|
-
t() {
|
|
12475
|
-
return this.translator && this.translator.translate(...arguments);
|
|
12476
|
-
}
|
|
12477
|
-
exists() {
|
|
12478
|
-
return this.translator && this.translator.exists(...arguments);
|
|
12479
|
-
}
|
|
12480
|
-
setDefaultNamespace(ns) {
|
|
12481
|
-
this.options.defaultNS = ns;
|
|
12482
|
-
}
|
|
12483
|
-
hasLoadedNamespace(ns) {
|
|
12484
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12485
|
-
if (!this.isInitialized) {
|
|
12486
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
12487
|
-
return false;
|
|
12488
|
-
}
|
|
12489
|
-
if (!this.languages || !this.languages.length) {
|
|
12490
|
-
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
12491
|
-
return false;
|
|
12492
|
-
}
|
|
12493
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
12494
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
12495
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
12496
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
12497
|
-
const loadNotPending = (l, n) => {
|
|
12498
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
12499
|
-
return loadState === -1 || loadState === 2;
|
|
12500
|
-
};
|
|
12501
|
-
if (options.precheck) {
|
|
12502
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
12503
|
-
if (preResult !== undefined) return preResult;
|
|
12504
10170
|
}
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
12508
|
-
return false;
|
|
12509
|
-
}
|
|
12510
|
-
loadNamespaces(ns, callback) {
|
|
12511
|
-
const deferred = defer();
|
|
12512
|
-
if (!this.options.ns) {
|
|
12513
|
-
if (callback) callback();
|
|
12514
|
-
return Promise.resolve();
|
|
10171
|
+
validateOpen(value) {
|
|
10172
|
+
validateOpen(this, value);
|
|
12515
10173
|
}
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
if (callback) callback(err);
|
|
12523
|
-
});
|
|
12524
|
-
return deferred;
|
|
12525
|
-
}
|
|
12526
|
-
loadLanguages(lngs, callback) {
|
|
12527
|
-
const deferred = defer();
|
|
12528
|
-
if (typeof lngs === 'string') lngs = [lngs];
|
|
12529
|
-
const preloaded = this.options.preload || [];
|
|
12530
|
-
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
|
|
12531
|
-
if (!newLngs.length) {
|
|
12532
|
-
if (callback) callback();
|
|
12533
|
-
return Promise.resolve();
|
|
12534
|
-
}
|
|
12535
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
12536
|
-
this.loadResources(err => {
|
|
12537
|
-
deferred.resolve();
|
|
12538
|
-
if (callback) callback(err);
|
|
12539
|
-
});
|
|
12540
|
-
return deferred;
|
|
12541
|
-
}
|
|
12542
|
-
dir(lng) {
|
|
12543
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
12544
|
-
if (!lng) return 'rtl';
|
|
12545
|
-
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'];
|
|
12546
|
-
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
12547
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
12548
|
-
}
|
|
12549
|
-
static createInstance() {
|
|
12550
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12551
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
12552
|
-
return new I18n(options, callback);
|
|
12553
|
-
}
|
|
12554
|
-
cloneInstance() {
|
|
12555
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12556
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
12557
|
-
const forkResourceStore = options.forkResourceStore;
|
|
12558
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
12559
|
-
const mergedOptions = {
|
|
12560
|
-
...this.options,
|
|
12561
|
-
...options,
|
|
12562
|
-
...{
|
|
12563
|
-
isClone: true
|
|
12564
|
-
}
|
|
12565
|
-
};
|
|
12566
|
-
const clone = new I18n(mergedOptions);
|
|
12567
|
-
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
12568
|
-
clone.logger = clone.logger.clone(options);
|
|
10174
|
+
componentWillLoad() {
|
|
10175
|
+
this.validateDisabled(this._disabled);
|
|
10176
|
+
this.validateLabel(this._label);
|
|
10177
|
+
this.validateLevel(this._level);
|
|
10178
|
+
this.validateOn(this._on);
|
|
10179
|
+
this.validateOpen(this._open);
|
|
12569
10180
|
}
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
};
|
|
12596
|
-
return clone;
|
|
12597
|
-
}
|
|
12598
|
-
toJSON() {
|
|
12599
|
-
return {
|
|
12600
|
-
options: this.options,
|
|
12601
|
-
store: this.store,
|
|
12602
|
-
language: this.language,
|
|
12603
|
-
languages: this.languages,
|
|
12604
|
-
resolvedLanguage: this.resolvedLanguage
|
|
12605
|
-
};
|
|
12606
|
-
}
|
|
10181
|
+
get host() { return getElement(this); }
|
|
10182
|
+
static get watchers() { return {
|
|
10183
|
+
"_disabled": ["validateDisabled"],
|
|
10184
|
+
"_label": ["validateLabel"],
|
|
10185
|
+
"_level": ["validateLevel"],
|
|
10186
|
+
"_on": ["validateOn"],
|
|
10187
|
+
"_open": ["validateOpen"]
|
|
10188
|
+
}; }
|
|
10189
|
+
static get style() { return {
|
|
10190
|
+
default: KolAccordionDefaultStyle0
|
|
10191
|
+
}; }
|
|
10192
|
+
static get cmpMeta() { return {
|
|
10193
|
+
"$flags$": 41,
|
|
10194
|
+
"$tagName$": "kol-accordion",
|
|
10195
|
+
"$members$": {
|
|
10196
|
+
"_disabled": [4],
|
|
10197
|
+
"_label": [1],
|
|
10198
|
+
"_level": [2],
|
|
10199
|
+
"_on": [16],
|
|
10200
|
+
"_open": [1540],
|
|
10201
|
+
"state": [32]
|
|
10202
|
+
},
|
|
10203
|
+
"$listeners$": undefined,
|
|
10204
|
+
"$lazyBundleId$": "-",
|
|
10205
|
+
"$attrsToReflect$": [["_open", "_open"]]
|
|
10206
|
+
}; }
|
|
12607
10207
|
}
|
|
12608
|
-
const instance = I18n.createInstance();
|
|
12609
|
-
instance.createInstance = I18n.createInstance;
|
|
12610
10208
|
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
10209
|
+
const defaultStyleCss$I = "@layer kol-global {\n .sc-kol-alert-default-h {\n \n --a11y-min-size: 44px;\n \n background-color: white;\n color: black;\n \n font-family: Verdana;\n }\n * {\n \n hyphens: auto;\n \n letter-spacing: inherit;\n \n word-break: break-word;\n \n word-spacing: inherit;\n }\n \n \n \n \n \n [role=button],\n button:not([role=link]),\n .kol-input .input {\n min-height: var(--a11y-min-size);\n min-width: var(--a11y-min-size);\n }\n \n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n \n font-family: inherit;\n \n font-size: inherit;\n }\n}\n\n/*!@.visually-hidden*/.visually-hidden.sc-kol-alert-default {\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n height: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n}\n\n@layer kol-global {\n \n :is(a, button) {\n background-color: transparent;\n border: none;\n margin: 0;\n padding: 0;\n width: 100%; \n }\n \n [hidden] {\n display: none !important;\n }\n}\n@layer kol-global {\n .sc-kol-alert-default-h {\n \n max-width: 100%;\n }\n * {\n \n box-sizing: border-box;\n }\n \n .kol-span-wc {\n display: grid;\n place-items: center;\n }\n \n .kol-span-wc > span {\n display: flex;\n place-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .hidden {\n display: none;\n visibility: hidden;\n }\n \n .hide-label > .kol-span-wc > span > span {\n display: none;\n }\n \n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n cursor: not-allowed;\n opacity: 0.5;\n outline: none;\n }\n [aria-disabled=true]:focus .kol-span-wc,\n [disabled]:focus .kol-span-wc {\n outline: none !important;\n }\n}\n@layer kol-component {\n .sc-kol-alert-default-h {\n display: block;\n }\n}\n@layer kol-component {\n .kol-alert-wc {\n display: grid;\n }\n .kol-alert-wc .heading {\n display: flex;\n place-items: center;\n }\n .kol-alert-wc .heading > div {\n flex-grow: 1;\n }\n .close {\n \n outline: transparent solid 1px;\n }\n}";
|
|
10210
|
+
var KolAlertDefaultStyle0 = defaultStyleCss$I;
|
|
10211
|
+
|
|
10212
|
+
class KolAlert {
|
|
10213
|
+
constructor(hostRef) {
|
|
10214
|
+
registerInstance(this, hostRef);
|
|
10215
|
+
this._alert = false;
|
|
10216
|
+
this._hasCloser = false;
|
|
10217
|
+
this._label = undefined;
|
|
10218
|
+
this._level = 1;
|
|
10219
|
+
this._on = undefined;
|
|
10220
|
+
this._type = 'default';
|
|
10221
|
+
this._variant = 'msg';
|
|
10222
|
+
this.state = {
|
|
10223
|
+
_level: 1,
|
|
10224
|
+
};
|
|
12614
10225
|
}
|
|
12615
|
-
|
|
12616
|
-
this.
|
|
10226
|
+
render() {
|
|
10227
|
+
return (hAsync(Host, { key: '0bc6af8580c2671652be185c0703d6863173054b', class: "kol-alert" }, hAsync(KolAlertWcTag, { key: '597bc59e70dd38fc02c75f93fd4bd0e18a2adc1c', _alert: this._alert, _hasCloser: this._hasCloser, _label: this._label, _level: this._level, _on: this._on, _type: this._type, _variant: this._variant }, hAsync("slot", { key: 'c3216b358f6a0dd8357009d7c95f3aa6101cc781' }))));
|
|
12617
10228
|
}
|
|
12618
|
-
static
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12629
|
-
|
|
12630
|
-
|
|
12631
|
-
|
|
12632
|
-
|
|
10229
|
+
static get style() { return {
|
|
10230
|
+
default: KolAlertDefaultStyle0
|
|
10231
|
+
}; }
|
|
10232
|
+
static get cmpMeta() { return {
|
|
10233
|
+
"$flags$": 41,
|
|
10234
|
+
"$tagName$": "kol-alert",
|
|
10235
|
+
"$members$": {
|
|
10236
|
+
"_alert": [4],
|
|
10237
|
+
"_hasCloser": [4, "_has-closer"],
|
|
10238
|
+
"_label": [1],
|
|
10239
|
+
"_level": [2],
|
|
10240
|
+
"_on": [16],
|
|
10241
|
+
"_type": [1],
|
|
10242
|
+
"_variant": [1],
|
|
10243
|
+
"state": [32]
|
|
10244
|
+
},
|
|
10245
|
+
"$listeners$": undefined,
|
|
10246
|
+
"$lazyBundleId$": "-",
|
|
10247
|
+
"$attrsToReflect$": []
|
|
10248
|
+
}; }
|
|
10249
|
+
}
|
|
10250
|
+
|
|
10251
|
+
const replaceAll = function (text, search, replacement) {
|
|
10252
|
+
return text.split(search).join(replacement);
|
|
10253
|
+
};
|
|
10254
|
+
class I18nService {
|
|
10255
|
+
constructor(initialLanguage) {
|
|
10256
|
+
this.resourceMap = new Map();
|
|
10257
|
+
this.language = initialLanguage !== null && initialLanguage !== void 0 ? initialLanguage : 'de';
|
|
12633
10258
|
}
|
|
12634
10259
|
addTranslations(translations) {
|
|
12635
10260
|
if (Array.isArray(translations)) {
|
|
@@ -12640,22 +10265,42 @@ class I18nextService {
|
|
|
12640
10265
|
}
|
|
12641
10266
|
if (translations !== undefined) {
|
|
12642
10267
|
translations.forEach((t) => t((l, t) => {
|
|
12643
|
-
|
|
10268
|
+
let resources = this.resourceMap.get(l);
|
|
10269
|
+
if (!resources) {
|
|
10270
|
+
resources = new Map();
|
|
10271
|
+
this.resourceMap.set(l, resources);
|
|
10272
|
+
}
|
|
10273
|
+
Object.entries(t).forEach(([k, v]) => {
|
|
10274
|
+
if (v) {
|
|
10275
|
+
resources.set(k, v);
|
|
10276
|
+
}
|
|
10277
|
+
});
|
|
12644
10278
|
return l;
|
|
12645
10279
|
}));
|
|
12646
10280
|
}
|
|
12647
10281
|
}
|
|
12648
|
-
|
|
12649
|
-
|
|
10282
|
+
setLanguage(lng) {
|
|
10283
|
+
this.language = lng;
|
|
12650
10284
|
}
|
|
12651
10285
|
translate(key, options) {
|
|
12652
|
-
|
|
10286
|
+
var _a;
|
|
10287
|
+
let result = (_a = this.resourceMap.get(this.language)) === null || _a === void 0 ? void 0 : _a.get(key);
|
|
10288
|
+
if (result) {
|
|
10289
|
+
if (options === null || options === void 0 ? void 0 : options.placeholders) {
|
|
10290
|
+
Object.entries(options.placeholders).forEach(([k, v]) => {
|
|
10291
|
+
result = replaceAll(result, `{{${k}}}`, v);
|
|
10292
|
+
});
|
|
10293
|
+
}
|
|
10294
|
+
}
|
|
10295
|
+
else {
|
|
10296
|
+
result = key;
|
|
10297
|
+
}
|
|
10298
|
+
return result;
|
|
12653
10299
|
}
|
|
12654
10300
|
}
|
|
12655
|
-
I18nextService.namespace = 'KoliBri';
|
|
12656
10301
|
let i18n;
|
|
12657
10302
|
const getI18nInstance = () => {
|
|
12658
|
-
if (!(i18n instanceof
|
|
10303
|
+
if (!(i18n instanceof I18nService)) {
|
|
12659
10304
|
throw new Error('i18n not initialized yet');
|
|
12660
10305
|
}
|
|
12661
10306
|
return i18n;
|
|
@@ -14915,7 +12560,7 @@ class KolInputCheckbox {
|
|
|
14915
12560
|
_icons: {
|
|
14916
12561
|
checked: 'codicon codicon-check',
|
|
14917
12562
|
indeterminate: 'codicon codicon-remove',
|
|
14918
|
-
unchecked: 'codicon codicon-
|
|
12563
|
+
unchecked: 'codicon codicon-close',
|
|
14919
12564
|
},
|
|
14920
12565
|
_id: `id-${nonce()}`,
|
|
14921
12566
|
_indeterminate: false,
|
|
@@ -30935,24 +28580,21 @@ class KolTabs {
|
|
|
30935
28580
|
return offset;
|
|
30936
28581
|
};
|
|
30937
28582
|
this.onKeyDown = (event) => {
|
|
30938
|
-
|
|
30939
|
-
|
|
30940
|
-
|
|
30941
|
-
|
|
30942
|
-
|
|
30943
|
-
|
|
30944
|
-
|
|
30945
|
-
|
|
30946
|
-
|
|
30947
|
-
|
|
30948
|
-
|
|
30949
|
-
|
|
30950
|
-
this.onSelect(event, selectedIndex, true);
|
|
30951
|
-
}
|
|
30952
|
-
}, 250);
|
|
28583
|
+
let selectedIndex = null;
|
|
28584
|
+
switch (event.key) {
|
|
28585
|
+
case 'ArrowRight':
|
|
28586
|
+
selectedIndex = this.nextPossibleTabIndex(this.state._tabs, this.state._selected, 1);
|
|
28587
|
+
break;
|
|
28588
|
+
case 'ArrowLeft':
|
|
28589
|
+
selectedIndex = this.nextPossibleTabIndex(this.state._tabs, this.state._selected, -1);
|
|
28590
|
+
break;
|
|
28591
|
+
}
|
|
28592
|
+
if (selectedIndex !== null) {
|
|
28593
|
+
this.onSelect(event, selectedIndex);
|
|
28594
|
+
}
|
|
30953
28595
|
};
|
|
30954
28596
|
this.onClickSelect = (event, index) => {
|
|
30955
|
-
this.onSelect(event, index
|
|
28597
|
+
this.onSelect(event, index);
|
|
30956
28598
|
};
|
|
30957
28599
|
this.onMouseDown = (event) => {
|
|
30958
28600
|
event.preventDefault();
|
|
@@ -31059,11 +28701,11 @@ class KolTabs {
|
|
|
31059
28701
|
} }))));
|
|
31060
28702
|
}
|
|
31061
28703
|
render() {
|
|
31062
|
-
return (hAsync(Host, { key: '
|
|
28704
|
+
return (hAsync(Host, { key: '57bc5eb1700fdd03afd712843b7c5c9995a1ef87', class: "kol-tabs" }, hAsync("div", { key: '8328b21303df5ae29a4c6070c9edfad7802e45af', ref: (el) => {
|
|
31063
28705
|
this.tabPanelsElement = el;
|
|
31064
28706
|
}, class: {
|
|
31065
28707
|
[`tabs-align-${this.state._align}`]: true,
|
|
31066
|
-
} }, this.renderButtonGroup(), hAsync("div", { key: '
|
|
28708
|
+
} }, this.renderButtonGroup(), hAsync("div", { key: '65990fd3953ff000fadb11f03dae5ad967cc5996', class: "tabs-content", ref: this.catchTabPanelHost }))));
|
|
31067
28709
|
}
|
|
31068
28710
|
validateAlign(value) {
|
|
31069
28711
|
validateAlign(this, value);
|
|
@@ -31148,20 +28790,15 @@ class KolTabs {
|
|
|
31148
28790
|
}
|
|
31149
28791
|
}
|
|
31150
28792
|
}
|
|
31151
|
-
onSelect(event, index
|
|
28793
|
+
onSelect(event, index) {
|
|
31152
28794
|
var _a, _b;
|
|
31153
28795
|
this._selected = index;
|
|
31154
28796
|
if (typeof ((_a = this._on) === null || _a === void 0 ? void 0 : _a.onSelect) === 'function') {
|
|
31155
28797
|
(_b = this._on) === null || _b === void 0 ? void 0 : _b.onSelect(event, index);
|
|
31156
28798
|
}
|
|
31157
|
-
if (
|
|
31158
|
-
|
|
31159
|
-
|
|
31160
|
-
if (this.tabPanelsElement) {
|
|
31161
|
-
const button = koliBriQuerySelector(`button#${this.state._label.replace(/\s/g, '-')}-tab-${index}`, this.tabPanelsElement);
|
|
31162
|
-
button === null || button === void 0 ? void 0 : button.focus();
|
|
31163
|
-
}
|
|
31164
|
-
}, 250);
|
|
28799
|
+
if (this.tabPanelsElement) {
|
|
28800
|
+
const button = koliBriQuerySelector(`button#${this.state._label.replace(/\s/g, '-')}-tab-${index}`, this.tabPanelsElement);
|
|
28801
|
+
button === null || button === void 0 ? void 0 : button.focus();
|
|
31165
28802
|
}
|
|
31166
28803
|
}
|
|
31167
28804
|
get host() { return getElement(this); }
|
|
@@ -31483,15 +29120,10 @@ class KolTextarea {
|
|
|
31483
29120
|
}; }
|
|
31484
29121
|
}
|
|
31485
29122
|
|
|
31486
|
-
const InternalToast = ({
|
|
31487
|
-
const handleRef = (element) => {
|
|
31488
|
-
if (typeof toastState.toast.render === 'function' && element) {
|
|
31489
|
-
toastState.toast.render(element, { close: () => onClose() });
|
|
31490
|
-
}
|
|
31491
|
-
};
|
|
29123
|
+
const InternalToast = ({ key, onClose, onRef, toastState }) => {
|
|
31492
29124
|
return (hAsync("div", { class: `toast ${toastState.status}`, key: key },
|
|
31493
29125
|
hAsync(KolAlertTag, { class: "alert", _alert: true, _label: toastState.toast.label, _level: 0, _hasCloser: true, _type: toastState.toast.type, _variant: toastState.toast.alertVariant || 'card', _on: { onClose } },
|
|
31494
|
-
hAsync("div", { ref:
|
|
29126
|
+
hAsync("div", { ref: onRef }, typeof toastState.toast.description === 'string' ? toastState.toast.description : null))));
|
|
31495
29127
|
};
|
|
31496
29128
|
|
|
31497
29129
|
const defaultStyleCss$3 = "@layer kol-component {\n .sc-kol-toast-container-default-h {\n display: flex;\n flex-direction: column;\n position: fixed;\n z-index: 200;\n }\n .close-all {\n align-self: flex-end;\n }\n}";
|
|
@@ -31501,6 +29133,7 @@ const TRANSITION_TIMEOUT = 300;
|
|
|
31501
29133
|
class KolToastContainer {
|
|
31502
29134
|
constructor(hostRef) {
|
|
31503
29135
|
registerInstance(this, hostRef);
|
|
29136
|
+
this.knownRenderFunctions = new Set();
|
|
31504
29137
|
this.state = {
|
|
31505
29138
|
_toastStates: [],
|
|
31506
29139
|
};
|
|
@@ -31537,12 +29170,18 @@ class KolToastContainer {
|
|
|
31537
29170
|
this.state = Object.assign(Object.assign({}, this.state), { _toastStates: [] });
|
|
31538
29171
|
}, TRANSITION_TIMEOUT);
|
|
31539
29172
|
}
|
|
29173
|
+
handleToastRef(toastState, element) {
|
|
29174
|
+
if (element && typeof toastState.toast.render === 'function' && !this.knownRenderFunctions.has(toastState.toast.render)) {
|
|
29175
|
+
this.knownRenderFunctions.add(toastState.toast.render);
|
|
29176
|
+
toastState.toast.render(element, { close: () => this.handleClose(toastState) });
|
|
29177
|
+
}
|
|
29178
|
+
}
|
|
31540
29179
|
render() {
|
|
31541
|
-
return (hAsync(Host, { key: '
|
|
29180
|
+
return (hAsync(Host, { key: 'f0b1a802c18178dd07acc9cf99a6db001ab321ae', class: "kol-toast-container" }, this.state._toastStates.length > 1 && (hAsync(KolButtonTag, { key: '879721d50e0dcdf7c275ed0d7e46d23eb84c453d', _label: translate('kol-toast-close-all'), class: "close-all", _on: {
|
|
31542
29181
|
onClick: () => {
|
|
31543
29182
|
void this.closeAll();
|
|
31544
29183
|
},
|
|
31545
|
-
} })), this.state._toastStates.map((toastState) => (hAsync(InternalToast, {
|
|
29184
|
+
} })), this.state._toastStates.map((toastState) => (hAsync(InternalToast, { key: toastState.id, onClose: () => this.handleClose(toastState), onRef: (element) => this.handleToastRef(toastState, element), toastState: toastState })))));
|
|
31546
29185
|
}
|
|
31547
29186
|
static get style() { return {
|
|
31548
29187
|
default: KolToastContainerDefaultStyle0
|
|
@@ -32316,8 +29955,6 @@ class ToasterService {
|
|
|
32316
29955
|
constructor(document, options) {
|
|
32317
29956
|
this.document = document;
|
|
32318
29957
|
this.options = options;
|
|
32319
|
-
console.log('create', KolToastContainerTag);
|
|
32320
|
-
console.trace();
|
|
32321
29958
|
this.toastContainerElement = this.document.createElement(KolToastContainerTag);
|
|
32322
29959
|
this.document.body.prepend(this.toastContainerElement);
|
|
32323
29960
|
}
|