@pie-element/simple-cloze 0.1.4-next.6 → 0.1.4-next.7
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/author.js +2 -0
- package/dist/author/index.d.ts +6 -0
- package/dist/author/index.js +194 -235
- package/dist/author/index.js.map +1 -1
- package/dist/browser/author/index.js +3497 -3436
- package/dist/browser/author/index.js.map +1 -1
- package/dist/browser/{client-Dt8SOe5Z.js → client-BSTc3boO.js} +650 -755
- package/dist/browser/client-BSTc3boO.js.map +1 -0
- package/dist/browser/controller/index.js +42 -32
- package/dist/browser/controller/index.js.map +1 -1
- package/dist/browser/delivery/index.js +129 -136
- package/dist/browser/delivery/index.js.map +1 -1
- package/dist/browser/dist-CYpSKy-4.js +80 -0
- package/dist/browser/dist-CYpSKy-4.js.map +1 -0
- package/dist/browser/i18n-DJMxdTMU.js +1612 -0
- package/dist/browser/i18n-DJMxdTMU.js.map +1 -0
- package/dist/browser/plain-text-iaQZhkGe.js +53 -0
- package/dist/browser/plain-text-iaQZhkGe.js.map +1 -0
- package/dist/browser/print/index.js +64 -21
- package/dist/browser/print/index.js.map +1 -1
- package/dist/controller/defaults.d.ts +1 -0
- package/dist/controller/index.d.ts +51 -8
- package/dist/controller/index.js +121 -29
- package/dist/controller/index.js.map +1 -1
- package/dist/controller/plain-text.d.ts +11 -0
- package/dist/delivery/index.d.ts +9 -4
- package/dist/delivery/index.js +2826 -267
- package/dist/delivery/index.js.map +1 -1
- package/dist/i18n.d.ts +7 -0
- package/dist/index.iife.js +9 -3
- package/dist/index.js +2826 -267
- package/dist/index.js.map +1 -1
- package/dist/print/index.d.ts +7 -0
- package/dist/print/index.js +2775 -28
- package/dist/print/index.js.map +1 -1
- package/module/print.js +2383 -600
- package/module/print.js.map +1 -1
- package/package.json +2 -1
- package/dist/browser/client-Dt8SOe5Z.js.map +0 -1
package/dist/print/index.js
CHANGED
|
@@ -18,11 +18,12 @@ var array_from = Array.from;
|
|
|
18
18
|
var object_keys = Object.keys;
|
|
19
19
|
var define_property = Object.defineProperty;
|
|
20
20
|
var get_descriptor = Object.getOwnPropertyDescriptor;
|
|
21
|
+
var get_descriptors = Object.getOwnPropertyDescriptors;
|
|
21
22
|
var object_prototype = Object.prototype;
|
|
22
23
|
var array_prototype = Array.prototype;
|
|
23
24
|
var get_prototype_of = Object.getPrototypeOf;
|
|
24
25
|
var is_extensible = Object.isExtensible;
|
|
25
|
-
var noop = () => {};
|
|
26
|
+
var noop$1 = () => {};
|
|
26
27
|
/** @param {Array<() => void>} arr */
|
|
27
28
|
function run_all(arr) {
|
|
28
29
|
for (var i = 0; i < arr.length; i++) arr[i]();
|
|
@@ -113,6 +114,7 @@ var STATE_SYMBOL = Symbol("$state");
|
|
|
113
114
|
/** Marks component export objects, so that `proxy(...)` leaves them untouched */
|
|
114
115
|
var COMPONENT_SYMBOL = Symbol("component");
|
|
115
116
|
var LEGACY_PROPS = Symbol("legacy props");
|
|
117
|
+
var LOADING_ATTR_SYMBOL = Symbol("");
|
|
116
118
|
var ATTRIBUTES_CACHE = Symbol("attributes");
|
|
117
119
|
var CLASS_CACHE = Symbol("class");
|
|
118
120
|
var STYLE_CACHE = Symbol("style");
|
|
@@ -125,7 +127,7 @@ var STALE_REACTION = new class StaleReactionError extends Error {
|
|
|
125
127
|
_defineProperty(this, "message", "The reaction that called `getAbortSignal()` was re-run or destroyed");
|
|
126
128
|
}
|
|
127
129
|
}();
|
|
128
|
-
globalThis.document?.contentType;
|
|
130
|
+
var IS_XHTML = !!globalThis.document?.contentType && /* @__PURE__ */ globalThis.document.contentType.includes("xml");
|
|
129
131
|
/**
|
|
130
132
|
* Reading a derived belonging to a now-destroyed effect may result in stale values
|
|
131
133
|
*/
|
|
@@ -705,6 +707,17 @@ function async_derived(fn, label, location) {
|
|
|
705
707
|
* @returns {Derived<V>}
|
|
706
708
|
*/
|
|
707
709
|
/*#__NO_SIDE_EFFECTS__*/
|
|
710
|
+
function user_derived(fn) {
|
|
711
|
+
const d = /* @__PURE__ */ derived(fn);
|
|
712
|
+
if (!async_mode_flag) push_reaction_value(d);
|
|
713
|
+
return d;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* @template V
|
|
717
|
+
* @param {() => V} fn
|
|
718
|
+
* @returns {Derived<V>}
|
|
719
|
+
*/
|
|
720
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
708
721
|
function derived_safe_equal(fn) {
|
|
709
722
|
const signal = /* @__PURE__ */ derived(fn);
|
|
710
723
|
signal.equals = safe_equals;
|
|
@@ -779,7 +792,7 @@ function freeze_derived_effects(derived) {
|
|
|
779
792
|
/** @type {AbortController} */ e.ac.abort(STALE_REACTION);
|
|
780
793
|
e.ac = null;
|
|
781
794
|
});
|
|
782
|
-
if (e.fn !== null) e.teardown = noop;
|
|
795
|
+
if (e.fn !== null) e.teardown = noop$1;
|
|
783
796
|
remove_reactions(e, 0);
|
|
784
797
|
destroy_effect_children(e);
|
|
785
798
|
}
|
|
@@ -1753,7 +1766,7 @@ function proxy(value) {
|
|
|
1753
1766
|
sources.set(prop, s);
|
|
1754
1767
|
}
|
|
1755
1768
|
if (s !== void 0) {
|
|
1756
|
-
var v = get(s);
|
|
1769
|
+
var v = get$1(s);
|
|
1757
1770
|
return v === UNINITIALIZED ? void 0 : v;
|
|
1758
1771
|
}
|
|
1759
1772
|
return Reflect.get(target, prop, receiver);
|
|
@@ -1762,7 +1775,7 @@ function proxy(value) {
|
|
|
1762
1775
|
var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
1763
1776
|
if (descriptor && "value" in descriptor) {
|
|
1764
1777
|
var s = sources.get(prop);
|
|
1765
|
-
if (s) descriptor.value = get(s);
|
|
1778
|
+
if (s) descriptor.value = get$1(s);
|
|
1766
1779
|
} else if (descriptor === void 0) {
|
|
1767
1780
|
var source = sources.get(prop);
|
|
1768
1781
|
var value = source?.v;
|
|
@@ -1786,7 +1799,7 @@ function proxy(value) {
|
|
|
1786
1799
|
});
|
|
1787
1800
|
sources.set(prop, s);
|
|
1788
1801
|
}
|
|
1789
|
-
if (get(s) === UNINITIALIZED) return false;
|
|
1802
|
+
if (get$1(s) === UNINITIALIZED) return false;
|
|
1790
1803
|
}
|
|
1791
1804
|
return has;
|
|
1792
1805
|
},
|
|
@@ -1825,7 +1838,7 @@ function proxy(value) {
|
|
|
1825
1838
|
return true;
|
|
1826
1839
|
},
|
|
1827
1840
|
ownKeys(target) {
|
|
1828
|
-
get(version);
|
|
1841
|
+
get$1(version);
|
|
1829
1842
|
var own_keys = Reflect.ownKeys(target).filter((key) => {
|
|
1830
1843
|
var source = sources.get(key);
|
|
1831
1844
|
return source === void 0 || source.v !== UNINITIALIZED;
|
|
@@ -1916,6 +1929,72 @@ function child(node, is_text) {
|
|
|
1916
1929
|
return child;
|
|
1917
1930
|
}
|
|
1918
1931
|
/**
|
|
1932
|
+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
1933
|
+
* @param {TemplateNode} node
|
|
1934
|
+
* @param {boolean} [is_text]
|
|
1935
|
+
* @returns {TemplateNode | null}
|
|
1936
|
+
*/
|
|
1937
|
+
function first_child(node, is_text = false) {
|
|
1938
|
+
if (!hydrating) {
|
|
1939
|
+
var first = /* @__PURE__ */ get_first_child(node);
|
|
1940
|
+
if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
|
|
1941
|
+
return first;
|
|
1942
|
+
}
|
|
1943
|
+
if (is_text) {
|
|
1944
|
+
if (hydrate_node?.nodeType !== 3) {
|
|
1945
|
+
var text = create_text();
|
|
1946
|
+
hydrate_node?.before(text);
|
|
1947
|
+
set_hydrate_node(text);
|
|
1948
|
+
return text;
|
|
1949
|
+
}
|
|
1950
|
+
merge_text_nodes(hydrate_node);
|
|
1951
|
+
}
|
|
1952
|
+
return hydrate_node;
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* `child`, for the very common case of an element with exactly one child. Resetting the
|
|
1956
|
+
* hydration cursor is part of the same step, so the compiler doesn't have to emit a
|
|
1957
|
+
* separate `reset` call for every `<p>{text}</p>` in an app.
|
|
1958
|
+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
1959
|
+
* @param {TemplateNode} node
|
|
1960
|
+
* @param {boolean} [is_text]
|
|
1961
|
+
* @returns {TemplateNode | null}
|
|
1962
|
+
*/
|
|
1963
|
+
function only_child(node, is_text = false) {
|
|
1964
|
+
if (!hydrating) return /* @__PURE__ */ get_first_child(node);
|
|
1965
|
+
var first = child(node, is_text);
|
|
1966
|
+
reset(node);
|
|
1967
|
+
return first;
|
|
1968
|
+
}
|
|
1969
|
+
/**
|
|
1970
|
+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
1971
|
+
* @param {TemplateNode} node
|
|
1972
|
+
* @param {number} count
|
|
1973
|
+
* @param {boolean} is_text
|
|
1974
|
+
* @returns {TemplateNode | null}
|
|
1975
|
+
*/
|
|
1976
|
+
function sibling(node, count = 1, is_text = false) {
|
|
1977
|
+
let next_sibling = hydrating ? hydrate_node : node;
|
|
1978
|
+
var last_sibling;
|
|
1979
|
+
while (count--) {
|
|
1980
|
+
last_sibling = next_sibling;
|
|
1981
|
+
next_sibling = /* @__PURE__ */ get_next_sibling(next_sibling);
|
|
1982
|
+
}
|
|
1983
|
+
if (!hydrating) return next_sibling;
|
|
1984
|
+
if (is_text) {
|
|
1985
|
+
if (next_sibling?.nodeType !== 3) {
|
|
1986
|
+
var text = create_text();
|
|
1987
|
+
if (next_sibling === null) last_sibling?.after(text);
|
|
1988
|
+
else next_sibling.before(text);
|
|
1989
|
+
set_hydrate_node(text);
|
|
1990
|
+
return text;
|
|
1991
|
+
}
|
|
1992
|
+
merge_text_nodes(next_sibling);
|
|
1993
|
+
}
|
|
1994
|
+
set_hydrate_node(next_sibling);
|
|
1995
|
+
return next_sibling;
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1919
1998
|
* @template {Node} N
|
|
1920
1999
|
* @param {N} node
|
|
1921
2000
|
* @returns {void}
|
|
@@ -2172,7 +2251,7 @@ function render_effect(fn, flags = 0) {
|
|
|
2172
2251
|
function template_effect(fn, sync = [], async = [], blockers = []) {
|
|
2173
2252
|
flatten(blockers, sync, async, (values) => {
|
|
2174
2253
|
create_effect(8, () => {
|
|
2175
|
-
fn(...values.map(get));
|
|
2254
|
+
fn(...values.map(get$1));
|
|
2176
2255
|
});
|
|
2177
2256
|
});
|
|
2178
2257
|
}
|
|
@@ -2657,7 +2736,7 @@ function update_effect(effect) {
|
|
|
2657
2736
|
* @param {Value<V>} signal
|
|
2658
2737
|
* @returns {V}
|
|
2659
2738
|
*/
|
|
2660
|
-
function get(signal) {
|
|
2739
|
+
function get$1(signal) {
|
|
2661
2740
|
var is_derived = (signal.f & 2) !== 0;
|
|
2662
2741
|
captured_signals?.add(signal);
|
|
2663
2742
|
if (active_reaction !== null && !untracking) {
|
|
@@ -3004,7 +3083,7 @@ function createSubscriber(start) {
|
|
|
3004
3083
|
let stop;
|
|
3005
3084
|
return () => {
|
|
3006
3085
|
if (effect_tracking()) {
|
|
3007
|
-
get(version);
|
|
3086
|
+
get$1(version);
|
|
3008
3087
|
render_effect(() => {
|
|
3009
3088
|
if (subscribers === 0) stop = untrack(() => start(() => increment(version)));
|
|
3010
3089
|
subscribers += 1;
|
|
@@ -3167,7 +3246,7 @@ var Boundary = class {
|
|
|
3167
3246
|
}
|
|
3168
3247
|
get_effect_pending() {
|
|
3169
3248
|
_classPrivateFieldGet2(_effect_pending_subscriber, this).call(this);
|
|
3170
|
-
return get(_classPrivateFieldGet2(_effect_pending, this));
|
|
3249
|
+
return get$1(_classPrivateFieldGet2(_effect_pending, this));
|
|
3171
3250
|
}
|
|
3172
3251
|
/** @param {unknown} error */
|
|
3173
3252
|
error(error) {
|
|
@@ -3406,6 +3485,18 @@ function _handle_error(error) {
|
|
|
3406
3485
|
});
|
|
3407
3486
|
}
|
|
3408
3487
|
/**
|
|
3488
|
+
* @param {Element} text
|
|
3489
|
+
* @param {string} value
|
|
3490
|
+
* @returns {void}
|
|
3491
|
+
*/
|
|
3492
|
+
function set_text(text, value) {
|
|
3493
|
+
var str = value == null ? "" : typeof value === "object" ? `${value}` : value;
|
|
3494
|
+
if (str !== (text[TEXT_CACHE] ?? (text[TEXT_CACHE] = text.nodeValue))) {
|
|
3495
|
+
/** @type {any} */ text[TEXT_CACHE] = str;
|
|
3496
|
+
text.nodeValue = `${str}`;
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
/**
|
|
3409
3500
|
* Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component.
|
|
3410
3501
|
* Transitions will play during the initial render unless the `intro` option is set to `false`.
|
|
3411
3502
|
*
|
|
@@ -3829,6 +3920,61 @@ function append_styles(anchor, css) {
|
|
|
3829
3920
|
});
|
|
3830
3921
|
}
|
|
3831
3922
|
//#endregion
|
|
3923
|
+
//#region ../../../node_modules/.bun/svelte@5.57.0/node_modules/svelte/src/internal/client/dom/elements/attributes.js
|
|
3924
|
+
/** @import { Blocker, Effect } from '#client' */
|
|
3925
|
+
var IS_CUSTOM_ELEMENT = Symbol("is custom element");
|
|
3926
|
+
var IS_HTML = Symbol("is html");
|
|
3927
|
+
var LINK_TAG = IS_XHTML ? "link" : "LINK";
|
|
3928
|
+
/**
|
|
3929
|
+
* @param {Element} element
|
|
3930
|
+
* @param {string} attribute
|
|
3931
|
+
* @param {string | null} value
|
|
3932
|
+
* @param {boolean} [skip_warning]
|
|
3933
|
+
*/
|
|
3934
|
+
function set_attribute(element, attribute, value, skip_warning) {
|
|
3935
|
+
var attributes = get_attributes(element);
|
|
3936
|
+
if (hydrating) {
|
|
3937
|
+
attributes[attribute] = element.getAttribute(attribute);
|
|
3938
|
+
if (attribute === "src" || attribute === "srcset" || attribute === "href" && element.nodeName === LINK_TAG) {
|
|
3939
|
+
if (!skip_warning);
|
|
3940
|
+
return;
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3943
|
+
if (attributes[attribute] === (attributes[attribute] = value)) return;
|
|
3944
|
+
if (attribute === "loading") element[LOADING_ATTR_SYMBOL] = value;
|
|
3945
|
+
if (value == null) element.removeAttribute(attribute);
|
|
3946
|
+
else if (typeof value !== "string" && get_setters(element).has(attribute)) element[attribute] = value;
|
|
3947
|
+
else element.setAttribute(attribute, value);
|
|
3948
|
+
}
|
|
3949
|
+
/**
|
|
3950
|
+
*
|
|
3951
|
+
* @param {Element} element
|
|
3952
|
+
*/
|
|
3953
|
+
function get_attributes(element) {
|
|
3954
|
+
return element[ATTRIBUTES_CACHE] ?? (element[ATTRIBUTES_CACHE] = {
|
|
3955
|
+
[IS_CUSTOM_ELEMENT]: element.nodeName.includes("-"),
|
|
3956
|
+
[IS_HTML]: element.namespaceURI === "http://www.w3.org/1999/xhtml"
|
|
3957
|
+
});
|
|
3958
|
+
}
|
|
3959
|
+
/** @type {Map<string, Set<string>>} */
|
|
3960
|
+
var setters_cache = /* @__PURE__ */ new Map();
|
|
3961
|
+
/** @param {Element} element */
|
|
3962
|
+
function get_setters(element) {
|
|
3963
|
+
var cache_key = element.getAttribute("is") || element.nodeName;
|
|
3964
|
+
var setters = setters_cache.get(cache_key);
|
|
3965
|
+
if (setters) return setters;
|
|
3966
|
+
setters_cache.set(cache_key, setters = /* @__PURE__ */ new Set());
|
|
3967
|
+
var descriptors;
|
|
3968
|
+
var proto = element;
|
|
3969
|
+
var element_proto = Element.prototype;
|
|
3970
|
+
while (element_proto !== proto) {
|
|
3971
|
+
descriptors = get_descriptors(proto);
|
|
3972
|
+
for (var key in descriptors) if (descriptors[key].set && key !== "innerHTML" && key !== "textContent" && key !== "innerText") setters.add(key);
|
|
3973
|
+
proto = get_prototype_of(proto);
|
|
3974
|
+
}
|
|
3975
|
+
return setters;
|
|
3976
|
+
}
|
|
3977
|
+
//#endregion
|
|
3832
3978
|
//#region ../../../node_modules/.bun/svelte@5.57.0/node_modules/svelte/src/internal/client/dom/elements/bindings/size.js
|
|
3833
3979
|
var _ResizeObserverSingleton;
|
|
3834
3980
|
var _listeners = /* @__PURE__ */ new WeakMap();
|
|
@@ -3881,6 +4027,58 @@ function _getObserver() {
|
|
|
3881
4027
|
}
|
|
3882
4028
|
_defineProperty(ResizeObserverSingleton, "entries", /* @__PURE__ */ new WeakMap());
|
|
3883
4029
|
//#endregion
|
|
4030
|
+
//#region ../../../node_modules/.bun/svelte@5.57.0/node_modules/svelte/src/internal/client/dom/elements/bindings/this.js
|
|
4031
|
+
/** @import { ComponentContext, Effect } from '#client' */
|
|
4032
|
+
/**
|
|
4033
|
+
* @param {any} bound_value
|
|
4034
|
+
* @param {Element} element_or_component
|
|
4035
|
+
* @returns {boolean}
|
|
4036
|
+
*/
|
|
4037
|
+
function is_bound_this(bound_value, element_or_component) {
|
|
4038
|
+
return bound_value === element_or_component || bound_value?.[STATE_SYMBOL] === element_or_component;
|
|
4039
|
+
}
|
|
4040
|
+
/**
|
|
4041
|
+
* @param {any} element_or_component
|
|
4042
|
+
* @param {(value: unknown, ...parts: unknown[]) => void} update
|
|
4043
|
+
* @param {(...parts: unknown[]) => unknown} get_value
|
|
4044
|
+
* @param {() => unknown[]} [get_parts] Set if the this binding is used inside an each block,
|
|
4045
|
+
* returns all the parts of the each block context that are used in the expression
|
|
4046
|
+
* @returns {void}
|
|
4047
|
+
*/
|
|
4048
|
+
function bind_this(element_or_component = mark_as_component(), update, get_value, get_parts) {
|
|
4049
|
+
var component_effect = component_context.r;
|
|
4050
|
+
var parent = active_effect;
|
|
4051
|
+
effect(() => {
|
|
4052
|
+
/** @type {unknown[]} */
|
|
4053
|
+
var old_parts;
|
|
4054
|
+
/** @type {unknown[]} */
|
|
4055
|
+
var parts;
|
|
4056
|
+
render_effect(() => {
|
|
4057
|
+
old_parts = parts;
|
|
4058
|
+
parts = get_parts?.() || [];
|
|
4059
|
+
untrack(() => {
|
|
4060
|
+
if (!is_bound_this(get_value(...parts), element_or_component)) {
|
|
4061
|
+
update(element_or_component, ...parts);
|
|
4062
|
+
if (old_parts && is_bound_this(get_value(...old_parts), element_or_component)) update(null, ...old_parts);
|
|
4063
|
+
}
|
|
4064
|
+
});
|
|
4065
|
+
});
|
|
4066
|
+
return () => {
|
|
4067
|
+
let p = parent;
|
|
4068
|
+
while (p !== component_effect && p.parent !== null && p.parent.f & 33554432) p = p.parent;
|
|
4069
|
+
const teardown = () => {
|
|
4070
|
+
if (parts && is_bound_this(get_value(...parts), element_or_component)) update(null, ...parts);
|
|
4071
|
+
};
|
|
4072
|
+
const original_teardown = p.teardown;
|
|
4073
|
+
p.teardown = () => {
|
|
4074
|
+
teardown();
|
|
4075
|
+
original_teardown?.();
|
|
4076
|
+
};
|
|
4077
|
+
};
|
|
4078
|
+
});
|
|
4079
|
+
return element_or_component;
|
|
4080
|
+
}
|
|
4081
|
+
//#endregion
|
|
3884
4082
|
//#region ../../../node_modules/.bun/svelte@5.57.0/node_modules/svelte/src/internal/client/reactivity/props.js
|
|
3885
4083
|
/** @import { Derived, Effect, Source } from './types.js' */
|
|
3886
4084
|
/**
|
|
@@ -3903,7 +4101,7 @@ function prop(props, key, flags, fallback) {
|
|
|
3903
4101
|
var get_fallback = () => {
|
|
3904
4102
|
if (lazy && runes) {
|
|
3905
4103
|
fallback_signal ?? (fallback_signal = /* @__PURE__ */ derived(fallback));
|
|
3906
|
-
return get(fallback_signal);
|
|
4104
|
+
return get$1(fallback_signal);
|
|
3907
4105
|
}
|
|
3908
4106
|
if (fallback_dirty) {
|
|
3909
4107
|
fallback_dirty = false;
|
|
@@ -3959,18 +4157,18 @@ function prop(props, key, flags, fallback) {
|
|
|
3959
4157
|
overridden = false;
|
|
3960
4158
|
return getter();
|
|
3961
4159
|
});
|
|
3962
|
-
if (bindable) get(d);
|
|
4160
|
+
if (bindable) get$1(d);
|
|
3963
4161
|
var parent_effect = active_effect;
|
|
3964
4162
|
return (function(value, mutation) {
|
|
3965
4163
|
if (arguments.length > 0) {
|
|
3966
|
-
const new_value = mutation ? get(d) : runes && bindable ? proxy(value) : value;
|
|
4164
|
+
const new_value = mutation ? get$1(d) : runes && bindable ? proxy(value) : value;
|
|
3967
4165
|
set(d, new_value);
|
|
3968
4166
|
overridden = true;
|
|
3969
4167
|
if (fallback_value !== void 0) fallback_value = new_value;
|
|
3970
4168
|
return value;
|
|
3971
4169
|
}
|
|
3972
4170
|
if (is_destroying_effect && overridden || (parent_effect.f & 16384) !== 0) return d.v;
|
|
3973
|
-
return get(d);
|
|
4171
|
+
return get$1(d);
|
|
3974
4172
|
});
|
|
3975
4173
|
}
|
|
3976
4174
|
//#endregion
|
|
@@ -4024,11 +4222,11 @@ var Svelte4Component = class {
|
|
|
4024
4222
|
$$events: {}
|
|
4025
4223
|
}, {
|
|
4026
4224
|
get(target, prop) {
|
|
4027
|
-
return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
4225
|
+
return get$1(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
4028
4226
|
},
|
|
4029
4227
|
has(target, prop) {
|
|
4030
4228
|
if (prop === LEGACY_PROPS) return true;
|
|
4031
|
-
get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
4229
|
+
get$1(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
4032
4230
|
return Reflect.has(target, prop);
|
|
4033
4231
|
},
|
|
4034
4232
|
set(target, prop, value) {
|
|
@@ -4378,20 +4576,2514 @@ function create_custom_element(Component, props_definition, slots, exports, shad
|
|
|
4378
4576
|
return Class;
|
|
4379
4577
|
}
|
|
4380
4578
|
//#endregion
|
|
4579
|
+
//#region ../../shared/math-rendering-mathjax/dist/index.js
|
|
4580
|
+
var e$2 = null;
|
|
4581
|
+
function t$2(t) {
|
|
4582
|
+
return typeof window > "u" || window.MathJax?.typesetPromise ? Promise.resolve() : e$2 || (e$2 = new Promise((e, n) => {
|
|
4583
|
+
let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: a = !0, srcUrl: o } = t, s = {
|
|
4584
|
+
loader: { load: i ? ["a11y/assistive-mml"] : [] },
|
|
4585
|
+
tex: {
|
|
4586
|
+
packages: [
|
|
4587
|
+
"base",
|
|
4588
|
+
"ams",
|
|
4589
|
+
"autoload"
|
|
4590
|
+
],
|
|
4591
|
+
macros: {
|
|
4592
|
+
parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
|
|
4593
|
+
overarc: "\\overparen",
|
|
4594
|
+
napprox: "\\not\\approx",
|
|
4595
|
+
longdiv: "\\enclose{longdiv}"
|
|
4596
|
+
}
|
|
4597
|
+
},
|
|
4598
|
+
options: {
|
|
4599
|
+
enableMenu: i,
|
|
4600
|
+
enableExplorer: i,
|
|
4601
|
+
enableAssistiveMml: i
|
|
4602
|
+
},
|
|
4603
|
+
startup: {
|
|
4604
|
+
ready: () => {
|
|
4605
|
+
window.MathJax?.startup.defaultReady && (window.MathJax.startup.defaultReady(), e());
|
|
4606
|
+
},
|
|
4607
|
+
defaultReady: () => {}
|
|
4608
|
+
}
|
|
4609
|
+
};
|
|
4610
|
+
r && s.tex && (s.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], s.tex.processEscapes = !0), a || (s.chtml = { fontURL: "" }), window.MathJax = s;
|
|
4611
|
+
let c = document.createElement("script");
|
|
4612
|
+
c.src = o || "https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js", c.async = !0, c.onload = () => {
|
|
4613
|
+
setTimeout(e, 100);
|
|
4614
|
+
}, c.onerror = () => {
|
|
4615
|
+
n(/* @__PURE__ */ Error("Failed to load MathJax"));
|
|
4616
|
+
}, document.head.appendChild(c);
|
|
4617
|
+
}), e$2);
|
|
4618
|
+
}
|
|
4619
|
+
function n() {
|
|
4620
|
+
let e = window.MathJax?.startup?.document;
|
|
4621
|
+
if (typeof e?.assistiveMml == "function") try {
|
|
4622
|
+
e.assistiveMml().updateDocument?.();
|
|
4623
|
+
} catch (e) {
|
|
4624
|
+
console.warn("[mathjax-renderer] Failed to attach assistive MathML:", e);
|
|
4625
|
+
}
|
|
4626
|
+
}
|
|
4627
|
+
function r$1(e = {}) {
|
|
4628
|
+
return async (r) => {
|
|
4629
|
+
if (await t$2(e), !window.MathJax?.typesetPromise) {
|
|
4630
|
+
console.warn("[mathjax-renderer] MathJax not loaded or missing typesetPromise.");
|
|
4631
|
+
return;
|
|
4632
|
+
}
|
|
4633
|
+
await window.MathJax.typesetPromise([r]), n();
|
|
4634
|
+
};
|
|
4635
|
+
}
|
|
4636
|
+
var a = null;
|
|
4637
|
+
function o() {
|
|
4638
|
+
return a || (a = r$1({
|
|
4639
|
+
accessibility: !0,
|
|
4640
|
+
useSingleDollar: !0
|
|
4641
|
+
})), a;
|
|
4642
|
+
}
|
|
4643
|
+
function s() {
|
|
4644
|
+
if (typeof window > "u") return null;
|
|
4645
|
+
let e = window["@pie-lib/math-rendering"];
|
|
4646
|
+
return typeof e?.renderMath == "function" ? e : null;
|
|
4647
|
+
}
|
|
4648
|
+
var c = async (e) => {
|
|
4649
|
+
if (typeof window > "u") return;
|
|
4650
|
+
let t = typeof e == "string", n;
|
|
4651
|
+
t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
|
|
4652
|
+
let r = s();
|
|
4653
|
+
return r ? await r.renderMath?.(n) : await o()(n), t ? n.innerHTML : void 0;
|
|
4654
|
+
};
|
|
4655
|
+
//#endregion
|
|
4656
|
+
//#region src/controller/plain-text.ts
|
|
4657
|
+
/**
|
|
4658
|
+
* The text an HTML fragment reads as, computed without a DOM because
|
|
4659
|
+
* controllers also run server-side. An answer key authored in an editor is HTML
|
|
4660
|
+
* (`<p>Salt & pepper</p>`) while the learner types plain text.
|
|
4661
|
+
*/
|
|
4662
|
+
var LATIN_1 = [
|
|
4663
|
+
"nbsp iexcl cent pound curren yen brvbar sect uml copy ordf laquo not shy reg macr",
|
|
4664
|
+
"deg plusmn sup2 sup3 acute micro para middot cedil sup1 ordm raquo frac14 frac12 frac34 iquest",
|
|
4665
|
+
"Agrave Aacute Acirc Atilde Auml Aring AElig Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml",
|
|
4666
|
+
"ETH Ntilde Ograve Oacute Ocirc Otilde Ouml times Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig",
|
|
4667
|
+
"agrave aacute acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute icirc iuml",
|
|
4668
|
+
"eth ntilde ograve oacute ocirc otilde ouml divide oslash ugrave uacute ucirc uuml yacute thorn yuml"
|
|
4669
|
+
].join(" ");
|
|
4670
|
+
var GREEK = "alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu nu xi omicron pi rho sigmaf sigma tau upsilon phi chi psi omega";
|
|
4671
|
+
var NAMED = new Map(Object.entries({
|
|
4672
|
+
quot: 34,
|
|
4673
|
+
amp: 38,
|
|
4674
|
+
apos: 39,
|
|
4675
|
+
lt: 60,
|
|
4676
|
+
gt: 62,
|
|
4677
|
+
ensp: 8194,
|
|
4678
|
+
emsp: 8195,
|
|
4679
|
+
thinsp: 8201,
|
|
4680
|
+
ndash: 8211,
|
|
4681
|
+
mdash: 8212,
|
|
4682
|
+
lsquo: 8216,
|
|
4683
|
+
rsquo: 8217,
|
|
4684
|
+
sbquo: 8218,
|
|
4685
|
+
ldquo: 8220,
|
|
4686
|
+
rdquo: 8221,
|
|
4687
|
+
bdquo: 8222,
|
|
4688
|
+
bull: 8226,
|
|
4689
|
+
hellip: 8230,
|
|
4690
|
+
prime: 8242,
|
|
4691
|
+
Prime: 8243,
|
|
4692
|
+
euro: 8364,
|
|
4693
|
+
trade: 8482,
|
|
4694
|
+
minus: 8722,
|
|
4695
|
+
radic: 8730,
|
|
4696
|
+
infin: 8734,
|
|
4697
|
+
asymp: 8776,
|
|
4698
|
+
ne: 8800,
|
|
4699
|
+
le: 8804,
|
|
4700
|
+
ge: 8805
|
|
4701
|
+
}));
|
|
4702
|
+
for (const [i, name] of LATIN_1.split(" ").entries()) NAMED.set(name, 160 + i);
|
|
4703
|
+
for (const [i, name] of GREEK.split(" ").entries()) {
|
|
4704
|
+
NAMED.set(name, 945 + i);
|
|
4705
|
+
if (name !== "sigmaf") NAMED.set(name[0].toUpperCase() + name.slice(1), 913 + i);
|
|
4706
|
+
}
|
|
4707
|
+
var BLOCK_BOUNDARY = /<\/?(?:br|p|div|li|h[1-6]|blockquote|pre|tr|td|th)\b[^>]*>/gi;
|
|
4708
|
+
var TAG = /<\/?[a-z][^>]*>|<!--[\s\S]*?-->/gi;
|
|
4709
|
+
var ENTITY = /&(#[0-9]+|#x[0-9a-f]+|[a-z][a-z0-9]*);/gi;
|
|
4710
|
+
var decodeEntity = (match, body) => {
|
|
4711
|
+
if (body[0] === "#") {
|
|
4712
|
+
const hex = body[1] === "x" || body[1] === "X";
|
|
4713
|
+
const code = Number.parseInt(body.slice(hex ? 2 : 1), hex ? 16 : 10);
|
|
4714
|
+
const valid = code > 0 && code <= 1114111 && (code < 55296 || code > 57343);
|
|
4715
|
+
return String.fromCodePoint(valid ? code : 65533);
|
|
4716
|
+
}
|
|
4717
|
+
const code = NAMED.get(body);
|
|
4718
|
+
return code === void 0 ? match : String.fromCodePoint(code);
|
|
4719
|
+
};
|
|
4720
|
+
/**
|
|
4721
|
+
* Tags stripped, entities decoded (named and numeric), and each run of
|
|
4722
|
+
* whitespace, ` ` included, collapsed to one space and trimmed. An unknown
|
|
4723
|
+
* named entity stays as written.
|
|
4724
|
+
*/
|
|
4725
|
+
var toPlainText = (value) => typeof value === "string" ? value.replace(BLOCK_BOUNDARY, " ").replace(TAG, "").replace(ENTITY, decodeEntity).replace(/\s+/g, " ").trim() : "";
|
|
4726
|
+
//#endregion
|
|
4727
|
+
//#region ../../shared/translator/dist/en.js
|
|
4728
|
+
var e$1 = {
|
|
4729
|
+
translation: {
|
|
4730
|
+
categorize: {
|
|
4731
|
+
limitMaxChoicesPerCategory: "You've reached the limit of {{maxChoicesPerCategory}} responses per area. To add another response, one must first be removed.",
|
|
4732
|
+
maxChoicesPerCategoryRestriction: "To change this value to {{maxChoicesPerCategory}}, each category must have {{maxChoicesPerCategory}} or fewer answer choice[s]."
|
|
4733
|
+
},
|
|
4734
|
+
ebsr: { part: "Part {{index}}" },
|
|
4735
|
+
numberLine: {
|
|
4736
|
+
addElementLimit_one: "You can only add {{count}} element",
|
|
4737
|
+
addElementLimit_other: "You can only add {{count}} elements",
|
|
4738
|
+
clearAll: "Clear all"
|
|
4739
|
+
},
|
|
4740
|
+
imageClozeAssociation: {
|
|
4741
|
+
reachedLimit_one: "You’ve reached the limit of {{count}} response per area. To add another response, one must first be removed.",
|
|
4742
|
+
reachedLimit_other: "Full"
|
|
4743
|
+
},
|
|
4744
|
+
drawingResponse: {
|
|
4745
|
+
fillColor: "Fill color",
|
|
4746
|
+
outlineColor: "Outline color",
|
|
4747
|
+
noFill: "No fill",
|
|
4748
|
+
lightblue: "Light blue",
|
|
4749
|
+
lightyellow: "Light yellow",
|
|
4750
|
+
red: "Red",
|
|
4751
|
+
orange: "Orange",
|
|
4752
|
+
yellow: "Yellow",
|
|
4753
|
+
violet: "Violet",
|
|
4754
|
+
blue: "Blue",
|
|
4755
|
+
green: "Green",
|
|
4756
|
+
white: "White",
|
|
4757
|
+
black: "Black",
|
|
4758
|
+
onDoubleClick: "Double click to edit this text. Press Enter to submit."
|
|
4759
|
+
},
|
|
4760
|
+
charting: {
|
|
4761
|
+
addCategory: "Add category",
|
|
4762
|
+
actions: "Actions",
|
|
4763
|
+
add: "Add",
|
|
4764
|
+
delete: "Delete",
|
|
4765
|
+
newLabel: "New label",
|
|
4766
|
+
reachedLimit_other: "There can't be more than {{count}} categories.",
|
|
4767
|
+
keyLegend: {
|
|
4768
|
+
incorrectAnswer: "Student incorrect answer",
|
|
4769
|
+
correctAnswer: "Student correct answer",
|
|
4770
|
+
correctKeyAnswer: "Answer key correct"
|
|
4771
|
+
}
|
|
4772
|
+
},
|
|
4773
|
+
graphing: {
|
|
4774
|
+
point: "Point",
|
|
4775
|
+
circle: "Circle",
|
|
4776
|
+
line: "Line",
|
|
4777
|
+
parabola: "Parabola",
|
|
4778
|
+
absolute: "Absolute Value",
|
|
4779
|
+
exponential: "Exponential",
|
|
4780
|
+
polygon: "Polygon",
|
|
4781
|
+
ray: "Ray",
|
|
4782
|
+
segment: "Segment",
|
|
4783
|
+
sine: "Sine",
|
|
4784
|
+
vector: "Vector",
|
|
4785
|
+
label: "Label",
|
|
4786
|
+
redo: "Redo",
|
|
4787
|
+
reset: "Reset"
|
|
4788
|
+
},
|
|
4789
|
+
mathInline: { primaryCorrectWithAlternates: "Note: The answer shown above is the primary correct answer specified by the author for this item, but other answers may also be recognized as correct." },
|
|
4790
|
+
mcPopulatedBlank: {
|
|
4791
|
+
answerChoices: "Answer choices",
|
|
4792
|
+
blankLabel: "blank",
|
|
4793
|
+
emptyBlank: "(blank)",
|
|
4794
|
+
blankPreSelectionHint: "The answer you choose will appear on the blank line above.",
|
|
4795
|
+
correctAnswerSelected: "Correct answer selected",
|
|
4796
|
+
incorrectAnswerSelected: "Incorrect answer selected",
|
|
4797
|
+
selectedAnswerImage: "Selected answer image",
|
|
4798
|
+
choiceImage: "Choice {{id}}",
|
|
4799
|
+
clickToEnableAutoplay: "Click to enable audio autoplay",
|
|
4800
|
+
audioResourceUnavailable: "Audio is enabled but no playable audio URL is configured.",
|
|
4801
|
+
listen: "Listen",
|
|
4802
|
+
listenSilentAlt: "Repeat instructions",
|
|
4803
|
+
listenPlayingAlt: "Instructions are playing",
|
|
4804
|
+
printAudio: "Audio:",
|
|
4805
|
+
printTranscript: "Transcript:",
|
|
4806
|
+
printKey: "(key)"
|
|
4807
|
+
},
|
|
4808
|
+
multipleChoice: {
|
|
4809
|
+
minSelections: "Select at least {{minSelections}}.",
|
|
4810
|
+
maxSelections_one: "Only {{maxSelections}} answer is allowed.",
|
|
4811
|
+
maxSelections_other: "Only {{maxSelections}} answers are allowed.",
|
|
4812
|
+
minmaxSelections_equal: "Select {{minSelections}}.",
|
|
4813
|
+
minmaxSelections_range: "Select between {{minSelections}} and {{maxSelections}}."
|
|
4814
|
+
},
|
|
4815
|
+
selectText: {
|
|
4816
|
+
correctAnswerSelected: "Correct",
|
|
4817
|
+
correctAnswerNotSelected: "Correct Answer Not Selected",
|
|
4818
|
+
incorrectSelection: "Incorrect Selection",
|
|
4819
|
+
key: "Key"
|
|
4820
|
+
},
|
|
4821
|
+
simpleCloze: {
|
|
4822
|
+
correctAnswerShown: "Correct answer",
|
|
4823
|
+
correct: "Correct",
|
|
4824
|
+
incorrect: "Incorrect",
|
|
4825
|
+
unanswered: "No answer",
|
|
4826
|
+
placeholder: "Enter your answer...",
|
|
4827
|
+
answerInput: "Your answer",
|
|
4828
|
+
printCorrectAnswer: "Correct answer:",
|
|
4829
|
+
printAnswerBlank: "Answer blank"
|
|
4830
|
+
},
|
|
4831
|
+
vennClassification: {
|
|
4832
|
+
tray: "Tiles to classify",
|
|
4833
|
+
unknownTarget: "unknown",
|
|
4834
|
+
cancelled: "Cancelled",
|
|
4835
|
+
returnedToTray: "{{name}} returned to tray",
|
|
4836
|
+
placedIn: "{{name}} placed in {{target}}",
|
|
4837
|
+
pickedUp: "Picked up {{name}}",
|
|
4838
|
+
pickedUpWithKeyboard: "Picked up {{name}}, drop target: {{target}}. Use arrow keys to choose a drop target, Enter to drop, Escape to cancel.",
|
|
4839
|
+
dropTarget: "Drop target: {{target}}",
|
|
4840
|
+
unsupportedCircles_one: "This diagram cannot be shown: it has {{count}} circle, and only {{supported}} are supported.",
|
|
4841
|
+
unsupportedCircles_other: "This diagram cannot be shown: it has {{count}} circles, and only {{supported}} are supported.",
|
|
4842
|
+
setNumber: "Set {{number}}",
|
|
4843
|
+
regionOnly: "{{set}} only",
|
|
4844
|
+
regionNeither: "Neither {{first}} nor {{second}}",
|
|
4845
|
+
regionNoneOf: "None of {{sets}}",
|
|
4846
|
+
regionAndSeparator: " and ",
|
|
4847
|
+
tileFallbackName: "Tile",
|
|
4848
|
+
tileNotPlaced: "not placed",
|
|
4849
|
+
tileInRegion: "in {{region}}",
|
|
4850
|
+
tileCorrect: "correct",
|
|
4851
|
+
tileIncorrect: "incorrect"
|
|
4852
|
+
}
|
|
4853
|
+
},
|
|
4854
|
+
common: {
|
|
4855
|
+
undo: "Undo",
|
|
4856
|
+
clearAll: "Clear all",
|
|
4857
|
+
correct: "Correct",
|
|
4858
|
+
incorrect: "Incorrect",
|
|
4859
|
+
showCorrectAnswer: "Show correct answer",
|
|
4860
|
+
hideCorrectAnswer: "Hide correct answer",
|
|
4861
|
+
showTeacherInstructions: "Show Teacher Instructions",
|
|
4862
|
+
hideTeacherInstructions: "Hide Teacher Instructions",
|
|
4863
|
+
commonCorrectAnswerWithAlternates: "Note: The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.",
|
|
4864
|
+
warning: "Warning",
|
|
4865
|
+
showNote: "Show Note",
|
|
4866
|
+
hideNote: "Hide Note",
|
|
4867
|
+
cancel: "Cancel"
|
|
4868
|
+
}
|
|
4869
|
+
};
|
|
4870
|
+
//#endregion
|
|
4871
|
+
//#region ../../shared/translator/dist/es.js
|
|
4872
|
+
var e = {
|
|
4873
|
+
translation: {
|
|
4874
|
+
categorize: {
|
|
4875
|
+
limitMaxChoicesPerCategory: "Has alcanzado el límite de {{maxChoicesPerCategory}} respuestas por área. Para agregar otra respuesta, primero se debe eliminar una respuesta.",
|
|
4876
|
+
maxChoicesPerCategoryRestriction: "Para cambiar este valor a {{maxChoicesPerCategory}}, cada categoría debe tener {{maxChoicesPerCategory}} o menos opciones de respuesta"
|
|
4877
|
+
},
|
|
4878
|
+
ebsr: { part: "Parte {{index}}" },
|
|
4879
|
+
numberLine: {
|
|
4880
|
+
addElementLimit_one: "Solo puedes agregar {{count}} elemento",
|
|
4881
|
+
addElementLimit_other: "Solo puedes agregar {{count}} elementos",
|
|
4882
|
+
clearAll: "Borrar todo"
|
|
4883
|
+
},
|
|
4884
|
+
imageClozeAssociation: {
|
|
4885
|
+
reachedLimit_one: "Has alcanzado el límite de {{count}} respuesta por área. Para agregar otra respuesta, primero se debe eliminar una respuesta.",
|
|
4886
|
+
reachedLimit_other: "Lleno"
|
|
4887
|
+
},
|
|
4888
|
+
drawingResponse: {
|
|
4889
|
+
fillColor: "Color de relleno",
|
|
4890
|
+
outlineColor: "Color del contorno",
|
|
4891
|
+
noFill: "Sin relleno",
|
|
4892
|
+
lightblue: "Azul claro",
|
|
4893
|
+
lightyellow: "Amarillo claro",
|
|
4894
|
+
red: "Rojo",
|
|
4895
|
+
orange: "Naranja",
|
|
4896
|
+
yellow: "Amarillo",
|
|
4897
|
+
violet: "Violeta",
|
|
4898
|
+
blue: "Azul",
|
|
4899
|
+
green: "Verde",
|
|
4900
|
+
white: "Blanco",
|
|
4901
|
+
black: "Negro",
|
|
4902
|
+
onDoubleClick: "Haz doble clic para revisar este texto. Presiona el botón de ingreso para enviar"
|
|
4903
|
+
},
|
|
4904
|
+
charting: {
|
|
4905
|
+
addCategory: "Añadir categoría",
|
|
4906
|
+
actions: "Acciones",
|
|
4907
|
+
add: "Añadir",
|
|
4908
|
+
delete: "Eliminar",
|
|
4909
|
+
newLabel: "Nueva etiqueta",
|
|
4910
|
+
reachedLimit_other: "No puede haber más de {{count}} categorías.",
|
|
4911
|
+
keyLegend: {
|
|
4912
|
+
incorrectAnswer: "Respuesta incorrecta del estudiante",
|
|
4913
|
+
correctAnswer: "Respuesta correcta del estudiante",
|
|
4914
|
+
correctKeyAnswer: "Clave de respuesta correcta"
|
|
4915
|
+
}
|
|
4916
|
+
},
|
|
4917
|
+
graphing: {
|
|
4918
|
+
point: "Punto",
|
|
4919
|
+
circle: "Circulo",
|
|
4920
|
+
line: "Línea",
|
|
4921
|
+
parabola: "Parábola",
|
|
4922
|
+
absolute: "Valor absoluto",
|
|
4923
|
+
exponential: "Exponencial",
|
|
4924
|
+
polygon: "Polígono",
|
|
4925
|
+
ray: "Semirrecta",
|
|
4926
|
+
segment: "Segmento ",
|
|
4927
|
+
sine: "Seno",
|
|
4928
|
+
vector: "Vector",
|
|
4929
|
+
label: "Etiqueta",
|
|
4930
|
+
redo: "Rehacer",
|
|
4931
|
+
reset: "Reiniciar"
|
|
4932
|
+
},
|
|
4933
|
+
mathInline: { primaryCorrectWithAlternates: "Nota: La respuesta que se muestra arriba es la respuesta correcta principal especificada por el autor para esta pregunta, pero también se pueden reconocer otras respuestas como correctas." },
|
|
4934
|
+
mcPopulatedBlank: {
|
|
4935
|
+
answerChoices: "Opciones de respuesta",
|
|
4936
|
+
blankLabel: "espacio en blanco",
|
|
4937
|
+
emptyBlank: "(en blanco)",
|
|
4938
|
+
blankPreSelectionHint: "La respuesta que elijas aparecerá en la línea en blanco de arriba.",
|
|
4939
|
+
correctAnswerSelected: "Respuesta correcta seleccionada",
|
|
4940
|
+
incorrectAnswerSelected: "Respuesta incorrecta seleccionada",
|
|
4941
|
+
selectedAnswerImage: "Imagen de la respuesta seleccionada",
|
|
4942
|
+
choiceImage: "Opción {{id}}",
|
|
4943
|
+
clickToEnableAutoplay: "Haz clic para activar la reproducción automática del audio",
|
|
4944
|
+
audioResourceUnavailable: "El audio está activado, pero no hay una URL de audio reproducible configurada.",
|
|
4945
|
+
listen: "Escuchar",
|
|
4946
|
+
listenSilentAlt: "Escuchar. Repetir las instrucciones.",
|
|
4947
|
+
listenPlayingAlt: "Escuchar. Estas son las instrucciones.",
|
|
4948
|
+
printAudio: "Audio:",
|
|
4949
|
+
printTranscript: "Transcripción:",
|
|
4950
|
+
printKey: "(clave)"
|
|
4951
|
+
},
|
|
4952
|
+
multipleChoice: {
|
|
4953
|
+
minSelections: "Seleccione al menos {{minSelections}}.",
|
|
4954
|
+
maxSelections_one: "Sólo se permite {{maxSelections}} respuesta.",
|
|
4955
|
+
maxSelections_other: "Sólo se permiten {{maxSelections}} respuestas.",
|
|
4956
|
+
minmaxSelections_equal: "Seleccione {{minSelections}}.",
|
|
4957
|
+
minmaxSelections_range: "Seleccione entre {{minSelections}} y {{maxSelections}}."
|
|
4958
|
+
},
|
|
4959
|
+
selectText: {
|
|
4960
|
+
correctAnswerSelected: "Respuesta Correcta",
|
|
4961
|
+
correctAnswerNotSelected: "Respuesta Correcta No Seleccionada",
|
|
4962
|
+
incorrectSelection: "Selección Incorrecta",
|
|
4963
|
+
key: "Clave"
|
|
4964
|
+
},
|
|
4965
|
+
simpleCloze: {
|
|
4966
|
+
correctAnswerShown: "Respuesta correcta",
|
|
4967
|
+
correct: "Correcto",
|
|
4968
|
+
incorrect: "Incorrecto",
|
|
4969
|
+
unanswered: "Sin respuesta",
|
|
4970
|
+
placeholder: "Escribe tu respuesta...",
|
|
4971
|
+
answerInput: "Tu respuesta",
|
|
4972
|
+
printCorrectAnswer: "Respuesta correcta:",
|
|
4973
|
+
printAnswerBlank: "Espacio para la respuesta"
|
|
4974
|
+
},
|
|
4975
|
+
vennClassification: {
|
|
4976
|
+
tray: "Fichas para clasificar",
|
|
4977
|
+
unknownTarget: "desconocido",
|
|
4978
|
+
cancelled: "Cancelado",
|
|
4979
|
+
returnedToTray: "Se devolvió {{name}} a la bandeja",
|
|
4980
|
+
placedIn: "Se colocó {{name}} en {{target}}",
|
|
4981
|
+
pickedUp: "Se tomó {{name}}",
|
|
4982
|
+
pickedUpWithKeyboard: "Se tomó {{name}}, destino: {{target}}. Usa las flechas para elegir un destino, Enter para soltar y Escape para cancelar.",
|
|
4983
|
+
dropTarget: "Destino: {{target}}",
|
|
4984
|
+
unsupportedCircles_one: "No se puede mostrar este diagrama: tiene {{count}} círculo, y solo se admiten {{supported}}.",
|
|
4985
|
+
unsupportedCircles_other: "No se puede mostrar este diagrama: tiene {{count}} círculos, y solo se admiten {{supported}}.",
|
|
4986
|
+
setNumber: "Conjunto {{number}}",
|
|
4987
|
+
regionOnly: "Solo {{set}}",
|
|
4988
|
+
regionNeither: "Ni {{first}} ni {{second}}",
|
|
4989
|
+
regionNoneOf: "Ninguno de {{sets}}",
|
|
4990
|
+
regionAndSeparator: " y ",
|
|
4991
|
+
tileFallbackName: "Ficha",
|
|
4992
|
+
tileNotPlaced: "sin colocar",
|
|
4993
|
+
tileInRegion: "en {{region}}",
|
|
4994
|
+
tileCorrect: "correcta",
|
|
4995
|
+
tileIncorrect: "incorrecta"
|
|
4996
|
+
}
|
|
4997
|
+
},
|
|
4998
|
+
common: {
|
|
4999
|
+
undo: "Deshacer",
|
|
5000
|
+
clearAll: "Borrar todo",
|
|
5001
|
+
correct: "Correcto",
|
|
5002
|
+
incorrect: "Incorrecto",
|
|
5003
|
+
showCorrectAnswer: "Mostrar respuesta correcta",
|
|
5004
|
+
hideCorrectAnswer: "Ocultar respuesta correcta",
|
|
5005
|
+
showTeacherInstructions: "Mostrar instrucciones para el maestro",
|
|
5006
|
+
hideTeacherInstructions: "Ocultar instrucciones para el maestro",
|
|
5007
|
+
commonCorrectAnswerWithAlternates: "Nota: La respuesta que se muestra arriba es la respuesta correcta más común para esta pregunta. También se definen una o más respuestas correctas adicionales, y también se reconocerán como correctas.",
|
|
5008
|
+
warning: "Advertencia",
|
|
5009
|
+
showNote: "Mostrar Nota",
|
|
5010
|
+
hideNote: "Ocultar Nota",
|
|
5011
|
+
cancel: "Cancelar"
|
|
5012
|
+
}
|
|
5013
|
+
};
|
|
5014
|
+
//#endregion
|
|
5015
|
+
//#region ../../../node_modules/.bun/i18next@25.10.10+1fb4c65d43e298b9/node_modules/i18next/dist/esm/i18next.js
|
|
5016
|
+
var isString = (obj) => typeof obj === "string";
|
|
5017
|
+
var defer = () => {
|
|
5018
|
+
let res;
|
|
5019
|
+
let rej;
|
|
5020
|
+
const promise = new Promise((resolve, reject) => {
|
|
5021
|
+
res = resolve;
|
|
5022
|
+
rej = reject;
|
|
5023
|
+
});
|
|
5024
|
+
promise.resolve = res;
|
|
5025
|
+
promise.reject = rej;
|
|
5026
|
+
return promise;
|
|
5027
|
+
};
|
|
5028
|
+
var makeString = (object) => {
|
|
5029
|
+
if (object == null) return "";
|
|
5030
|
+
return "" + object;
|
|
5031
|
+
};
|
|
5032
|
+
var copy = (a, s, t) => {
|
|
5033
|
+
a.forEach((m) => {
|
|
5034
|
+
if (s[m]) t[m] = s[m];
|
|
5035
|
+
});
|
|
5036
|
+
};
|
|
5037
|
+
var lastOfPathSeparatorRegExp = /###/g;
|
|
5038
|
+
var cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
5039
|
+
var canNotTraverseDeeper = (object) => !object || isString(object);
|
|
5040
|
+
var getLastOfPath = (object, path, Empty) => {
|
|
5041
|
+
const stack = !isString(path) ? path : path.split(".");
|
|
5042
|
+
let stackIndex = 0;
|
|
5043
|
+
while (stackIndex < stack.length - 1) {
|
|
5044
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
5045
|
+
const key = cleanKey(stack[stackIndex]);
|
|
5046
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
5047
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) object = object[key];
|
|
5048
|
+
else object = {};
|
|
5049
|
+
++stackIndex;
|
|
5050
|
+
}
|
|
5051
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
5052
|
+
return {
|
|
5053
|
+
obj: object,
|
|
5054
|
+
k: cleanKey(stack[stackIndex])
|
|
5055
|
+
};
|
|
5056
|
+
};
|
|
5057
|
+
var setPath = (object, path, newValue) => {
|
|
5058
|
+
const { obj, k } = getLastOfPath(object, path, Object);
|
|
5059
|
+
if (obj !== void 0 || path.length === 1) {
|
|
5060
|
+
obj[k] = newValue;
|
|
5061
|
+
return;
|
|
5062
|
+
}
|
|
5063
|
+
let e = path[path.length - 1];
|
|
5064
|
+
let p = path.slice(0, path.length - 1);
|
|
5065
|
+
let last = getLastOfPath(object, p, Object);
|
|
5066
|
+
while (last.obj === void 0 && p.length) {
|
|
5067
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
5068
|
+
p = p.slice(0, p.length - 1);
|
|
5069
|
+
last = getLastOfPath(object, p, Object);
|
|
5070
|
+
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") last.obj = void 0;
|
|
5071
|
+
}
|
|
5072
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
5073
|
+
};
|
|
5074
|
+
var pushPath = (object, path, newValue, concat) => {
|
|
5075
|
+
const { obj, k } = getLastOfPath(object, path, Object);
|
|
5076
|
+
obj[k] = obj[k] || [];
|
|
5077
|
+
obj[k].push(newValue);
|
|
5078
|
+
};
|
|
5079
|
+
var getPath = (object, path) => {
|
|
5080
|
+
const { obj, k } = getLastOfPath(object, path);
|
|
5081
|
+
if (!obj) return void 0;
|
|
5082
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
|
|
5083
|
+
return obj[k];
|
|
5084
|
+
};
|
|
5085
|
+
var getPathWithDefaults = (data, defaultData, key) => {
|
|
5086
|
+
const value = getPath(data, key);
|
|
5087
|
+
if (value !== void 0) return value;
|
|
5088
|
+
return getPath(defaultData, key);
|
|
5089
|
+
};
|
|
5090
|
+
var deepExtend = (target, source, overwrite) => {
|
|
5091
|
+
for (const prop in source) if (prop !== "__proto__" && prop !== "constructor") if (prop in target) if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
5092
|
+
if (overwrite) target[prop] = source[prop];
|
|
5093
|
+
} else deepExtend(target[prop], source[prop], overwrite);
|
|
5094
|
+
else target[prop] = source[prop];
|
|
5095
|
+
return target;
|
|
5096
|
+
};
|
|
5097
|
+
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
5098
|
+
var _entityMap = {
|
|
5099
|
+
"&": "&",
|
|
5100
|
+
"<": "<",
|
|
5101
|
+
">": ">",
|
|
5102
|
+
"\"": """,
|
|
5103
|
+
"'": "'",
|
|
5104
|
+
"/": "/"
|
|
5105
|
+
};
|
|
5106
|
+
var escape = (data) => {
|
|
5107
|
+
if (isString(data)) return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
5108
|
+
return data;
|
|
5109
|
+
};
|
|
5110
|
+
var RegExpCache = class {
|
|
5111
|
+
constructor(capacity) {
|
|
5112
|
+
this.capacity = capacity;
|
|
5113
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
5114
|
+
this.regExpQueue = [];
|
|
5115
|
+
}
|
|
5116
|
+
getRegExp(pattern) {
|
|
5117
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
5118
|
+
if (regExpFromCache !== void 0) return regExpFromCache;
|
|
5119
|
+
const regExpNew = new RegExp(pattern);
|
|
5120
|
+
if (this.regExpQueue.length === this.capacity) this.regExpMap.delete(this.regExpQueue.shift());
|
|
5121
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
5122
|
+
this.regExpQueue.push(pattern);
|
|
5123
|
+
return regExpNew;
|
|
5124
|
+
}
|
|
5125
|
+
};
|
|
5126
|
+
var chars = [
|
|
5127
|
+
" ",
|
|
5128
|
+
",",
|
|
5129
|
+
"?",
|
|
5130
|
+
"!",
|
|
5131
|
+
";"
|
|
5132
|
+
];
|
|
5133
|
+
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
5134
|
+
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
5135
|
+
nsSeparator = nsSeparator || "";
|
|
5136
|
+
keySeparator = keySeparator || "";
|
|
5137
|
+
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
5138
|
+
if (possibleChars.length === 0) return true;
|
|
5139
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
5140
|
+
let matched = !r.test(key);
|
|
5141
|
+
if (!matched) {
|
|
5142
|
+
const ki = key.indexOf(keySeparator);
|
|
5143
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) matched = true;
|
|
5144
|
+
}
|
|
5145
|
+
return matched;
|
|
5146
|
+
};
|
|
5147
|
+
var deepFind = (obj, path, keySeparator = ".") => {
|
|
5148
|
+
if (!obj) return void 0;
|
|
5149
|
+
if (obj[path]) {
|
|
5150
|
+
if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
|
|
5151
|
+
return obj[path];
|
|
5152
|
+
}
|
|
5153
|
+
const tokens = path.split(keySeparator);
|
|
5154
|
+
let current = obj;
|
|
5155
|
+
for (let i = 0; i < tokens.length;) {
|
|
5156
|
+
if (!current || typeof current !== "object") return;
|
|
5157
|
+
let next;
|
|
5158
|
+
let nextPath = "";
|
|
5159
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
5160
|
+
if (j !== i) nextPath += keySeparator;
|
|
5161
|
+
nextPath += tokens[j];
|
|
5162
|
+
next = current[nextPath];
|
|
5163
|
+
if (next !== void 0) {
|
|
5164
|
+
if ([
|
|
5165
|
+
"string",
|
|
5166
|
+
"number",
|
|
5167
|
+
"boolean"
|
|
5168
|
+
].indexOf(typeof next) > -1 && j < tokens.length - 1) continue;
|
|
5169
|
+
i += j - i + 1;
|
|
5170
|
+
break;
|
|
5171
|
+
}
|
|
5172
|
+
}
|
|
5173
|
+
current = next;
|
|
5174
|
+
}
|
|
5175
|
+
return current;
|
|
5176
|
+
};
|
|
5177
|
+
var getCleanedCode = (code) => code?.replace(/_/g, "-");
|
|
5178
|
+
var consoleLogger = {
|
|
5179
|
+
type: "logger",
|
|
5180
|
+
log(args) {
|
|
5181
|
+
this.output("log", args);
|
|
5182
|
+
},
|
|
5183
|
+
warn(args) {
|
|
5184
|
+
this.output("warn", args);
|
|
5185
|
+
},
|
|
5186
|
+
error(args) {
|
|
5187
|
+
this.output("error", args);
|
|
5188
|
+
},
|
|
5189
|
+
output(type, args) {
|
|
5190
|
+
console?.[type]?.apply?.(console, args);
|
|
5191
|
+
}
|
|
5192
|
+
};
|
|
5193
|
+
var baseLogger = new class Logger {
|
|
5194
|
+
constructor(concreteLogger, options = {}) {
|
|
5195
|
+
this.init(concreteLogger, options);
|
|
5196
|
+
}
|
|
5197
|
+
init(concreteLogger, options = {}) {
|
|
5198
|
+
this.prefix = options.prefix || "i18next:";
|
|
5199
|
+
this.logger = concreteLogger || consoleLogger;
|
|
5200
|
+
this.options = options;
|
|
5201
|
+
this.debug = options.debug;
|
|
5202
|
+
}
|
|
5203
|
+
log(...args) {
|
|
5204
|
+
return this.forward(args, "log", "", true);
|
|
5205
|
+
}
|
|
5206
|
+
warn(...args) {
|
|
5207
|
+
return this.forward(args, "warn", "", true);
|
|
5208
|
+
}
|
|
5209
|
+
error(...args) {
|
|
5210
|
+
return this.forward(args, "error", "");
|
|
5211
|
+
}
|
|
5212
|
+
deprecate(...args) {
|
|
5213
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
5214
|
+
}
|
|
5215
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
5216
|
+
if (debugOnly && !this.debug) return null;
|
|
5217
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
5218
|
+
return this.logger[lvl](args);
|
|
5219
|
+
}
|
|
5220
|
+
create(moduleName) {
|
|
5221
|
+
return new Logger(this.logger, {
|
|
5222
|
+
prefix: `${this.prefix}:${moduleName}:`,
|
|
5223
|
+
...this.options
|
|
5224
|
+
});
|
|
5225
|
+
}
|
|
5226
|
+
clone(options) {
|
|
5227
|
+
options = options || this.options;
|
|
5228
|
+
options.prefix = options.prefix || this.prefix;
|
|
5229
|
+
return new Logger(this.logger, options);
|
|
5230
|
+
}
|
|
5231
|
+
}();
|
|
5232
|
+
var EventEmitter = class {
|
|
5233
|
+
constructor() {
|
|
5234
|
+
this.observers = {};
|
|
5235
|
+
}
|
|
5236
|
+
on(events, listener) {
|
|
5237
|
+
events.split(" ").forEach((event) => {
|
|
5238
|
+
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
5239
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
5240
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
5241
|
+
});
|
|
5242
|
+
return this;
|
|
5243
|
+
}
|
|
5244
|
+
off(event, listener) {
|
|
5245
|
+
if (!this.observers[event]) return;
|
|
5246
|
+
if (!listener) {
|
|
5247
|
+
delete this.observers[event];
|
|
5248
|
+
return;
|
|
5249
|
+
}
|
|
5250
|
+
this.observers[event].delete(listener);
|
|
5251
|
+
}
|
|
5252
|
+
emit(event, ...args) {
|
|
5253
|
+
if (this.observers[event]) Array.from(this.observers[event].entries()).forEach(([observer, numTimesAdded]) => {
|
|
5254
|
+
for (let i = 0; i < numTimesAdded; i++) observer(...args);
|
|
5255
|
+
});
|
|
5256
|
+
if (this.observers["*"]) Array.from(this.observers["*"].entries()).forEach(([observer, numTimesAdded]) => {
|
|
5257
|
+
for (let i = 0; i < numTimesAdded; i++) observer.apply(observer, [event, ...args]);
|
|
5258
|
+
});
|
|
5259
|
+
}
|
|
5260
|
+
};
|
|
5261
|
+
var ResourceStore = class extends EventEmitter {
|
|
5262
|
+
constructor(data, options = {
|
|
5263
|
+
ns: ["translation"],
|
|
5264
|
+
defaultNS: "translation"
|
|
5265
|
+
}) {
|
|
5266
|
+
super();
|
|
5267
|
+
this.data = data || {};
|
|
5268
|
+
this.options = options;
|
|
5269
|
+
if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
|
|
5270
|
+
if (this.options.ignoreJSONStructure === void 0) this.options.ignoreJSONStructure = true;
|
|
5271
|
+
}
|
|
5272
|
+
addNamespaces(ns) {
|
|
5273
|
+
if (this.options.ns.indexOf(ns) < 0) this.options.ns.push(ns);
|
|
5274
|
+
}
|
|
5275
|
+
removeNamespaces(ns) {
|
|
5276
|
+
const index = this.options.ns.indexOf(ns);
|
|
5277
|
+
if (index > -1) this.options.ns.splice(index, 1);
|
|
5278
|
+
}
|
|
5279
|
+
getResource(lng, ns, key, options = {}) {
|
|
5280
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
5281
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
5282
|
+
let path;
|
|
5283
|
+
if (lng.indexOf(".") > -1) path = lng.split(".");
|
|
5284
|
+
else {
|
|
5285
|
+
path = [lng, ns];
|
|
5286
|
+
if (key) if (Array.isArray(key)) path.push(...key);
|
|
5287
|
+
else if (isString(key) && keySeparator) path.push(...key.split(keySeparator));
|
|
5288
|
+
else path.push(key);
|
|
5289
|
+
}
|
|
5290
|
+
const result = getPath(this.data, path);
|
|
5291
|
+
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
5292
|
+
lng = path[0];
|
|
5293
|
+
ns = path[1];
|
|
5294
|
+
key = path.slice(2).join(".");
|
|
5295
|
+
}
|
|
5296
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
5297
|
+
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
5298
|
+
}
|
|
5299
|
+
addResource(lng, ns, key, value, options = { silent: false }) {
|
|
5300
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
5301
|
+
let path = [lng, ns];
|
|
5302
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
5303
|
+
if (lng.indexOf(".") > -1) {
|
|
5304
|
+
path = lng.split(".");
|
|
5305
|
+
value = ns;
|
|
5306
|
+
ns = path[1];
|
|
5307
|
+
}
|
|
5308
|
+
this.addNamespaces(ns);
|
|
5309
|
+
setPath(this.data, path, value);
|
|
5310
|
+
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
5311
|
+
}
|
|
5312
|
+
addResources(lng, ns, resources, options = { silent: false }) {
|
|
5313
|
+
for (const m in resources) if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], { silent: true });
|
|
5314
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
5315
|
+
}
|
|
5316
|
+
addResourceBundle(lng, ns, resources, deep, overwrite, options = {
|
|
5317
|
+
silent: false,
|
|
5318
|
+
skipCopy: false
|
|
5319
|
+
}) {
|
|
5320
|
+
let path = [lng, ns];
|
|
5321
|
+
if (lng.indexOf(".") > -1) {
|
|
5322
|
+
path = lng.split(".");
|
|
5323
|
+
deep = resources;
|
|
5324
|
+
resources = ns;
|
|
5325
|
+
ns = path[1];
|
|
5326
|
+
}
|
|
5327
|
+
this.addNamespaces(ns);
|
|
5328
|
+
let pack = getPath(this.data, path) || {};
|
|
5329
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
5330
|
+
if (deep) deepExtend(pack, resources, overwrite);
|
|
5331
|
+
else pack = {
|
|
5332
|
+
...pack,
|
|
5333
|
+
...resources
|
|
5334
|
+
};
|
|
5335
|
+
setPath(this.data, path, pack);
|
|
5336
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
5337
|
+
}
|
|
5338
|
+
removeResourceBundle(lng, ns) {
|
|
5339
|
+
if (this.hasResourceBundle(lng, ns)) delete this.data[lng][ns];
|
|
5340
|
+
this.removeNamespaces(ns);
|
|
5341
|
+
this.emit("removed", lng, ns);
|
|
5342
|
+
}
|
|
5343
|
+
hasResourceBundle(lng, ns) {
|
|
5344
|
+
return this.getResource(lng, ns) !== void 0;
|
|
5345
|
+
}
|
|
5346
|
+
getResourceBundle(lng, ns) {
|
|
5347
|
+
if (!ns) ns = this.options.defaultNS;
|
|
5348
|
+
return this.getResource(lng, ns);
|
|
5349
|
+
}
|
|
5350
|
+
getDataByLanguage(lng) {
|
|
5351
|
+
return this.data[lng];
|
|
5352
|
+
}
|
|
5353
|
+
hasLanguageSomeTranslations(lng) {
|
|
5354
|
+
const data = this.getDataByLanguage(lng);
|
|
5355
|
+
return !!(data && Object.keys(data) || []).find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
5356
|
+
}
|
|
5357
|
+
toJSON() {
|
|
5358
|
+
return this.data;
|
|
5359
|
+
}
|
|
5360
|
+
};
|
|
5361
|
+
var postProcessor = {
|
|
5362
|
+
processors: {},
|
|
5363
|
+
addPostProcessor(module) {
|
|
5364
|
+
this.processors[module.name] = module;
|
|
5365
|
+
},
|
|
5366
|
+
handle(processors, value, key, options, translator) {
|
|
5367
|
+
processors.forEach((processor) => {
|
|
5368
|
+
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
5369
|
+
});
|
|
5370
|
+
return value;
|
|
5371
|
+
}
|
|
5372
|
+
};
|
|
5373
|
+
var PATH_KEY = Symbol("i18next/PATH_KEY");
|
|
5374
|
+
function createProxy() {
|
|
5375
|
+
const state = [];
|
|
5376
|
+
const handler = Object.create(null);
|
|
5377
|
+
let proxy;
|
|
5378
|
+
handler.get = (target, key) => {
|
|
5379
|
+
proxy?.revoke?.();
|
|
5380
|
+
if (key === PATH_KEY) return state;
|
|
5381
|
+
state.push(key);
|
|
5382
|
+
proxy = Proxy.revocable(target, handler);
|
|
5383
|
+
return proxy.proxy;
|
|
5384
|
+
};
|
|
5385
|
+
return Proxy.revocable(Object.create(null), handler).proxy;
|
|
5386
|
+
}
|
|
5387
|
+
function keysFromSelector(selector, opts) {
|
|
5388
|
+
const { [PATH_KEY]: path } = selector(createProxy());
|
|
5389
|
+
const keySeparator = opts?.keySeparator ?? ".";
|
|
5390
|
+
const nsSeparator = opts?.nsSeparator ?? ":";
|
|
5391
|
+
if (path.length > 1 && nsSeparator) {
|
|
5392
|
+
const ns = opts?.ns;
|
|
5393
|
+
const nsArray = Array.isArray(ns) ? ns : null;
|
|
5394
|
+
if (nsArray && nsArray.length > 1 && nsArray.slice(1).includes(path[0])) return `${path[0]}${nsSeparator}${path.slice(1).join(keySeparator)}`;
|
|
5395
|
+
}
|
|
5396
|
+
return path.join(keySeparator);
|
|
5397
|
+
}
|
|
5398
|
+
var checkedLoadedFor = {};
|
|
5399
|
+
var shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
5400
|
+
var Translator = class Translator extends EventEmitter {
|
|
5401
|
+
constructor(services, options = {}) {
|
|
5402
|
+
super();
|
|
5403
|
+
copy([
|
|
5404
|
+
"resourceStore",
|
|
5405
|
+
"languageUtils",
|
|
5406
|
+
"pluralResolver",
|
|
5407
|
+
"interpolator",
|
|
5408
|
+
"backendConnector",
|
|
5409
|
+
"i18nFormat",
|
|
5410
|
+
"utils"
|
|
5411
|
+
], services, this);
|
|
5412
|
+
this.options = options;
|
|
5413
|
+
if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
|
|
5414
|
+
this.logger = baseLogger.create("translator");
|
|
5415
|
+
}
|
|
5416
|
+
changeLanguage(lng) {
|
|
5417
|
+
if (lng) this.language = lng;
|
|
5418
|
+
}
|
|
5419
|
+
exists(key, o = { interpolation: {} }) {
|
|
5420
|
+
const opt = { ...o };
|
|
5421
|
+
if (key == null) return false;
|
|
5422
|
+
const resolved = this.resolve(key, opt);
|
|
5423
|
+
if (resolved?.res === void 0) return false;
|
|
5424
|
+
const isObject = shouldHandleAsObject(resolved.res);
|
|
5425
|
+
if (opt.returnObjects === false && isObject) return false;
|
|
5426
|
+
return true;
|
|
5427
|
+
}
|
|
5428
|
+
extractFromKey(key, opt) {
|
|
5429
|
+
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
5430
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
5431
|
+
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
5432
|
+
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
5433
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
5434
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
5435
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
5436
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
5437
|
+
if (m && m.length > 0) return {
|
|
5438
|
+
key,
|
|
5439
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
5440
|
+
};
|
|
5441
|
+
const parts = key.split(nsSeparator);
|
|
5442
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
5443
|
+
key = parts.join(keySeparator);
|
|
5444
|
+
}
|
|
5445
|
+
return {
|
|
5446
|
+
key,
|
|
5447
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
5448
|
+
};
|
|
5449
|
+
}
|
|
5450
|
+
translate(keys, o, lastKey) {
|
|
5451
|
+
let opt = typeof o === "object" ? { ...o } : o;
|
|
5452
|
+
if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
5453
|
+
if (typeof opt === "object") opt = { ...opt };
|
|
5454
|
+
if (!opt) opt = {};
|
|
5455
|
+
if (keys == null) return "";
|
|
5456
|
+
if (typeof keys === "function") keys = keysFromSelector(keys, {
|
|
5457
|
+
...this.options,
|
|
5458
|
+
...opt
|
|
5459
|
+
});
|
|
5460
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
5461
|
+
keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
5462
|
+
...this.options,
|
|
5463
|
+
...opt
|
|
5464
|
+
}) : String(k));
|
|
5465
|
+
const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
|
|
5466
|
+
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
5467
|
+
const { key, namespaces } = this.extractFromKey(keys[keys.length - 1], opt);
|
|
5468
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
5469
|
+
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
5470
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
5471
|
+
const lng = opt.lng || this.language;
|
|
5472
|
+
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
5473
|
+
if (lng?.toLowerCase() === "cimode") {
|
|
5474
|
+
if (appendNamespaceToCIMode) {
|
|
5475
|
+
if (returnDetails) return {
|
|
5476
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
5477
|
+
usedKey: key,
|
|
5478
|
+
exactUsedKey: key,
|
|
5479
|
+
usedLng: lng,
|
|
5480
|
+
usedNS: namespace,
|
|
5481
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
5482
|
+
};
|
|
5483
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
5484
|
+
}
|
|
5485
|
+
if (returnDetails) return {
|
|
5486
|
+
res: key,
|
|
5487
|
+
usedKey: key,
|
|
5488
|
+
exactUsedKey: key,
|
|
5489
|
+
usedLng: lng,
|
|
5490
|
+
usedNS: namespace,
|
|
5491
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
5492
|
+
};
|
|
5493
|
+
return key;
|
|
5494
|
+
}
|
|
5495
|
+
const resolved = this.resolve(keys, opt);
|
|
5496
|
+
let res = resolved?.res;
|
|
5497
|
+
const resUsedKey = resolved?.usedKey || key;
|
|
5498
|
+
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
5499
|
+
const noObject = [
|
|
5500
|
+
"[object Number]",
|
|
5501
|
+
"[object Function]",
|
|
5502
|
+
"[object RegExp]"
|
|
5503
|
+
];
|
|
5504
|
+
const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
|
|
5505
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
5506
|
+
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
5507
|
+
const hasDefaultValue = Translator.hasDefaultValue(opt);
|
|
5508
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
|
|
5509
|
+
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, { ordinal: false }) : "";
|
|
5510
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
5511
|
+
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
5512
|
+
let resForObjHndl = res;
|
|
5513
|
+
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) resForObjHndl = defaultValue;
|
|
5514
|
+
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
5515
|
+
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
5516
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
5517
|
+
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
5518
|
+
if (!this.options.returnedObjectHandler) this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
5519
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
5520
|
+
...opt,
|
|
5521
|
+
ns: namespaces
|
|
5522
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
5523
|
+
if (returnDetails) {
|
|
5524
|
+
resolved.res = r;
|
|
5525
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
5526
|
+
return resolved;
|
|
5527
|
+
}
|
|
5528
|
+
return r;
|
|
5529
|
+
}
|
|
5530
|
+
if (keySeparator) {
|
|
5531
|
+
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
5532
|
+
const copy = resTypeIsArray ? [] : {};
|
|
5533
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
5534
|
+
for (const m in resForObjHndl) if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
5535
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
5536
|
+
if (hasDefaultValue && !res) copy[m] = this.translate(deepKey, {
|
|
5537
|
+
...opt,
|
|
5538
|
+
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
|
|
5539
|
+
joinArrays: false,
|
|
5540
|
+
ns: namespaces
|
|
5541
|
+
});
|
|
5542
|
+
else copy[m] = this.translate(deepKey, {
|
|
5543
|
+
...opt,
|
|
5544
|
+
joinArrays: false,
|
|
5545
|
+
ns: namespaces
|
|
5546
|
+
});
|
|
5547
|
+
if (copy[m] === deepKey) copy[m] = resForObjHndl[m];
|
|
5548
|
+
}
|
|
5549
|
+
res = copy;
|
|
5550
|
+
}
|
|
5551
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
5552
|
+
res = res.join(joinArrays);
|
|
5553
|
+
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
5554
|
+
} else {
|
|
5555
|
+
let usedDefault = false;
|
|
5556
|
+
let usedKey = false;
|
|
5557
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
5558
|
+
usedDefault = true;
|
|
5559
|
+
res = defaultValue;
|
|
5560
|
+
}
|
|
5561
|
+
if (!this.isValidLookup(res)) {
|
|
5562
|
+
usedKey = true;
|
|
5563
|
+
res = key;
|
|
5564
|
+
}
|
|
5565
|
+
const resForMissing = (opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && usedKey ? void 0 : res;
|
|
5566
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
5567
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
5568
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
5569
|
+
if (keySeparator) {
|
|
5570
|
+
const fk = this.resolve(key, {
|
|
5571
|
+
...opt,
|
|
5572
|
+
keySeparator: false
|
|
5573
|
+
});
|
|
5574
|
+
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.");
|
|
5575
|
+
}
|
|
5576
|
+
let lngs = [];
|
|
5577
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
5578
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) for (let i = 0; i < fallbackLngs.length; i++) lngs.push(fallbackLngs[i]);
|
|
5579
|
+
else if (this.options.saveMissingTo === "all") lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
5580
|
+
else lngs.push(opt.lng || this.language);
|
|
5581
|
+
const send = (l, k, specificDefaultValue) => {
|
|
5582
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
5583
|
+
if (this.options.missingKeyHandler) this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
5584
|
+
else if (this.backendConnector?.saveMissing) this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
5585
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
5586
|
+
};
|
|
5587
|
+
if (this.options.saveMissing) if (this.options.saveMissingPlurals && needsPluralHandling) lngs.forEach((language) => {
|
|
5588
|
+
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
5589
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
5590
|
+
suffixes.forEach((suffix) => {
|
|
5591
|
+
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
5592
|
+
});
|
|
5593
|
+
});
|
|
5594
|
+
else send(lngs, key, defaultValue);
|
|
5595
|
+
}
|
|
5596
|
+
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
5597
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}${nsSeparator}${key}`;
|
|
5598
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
|
|
5599
|
+
}
|
|
5600
|
+
if (returnDetails) {
|
|
5601
|
+
resolved.res = res;
|
|
5602
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
5603
|
+
return resolved;
|
|
5604
|
+
}
|
|
5605
|
+
return res;
|
|
5606
|
+
}
|
|
5607
|
+
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
5608
|
+
if (this.i18nFormat?.parse) res = this.i18nFormat.parse(res, {
|
|
5609
|
+
...this.options.interpolation.defaultVariables,
|
|
5610
|
+
...opt
|
|
5611
|
+
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, { resolved });
|
|
5612
|
+
else if (!opt.skipInterpolation) {
|
|
5613
|
+
if (opt.interpolation) this.interpolator.init({
|
|
5614
|
+
...opt,
|
|
5615
|
+
interpolation: {
|
|
5616
|
+
...this.options.interpolation,
|
|
5617
|
+
...opt.interpolation
|
|
5618
|
+
}
|
|
5619
|
+
});
|
|
5620
|
+
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
5621
|
+
let nestBef;
|
|
5622
|
+
if (skipOnVariables) {
|
|
5623
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
5624
|
+
nestBef = nb && nb.length;
|
|
5625
|
+
}
|
|
5626
|
+
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
5627
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
5628
|
+
...this.options.interpolation.defaultVariables,
|
|
5629
|
+
...data
|
|
5630
|
+
};
|
|
5631
|
+
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
5632
|
+
if (skipOnVariables) {
|
|
5633
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
5634
|
+
const nestAft = na && na.length;
|
|
5635
|
+
if (nestBef < nestAft) opt.nest = false;
|
|
5636
|
+
}
|
|
5637
|
+
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
5638
|
+
if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
|
|
5639
|
+
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
5640
|
+
this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
5641
|
+
return null;
|
|
5642
|
+
}
|
|
5643
|
+
return this.translate(...args, key);
|
|
5644
|
+
}, opt);
|
|
5645
|
+
if (opt.interpolation) this.interpolator.reset();
|
|
5646
|
+
}
|
|
5647
|
+
const postProcess = opt.postProcess || this.options.postProcess;
|
|
5648
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
5649
|
+
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
5650
|
+
i18nResolved: {
|
|
5651
|
+
...resolved,
|
|
5652
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
5653
|
+
},
|
|
5654
|
+
...opt
|
|
5655
|
+
} : opt, this);
|
|
5656
|
+
return res;
|
|
5657
|
+
}
|
|
5658
|
+
resolve(keys, opt = {}) {
|
|
5659
|
+
let found;
|
|
5660
|
+
let usedKey;
|
|
5661
|
+
let exactUsedKey;
|
|
5662
|
+
let usedLng;
|
|
5663
|
+
let usedNS;
|
|
5664
|
+
if (isString(keys)) keys = [keys];
|
|
5665
|
+
if (Array.isArray(keys)) keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
5666
|
+
...this.options,
|
|
5667
|
+
...opt
|
|
5668
|
+
}) : k);
|
|
5669
|
+
keys.forEach((k) => {
|
|
5670
|
+
if (this.isValidLookup(found)) return;
|
|
5671
|
+
const extracted = this.extractFromKey(k, opt);
|
|
5672
|
+
const key = extracted.key;
|
|
5673
|
+
usedKey = key;
|
|
5674
|
+
let namespaces = extracted.namespaces;
|
|
5675
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
5676
|
+
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
5677
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
5678
|
+
const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
|
|
5679
|
+
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
5680
|
+
namespaces.forEach((ns) => {
|
|
5681
|
+
if (this.isValidLookup(found)) return;
|
|
5682
|
+
usedNS = ns;
|
|
5683
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
5684
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
5685
|
+
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!!!");
|
|
5686
|
+
}
|
|
5687
|
+
codes.forEach((code) => {
|
|
5688
|
+
if (this.isValidLookup(found)) return;
|
|
5689
|
+
usedLng = code;
|
|
5690
|
+
const finalKeys = [key];
|
|
5691
|
+
if (this.i18nFormat?.addLookupKeys) this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
5692
|
+
else {
|
|
5693
|
+
let pluralSuffix;
|
|
5694
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
5695
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
5696
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
5697
|
+
if (needsPluralHandling) {
|
|
5698
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
5699
|
+
finalKeys.push(key + pluralSuffix);
|
|
5700
|
+
if (needsZeroSuffixLookup) finalKeys.push(key + zeroSuffix);
|
|
5701
|
+
}
|
|
5702
|
+
if (needsContextHandling) {
|
|
5703
|
+
const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
|
|
5704
|
+
finalKeys.push(contextKey);
|
|
5705
|
+
if (needsPluralHandling) {
|
|
5706
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
5707
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
5708
|
+
if (needsZeroSuffixLookup) finalKeys.push(contextKey + zeroSuffix);
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5711
|
+
}
|
|
5712
|
+
let possibleKey;
|
|
5713
|
+
while (possibleKey = finalKeys.pop()) if (!this.isValidLookup(found)) {
|
|
5714
|
+
exactUsedKey = possibleKey;
|
|
5715
|
+
found = this.getResource(code, ns, possibleKey, opt);
|
|
5716
|
+
}
|
|
5717
|
+
});
|
|
5718
|
+
});
|
|
5719
|
+
});
|
|
5720
|
+
return {
|
|
5721
|
+
res: found,
|
|
5722
|
+
usedKey,
|
|
5723
|
+
exactUsedKey,
|
|
5724
|
+
usedLng,
|
|
5725
|
+
usedNS
|
|
5726
|
+
};
|
|
5727
|
+
}
|
|
5728
|
+
isValidLookup(res) {
|
|
5729
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
5730
|
+
}
|
|
5731
|
+
getResource(code, ns, key, options = {}) {
|
|
5732
|
+
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
5733
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
5734
|
+
}
|
|
5735
|
+
getUsedParamsDetails(options = {}) {
|
|
5736
|
+
const optionsKeys = [
|
|
5737
|
+
"defaultValue",
|
|
5738
|
+
"ordinal",
|
|
5739
|
+
"context",
|
|
5740
|
+
"replace",
|
|
5741
|
+
"lng",
|
|
5742
|
+
"lngs",
|
|
5743
|
+
"fallbackLng",
|
|
5744
|
+
"ns",
|
|
5745
|
+
"keySeparator",
|
|
5746
|
+
"nsSeparator",
|
|
5747
|
+
"returnObjects",
|
|
5748
|
+
"returnDetails",
|
|
5749
|
+
"joinArrays",
|
|
5750
|
+
"postProcess",
|
|
5751
|
+
"interpolation"
|
|
5752
|
+
];
|
|
5753
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
5754
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
5755
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") data.count = options.count;
|
|
5756
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
5757
|
+
...this.options.interpolation.defaultVariables,
|
|
5758
|
+
...data
|
|
5759
|
+
};
|
|
5760
|
+
if (!useOptionsReplaceForData) {
|
|
5761
|
+
data = { ...data };
|
|
5762
|
+
for (const key of optionsKeys) delete data[key];
|
|
5763
|
+
}
|
|
5764
|
+
return data;
|
|
5765
|
+
}
|
|
5766
|
+
static hasDefaultValue(options) {
|
|
5767
|
+
const prefix = "defaultValue";
|
|
5768
|
+
for (const option in options) if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, 12) && void 0 !== options[option]) return true;
|
|
5769
|
+
return false;
|
|
5770
|
+
}
|
|
5771
|
+
};
|
|
5772
|
+
var LanguageUtil = class {
|
|
5773
|
+
constructor(options) {
|
|
5774
|
+
this.options = options;
|
|
5775
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
5776
|
+
this.logger = baseLogger.create("languageUtils");
|
|
5777
|
+
}
|
|
5778
|
+
getScriptPartFromCode(code) {
|
|
5779
|
+
code = getCleanedCode(code);
|
|
5780
|
+
if (!code || code.indexOf("-") < 0) return null;
|
|
5781
|
+
const p = code.split("-");
|
|
5782
|
+
if (p.length === 2) return null;
|
|
5783
|
+
p.pop();
|
|
5784
|
+
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
5785
|
+
return this.formatLanguageCode(p.join("-"));
|
|
5786
|
+
}
|
|
5787
|
+
getLanguagePartFromCode(code) {
|
|
5788
|
+
code = getCleanedCode(code);
|
|
5789
|
+
if (!code || code.indexOf("-") < 0) return code;
|
|
5790
|
+
const p = code.split("-");
|
|
5791
|
+
return this.formatLanguageCode(p[0]);
|
|
5792
|
+
}
|
|
5793
|
+
formatLanguageCode(code) {
|
|
5794
|
+
if (isString(code) && code.indexOf("-") > -1) {
|
|
5795
|
+
let formattedCode;
|
|
5796
|
+
try {
|
|
5797
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
5798
|
+
} catch (e) {}
|
|
5799
|
+
if (formattedCode && this.options.lowerCaseLng) formattedCode = formattedCode.toLowerCase();
|
|
5800
|
+
if (formattedCode) return formattedCode;
|
|
5801
|
+
if (this.options.lowerCaseLng) return code.toLowerCase();
|
|
5802
|
+
return code;
|
|
5803
|
+
}
|
|
5804
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
5805
|
+
}
|
|
5806
|
+
isSupportedCode(code) {
|
|
5807
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) code = this.getLanguagePartFromCode(code);
|
|
5808
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
5809
|
+
}
|
|
5810
|
+
getBestMatchFromCodes(codes) {
|
|
5811
|
+
if (!codes) return null;
|
|
5812
|
+
let found;
|
|
5813
|
+
codes.forEach((code) => {
|
|
5814
|
+
if (found) return;
|
|
5815
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
5816
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
5817
|
+
});
|
|
5818
|
+
if (!found && this.options.supportedLngs) codes.forEach((code) => {
|
|
5819
|
+
if (found) return;
|
|
5820
|
+
const lngScOnly = this.getScriptPartFromCode(code);
|
|
5821
|
+
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
5822
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
5823
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
5824
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
5825
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
5826
|
+
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
|
|
5827
|
+
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
|
|
5828
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
5829
|
+
});
|
|
5830
|
+
});
|
|
5831
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
5832
|
+
return found;
|
|
5833
|
+
}
|
|
5834
|
+
getFallbackCodes(fallbacks, code) {
|
|
5835
|
+
if (!fallbacks) return [];
|
|
5836
|
+
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
5837
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
5838
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
5839
|
+
if (!code) return fallbacks.default || [];
|
|
5840
|
+
let found = fallbacks[code];
|
|
5841
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
5842
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
5843
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
5844
|
+
if (!found) found = fallbacks.default;
|
|
5845
|
+
return found || [];
|
|
5846
|
+
}
|
|
5847
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
5848
|
+
const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
|
|
5849
|
+
const codes = [];
|
|
5850
|
+
const addCode = (c) => {
|
|
5851
|
+
if (!c) return;
|
|
5852
|
+
if (this.isSupportedCode(c)) codes.push(c);
|
|
5853
|
+
else this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
5854
|
+
};
|
|
5855
|
+
if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
5856
|
+
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
5857
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
5858
|
+
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
5859
|
+
} else if (isString(code)) addCode(this.formatLanguageCode(code));
|
|
5860
|
+
fallbackCodes.forEach((fc) => {
|
|
5861
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
5862
|
+
});
|
|
5863
|
+
return codes;
|
|
5864
|
+
}
|
|
5865
|
+
};
|
|
5866
|
+
var suffixesOrder = {
|
|
5867
|
+
zero: 0,
|
|
5868
|
+
one: 1,
|
|
5869
|
+
two: 2,
|
|
5870
|
+
few: 3,
|
|
5871
|
+
many: 4,
|
|
5872
|
+
other: 5
|
|
5873
|
+
};
|
|
5874
|
+
var dummyRule = {
|
|
5875
|
+
select: (count) => count === 1 ? "one" : "other",
|
|
5876
|
+
resolvedOptions: () => ({ pluralCategories: ["one", "other"] })
|
|
5877
|
+
};
|
|
5878
|
+
var PluralResolver = class {
|
|
5879
|
+
constructor(languageUtils, options = {}) {
|
|
5880
|
+
this.languageUtils = languageUtils;
|
|
5881
|
+
this.options = options;
|
|
5882
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
5883
|
+
this.pluralRulesCache = {};
|
|
5884
|
+
}
|
|
5885
|
+
clearCache() {
|
|
5886
|
+
this.pluralRulesCache = {};
|
|
5887
|
+
}
|
|
5888
|
+
getRule(code, options = {}) {
|
|
5889
|
+
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
5890
|
+
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
5891
|
+
const cacheKey = JSON.stringify({
|
|
5892
|
+
cleanedCode,
|
|
5893
|
+
type
|
|
5894
|
+
});
|
|
5895
|
+
if (cacheKey in this.pluralRulesCache) return this.pluralRulesCache[cacheKey];
|
|
5896
|
+
let rule;
|
|
5897
|
+
try {
|
|
5898
|
+
rule = new Intl.PluralRules(cleanedCode, { type });
|
|
5899
|
+
} catch (err) {
|
|
5900
|
+
if (typeof Intl === "undefined") {
|
|
5901
|
+
this.logger.error("No Intl support, please use an Intl polyfill!");
|
|
5902
|
+
return dummyRule;
|
|
5903
|
+
}
|
|
5904
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
5905
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
5906
|
+
rule = this.getRule(lngPart, options);
|
|
5907
|
+
}
|
|
5908
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
5909
|
+
return rule;
|
|
5910
|
+
}
|
|
5911
|
+
needsPlural(code, options = {}) {
|
|
5912
|
+
let rule = this.getRule(code, options);
|
|
5913
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
5914
|
+
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
5915
|
+
}
|
|
5916
|
+
getPluralFormsOfKey(code, key, options = {}) {
|
|
5917
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
5918
|
+
}
|
|
5919
|
+
getSuffixes(code, options = {}) {
|
|
5920
|
+
let rule = this.getRule(code, options);
|
|
5921
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
5922
|
+
if (!rule) return [];
|
|
5923
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
5924
|
+
}
|
|
5925
|
+
getSuffix(code, count, options = {}) {
|
|
5926
|
+
const rule = this.getRule(code, options);
|
|
5927
|
+
if (rule) return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
5928
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
5929
|
+
return this.getSuffix("dev", count, options);
|
|
5930
|
+
}
|
|
5931
|
+
};
|
|
5932
|
+
var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
|
|
5933
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
5934
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
5935
|
+
path = deepFind(data, key, keySeparator);
|
|
5936
|
+
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
5937
|
+
}
|
|
5938
|
+
return path;
|
|
5939
|
+
};
|
|
5940
|
+
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
5941
|
+
var Interpolator = class {
|
|
5942
|
+
constructor(options = {}) {
|
|
5943
|
+
this.logger = baseLogger.create("interpolator");
|
|
5944
|
+
this.options = options;
|
|
5945
|
+
this.format = options?.interpolation?.format || ((value) => value);
|
|
5946
|
+
this.init(options);
|
|
5947
|
+
}
|
|
5948
|
+
init(options = {}) {
|
|
5949
|
+
if (!options.interpolation) options.interpolation = { escapeValue: true };
|
|
5950
|
+
const { escape: escape$1, escapeValue, useRawValueToEscape, prefix, prefixEscaped, suffix, suffixEscaped, formatSeparator, unescapeSuffix, unescapePrefix, nestingPrefix, nestingPrefixEscaped, nestingSuffix, nestingSuffixEscaped, nestingOptionsSeparator, maxReplaces, alwaysFormat } = options.interpolation;
|
|
5951
|
+
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
5952
|
+
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
5953
|
+
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
5954
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
5955
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
5956
|
+
this.formatSeparator = formatSeparator || ",";
|
|
5957
|
+
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
|
|
5958
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
|
|
5959
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
5960
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
5961
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
5962
|
+
this.maxReplaces = maxReplaces || 1e3;
|
|
5963
|
+
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
5964
|
+
this.resetRegExp();
|
|
5965
|
+
}
|
|
5966
|
+
reset() {
|
|
5967
|
+
if (this.options) this.init(this.options);
|
|
5968
|
+
}
|
|
5969
|
+
resetRegExp() {
|
|
5970
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
5971
|
+
if (existingRegExp?.source === pattern) {
|
|
5972
|
+
existingRegExp.lastIndex = 0;
|
|
5973
|
+
return existingRegExp;
|
|
5974
|
+
}
|
|
5975
|
+
return new RegExp(pattern, "g");
|
|
5976
|
+
};
|
|
5977
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
5978
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
5979
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
|
|
5980
|
+
}
|
|
5981
|
+
interpolate(str, data, lng, options) {
|
|
5982
|
+
let match;
|
|
5983
|
+
let value;
|
|
5984
|
+
let replaces;
|
|
5985
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
5986
|
+
const handleFormat = (key) => {
|
|
5987
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
5988
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
5989
|
+
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
5990
|
+
...options,
|
|
5991
|
+
...data,
|
|
5992
|
+
interpolationkey: key
|
|
5993
|
+
}) : path;
|
|
5994
|
+
}
|
|
5995
|
+
const p = key.split(this.formatSeparator);
|
|
5996
|
+
const k = p.shift().trim();
|
|
5997
|
+
const f = p.join(this.formatSeparator).trim();
|
|
5998
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
5999
|
+
...options,
|
|
6000
|
+
...data,
|
|
6001
|
+
interpolationkey: k
|
|
6002
|
+
});
|
|
6003
|
+
};
|
|
6004
|
+
this.resetRegExp();
|
|
6005
|
+
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
6006
|
+
const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
6007
|
+
[{
|
|
6008
|
+
regex: this.regexpUnescape,
|
|
6009
|
+
safeValue: (val) => regexSafe(val)
|
|
6010
|
+
}, {
|
|
6011
|
+
regex: this.regexp,
|
|
6012
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
6013
|
+
}].forEach((todo) => {
|
|
6014
|
+
replaces = 0;
|
|
6015
|
+
while (match = todo.regex.exec(str)) {
|
|
6016
|
+
const matchedVar = match[1].trim();
|
|
6017
|
+
value = handleFormat(matchedVar);
|
|
6018
|
+
if (value === void 0) if (typeof missingInterpolationHandler === "function") {
|
|
6019
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
6020
|
+
value = isString(temp) ? temp : "";
|
|
6021
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) value = "";
|
|
6022
|
+
else if (skipOnVariables) {
|
|
6023
|
+
value = match[0];
|
|
6024
|
+
continue;
|
|
6025
|
+
} else {
|
|
6026
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
6027
|
+
value = "";
|
|
6028
|
+
}
|
|
6029
|
+
else if (!isString(value) && !this.useRawValueToEscape) value = makeString(value);
|
|
6030
|
+
const safeValue = todo.safeValue(value);
|
|
6031
|
+
str = str.replace(match[0], safeValue);
|
|
6032
|
+
if (skipOnVariables) {
|
|
6033
|
+
todo.regex.lastIndex += value.length;
|
|
6034
|
+
todo.regex.lastIndex -= match[0].length;
|
|
6035
|
+
} else todo.regex.lastIndex = 0;
|
|
6036
|
+
replaces++;
|
|
6037
|
+
if (replaces >= this.maxReplaces) break;
|
|
6038
|
+
}
|
|
6039
|
+
});
|
|
6040
|
+
return str;
|
|
6041
|
+
}
|
|
6042
|
+
nest(str, fc, options = {}) {
|
|
6043
|
+
let match;
|
|
6044
|
+
let value;
|
|
6045
|
+
let clonedOptions;
|
|
6046
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
6047
|
+
const sep = this.nestingOptionsSeparator;
|
|
6048
|
+
if (key.indexOf(sep) < 0) return key;
|
|
6049
|
+
const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
|
|
6050
|
+
let optionsString = `{${c[1]}`;
|
|
6051
|
+
key = c[0];
|
|
6052
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
6053
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
6054
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
6055
|
+
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || (matchedDoubleQuotes?.length ?? 0) % 2 !== 0) optionsString = optionsString.replace(/'/g, "\"");
|
|
6056
|
+
try {
|
|
6057
|
+
clonedOptions = JSON.parse(optionsString);
|
|
6058
|
+
if (inheritedOptions) clonedOptions = {
|
|
6059
|
+
...inheritedOptions,
|
|
6060
|
+
...clonedOptions
|
|
6061
|
+
};
|
|
6062
|
+
} catch (e) {
|
|
6063
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
6064
|
+
return `${key}${sep}${optionsString}`;
|
|
6065
|
+
}
|
|
6066
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
6067
|
+
return key;
|
|
6068
|
+
};
|
|
6069
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
6070
|
+
let formatters = [];
|
|
6071
|
+
clonedOptions = { ...options };
|
|
6072
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
6073
|
+
clonedOptions.applyPostProcessor = false;
|
|
6074
|
+
delete clonedOptions.defaultValue;
|
|
6075
|
+
const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
|
|
6076
|
+
if (keyEndIndex !== -1) {
|
|
6077
|
+
formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
|
|
6078
|
+
match[1] = match[1].slice(0, keyEndIndex);
|
|
6079
|
+
}
|
|
6080
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
6081
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
6082
|
+
if (!isString(value)) value = makeString(value);
|
|
6083
|
+
if (!value) {
|
|
6084
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
6085
|
+
value = "";
|
|
6086
|
+
}
|
|
6087
|
+
if (formatters.length) value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
6088
|
+
...options,
|
|
6089
|
+
interpolationkey: match[1].trim()
|
|
6090
|
+
}), value.trim());
|
|
6091
|
+
str = str.replace(match[0], value);
|
|
6092
|
+
this.regexp.lastIndex = 0;
|
|
6093
|
+
}
|
|
6094
|
+
return str;
|
|
6095
|
+
}
|
|
6096
|
+
};
|
|
6097
|
+
var parseFormatStr = (formatStr) => {
|
|
6098
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
6099
|
+
const formatOptions = {};
|
|
6100
|
+
if (formatStr.indexOf("(") > -1) {
|
|
6101
|
+
const p = formatStr.split("(");
|
|
6102
|
+
formatName = p[0].toLowerCase().trim();
|
|
6103
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
6104
|
+
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
6105
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
6106
|
+
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
6107
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
6108
|
+
} else optStr.split(";").forEach((opt) => {
|
|
6109
|
+
if (opt) {
|
|
6110
|
+
const [key, ...rest] = opt.split(":");
|
|
6111
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
6112
|
+
const trimmedKey = key.trim();
|
|
6113
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
6114
|
+
if (val === "false") formatOptions[trimmedKey] = false;
|
|
6115
|
+
if (val === "true") formatOptions[trimmedKey] = true;
|
|
6116
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
6117
|
+
}
|
|
6118
|
+
});
|
|
6119
|
+
}
|
|
6120
|
+
return {
|
|
6121
|
+
formatName,
|
|
6122
|
+
formatOptions
|
|
6123
|
+
};
|
|
6124
|
+
};
|
|
6125
|
+
var createCachedFormatter = (fn) => {
|
|
6126
|
+
const cache = {};
|
|
6127
|
+
return (v, l, o) => {
|
|
6128
|
+
let optForCache = o;
|
|
6129
|
+
if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) optForCache = {
|
|
6130
|
+
...optForCache,
|
|
6131
|
+
[o.interpolationkey]: void 0
|
|
6132
|
+
};
|
|
6133
|
+
const key = l + JSON.stringify(optForCache);
|
|
6134
|
+
let frm = cache[key];
|
|
6135
|
+
if (!frm) {
|
|
6136
|
+
frm = fn(getCleanedCode(l), o);
|
|
6137
|
+
cache[key] = frm;
|
|
6138
|
+
}
|
|
6139
|
+
return frm(v);
|
|
6140
|
+
};
|
|
6141
|
+
};
|
|
6142
|
+
var createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
6143
|
+
var Formatter = class {
|
|
6144
|
+
constructor(options = {}) {
|
|
6145
|
+
this.logger = baseLogger.create("formatter");
|
|
6146
|
+
this.options = options;
|
|
6147
|
+
this.init(options);
|
|
6148
|
+
}
|
|
6149
|
+
init(services, options = { interpolation: {} }) {
|
|
6150
|
+
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
6151
|
+
const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
6152
|
+
this.formats = {
|
|
6153
|
+
number: cf((lng, opt) => {
|
|
6154
|
+
const formatter = new Intl.NumberFormat(lng, { ...opt });
|
|
6155
|
+
return (val) => formatter.format(val);
|
|
6156
|
+
}),
|
|
6157
|
+
currency: cf((lng, opt) => {
|
|
6158
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
6159
|
+
...opt,
|
|
6160
|
+
style: "currency"
|
|
6161
|
+
});
|
|
6162
|
+
return (val) => formatter.format(val);
|
|
6163
|
+
}),
|
|
6164
|
+
datetime: cf((lng, opt) => {
|
|
6165
|
+
const formatter = new Intl.DateTimeFormat(lng, { ...opt });
|
|
6166
|
+
return (val) => formatter.format(val);
|
|
6167
|
+
}),
|
|
6168
|
+
relativetime: cf((lng, opt) => {
|
|
6169
|
+
const formatter = new Intl.RelativeTimeFormat(lng, { ...opt });
|
|
6170
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
6171
|
+
}),
|
|
6172
|
+
list: cf((lng, opt) => {
|
|
6173
|
+
const formatter = new Intl.ListFormat(lng, { ...opt });
|
|
6174
|
+
return (val) => formatter.format(val);
|
|
6175
|
+
})
|
|
6176
|
+
};
|
|
6177
|
+
}
|
|
6178
|
+
add(name, fc) {
|
|
6179
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
6180
|
+
}
|
|
6181
|
+
addCached(name, fc) {
|
|
6182
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
6183
|
+
}
|
|
6184
|
+
format(value, format, lng, options = {}) {
|
|
6185
|
+
const formats = format.split(this.formatSeparator);
|
|
6186
|
+
if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
|
|
6187
|
+
const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
|
|
6188
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
6189
|
+
}
|
|
6190
|
+
return formats.reduce((mem, f) => {
|
|
6191
|
+
const { formatName, formatOptions } = parseFormatStr(f);
|
|
6192
|
+
if (this.formats[formatName]) {
|
|
6193
|
+
let formatted = mem;
|
|
6194
|
+
try {
|
|
6195
|
+
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
6196
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
6197
|
+
formatted = this.formats[formatName](mem, l, {
|
|
6198
|
+
...formatOptions,
|
|
6199
|
+
...options,
|
|
6200
|
+
...valOptions
|
|
6201
|
+
});
|
|
6202
|
+
} catch (error) {
|
|
6203
|
+
this.logger.warn(error);
|
|
6204
|
+
}
|
|
6205
|
+
return formatted;
|
|
6206
|
+
} else this.logger.warn(`there was no format function for ${formatName}`);
|
|
6207
|
+
return mem;
|
|
6208
|
+
}, value);
|
|
6209
|
+
}
|
|
6210
|
+
};
|
|
6211
|
+
var removePending = (q, name) => {
|
|
6212
|
+
if (q.pending[name] !== void 0) {
|
|
6213
|
+
delete q.pending[name];
|
|
6214
|
+
q.pendingCount--;
|
|
6215
|
+
}
|
|
6216
|
+
};
|
|
6217
|
+
var Connector = class extends EventEmitter {
|
|
6218
|
+
constructor(backend, store, services, options = {}) {
|
|
6219
|
+
super();
|
|
6220
|
+
this.backend = backend;
|
|
6221
|
+
this.store = store;
|
|
6222
|
+
this.services = services;
|
|
6223
|
+
this.languageUtils = services.languageUtils;
|
|
6224
|
+
this.options = options;
|
|
6225
|
+
this.logger = baseLogger.create("backendConnector");
|
|
6226
|
+
this.waitingReads = [];
|
|
6227
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
6228
|
+
this.readingCalls = 0;
|
|
6229
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
6230
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
6231
|
+
this.state = {};
|
|
6232
|
+
this.queue = [];
|
|
6233
|
+
this.backend?.init?.(services, options.backend, options);
|
|
6234
|
+
}
|
|
6235
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
6236
|
+
const toLoad = {};
|
|
6237
|
+
const pending = {};
|
|
6238
|
+
const toLoadLanguages = {};
|
|
6239
|
+
const toLoadNamespaces = {};
|
|
6240
|
+
languages.forEach((lng) => {
|
|
6241
|
+
let hasAllNamespaces = true;
|
|
6242
|
+
namespaces.forEach((ns) => {
|
|
6243
|
+
const name = `${lng}|${ns}`;
|
|
6244
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) this.state[name] = 2;
|
|
6245
|
+
else if (this.state[name] < 0);
|
|
6246
|
+
else if (this.state[name] === 1) {
|
|
6247
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
6248
|
+
} else {
|
|
6249
|
+
this.state[name] = 1;
|
|
6250
|
+
hasAllNamespaces = false;
|
|
6251
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
6252
|
+
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
6253
|
+
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
6254
|
+
}
|
|
6255
|
+
});
|
|
6256
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
6257
|
+
});
|
|
6258
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) this.queue.push({
|
|
6259
|
+
pending,
|
|
6260
|
+
pendingCount: Object.keys(pending).length,
|
|
6261
|
+
loaded: {},
|
|
6262
|
+
errors: [],
|
|
6263
|
+
callback
|
|
6264
|
+
});
|
|
6265
|
+
return {
|
|
6266
|
+
toLoad: Object.keys(toLoad),
|
|
6267
|
+
pending: Object.keys(pending),
|
|
6268
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
6269
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
6270
|
+
};
|
|
6271
|
+
}
|
|
6272
|
+
loaded(name, err, data) {
|
|
6273
|
+
const s = name.split("|");
|
|
6274
|
+
const lng = s[0];
|
|
6275
|
+
const ns = s[1];
|
|
6276
|
+
if (err) this.emit("failedLoading", lng, ns, err);
|
|
6277
|
+
if (!err && data) this.store.addResourceBundle(lng, ns, data, void 0, void 0, { skipCopy: true });
|
|
6278
|
+
this.state[name] = err ? -1 : 2;
|
|
6279
|
+
if (err && data) this.state[name] = 0;
|
|
6280
|
+
const loaded = {};
|
|
6281
|
+
this.queue.forEach((q) => {
|
|
6282
|
+
pushPath(q.loaded, [lng], ns);
|
|
6283
|
+
removePending(q, name);
|
|
6284
|
+
if (err) q.errors.push(err);
|
|
6285
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
6286
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
6287
|
+
if (!loaded[l]) loaded[l] = {};
|
|
6288
|
+
const loadedKeys = q.loaded[l];
|
|
6289
|
+
if (loadedKeys.length) loadedKeys.forEach((n) => {
|
|
6290
|
+
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
6291
|
+
});
|
|
6292
|
+
});
|
|
6293
|
+
q.done = true;
|
|
6294
|
+
if (q.errors.length) q.callback(q.errors);
|
|
6295
|
+
else q.callback();
|
|
6296
|
+
}
|
|
6297
|
+
});
|
|
6298
|
+
this.emit("loaded", loaded);
|
|
6299
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
6300
|
+
}
|
|
6301
|
+
read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
|
|
6302
|
+
if (!lng.length) return callback(null, {});
|
|
6303
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
6304
|
+
this.waitingReads.push({
|
|
6305
|
+
lng,
|
|
6306
|
+
ns,
|
|
6307
|
+
fcName,
|
|
6308
|
+
tried,
|
|
6309
|
+
wait,
|
|
6310
|
+
callback
|
|
6311
|
+
});
|
|
6312
|
+
return;
|
|
6313
|
+
}
|
|
6314
|
+
this.readingCalls++;
|
|
6315
|
+
const resolver = (err, data) => {
|
|
6316
|
+
this.readingCalls--;
|
|
6317
|
+
if (this.waitingReads.length > 0) {
|
|
6318
|
+
const next = this.waitingReads.shift();
|
|
6319
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
6320
|
+
}
|
|
6321
|
+
if (err && data && tried < this.maxRetries) {
|
|
6322
|
+
setTimeout(() => {
|
|
6323
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
6324
|
+
}, wait);
|
|
6325
|
+
return;
|
|
6326
|
+
}
|
|
6327
|
+
callback(err, data);
|
|
6328
|
+
};
|
|
6329
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
6330
|
+
if (fc.length === 2) {
|
|
6331
|
+
try {
|
|
6332
|
+
const r = fc(lng, ns);
|
|
6333
|
+
if (r && typeof r.then === "function") r.then((data) => resolver(null, data)).catch(resolver);
|
|
6334
|
+
else resolver(null, r);
|
|
6335
|
+
} catch (err) {
|
|
6336
|
+
resolver(err);
|
|
6337
|
+
}
|
|
6338
|
+
return;
|
|
6339
|
+
}
|
|
6340
|
+
return fc(lng, ns, resolver);
|
|
6341
|
+
}
|
|
6342
|
+
prepareLoading(languages, namespaces, options = {}, callback) {
|
|
6343
|
+
if (!this.backend) {
|
|
6344
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
6345
|
+
return callback && callback();
|
|
6346
|
+
}
|
|
6347
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
6348
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
6349
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
6350
|
+
if (!toLoad.toLoad.length) {
|
|
6351
|
+
if (!toLoad.pending.length) callback();
|
|
6352
|
+
return null;
|
|
6353
|
+
}
|
|
6354
|
+
toLoad.toLoad.forEach((name) => {
|
|
6355
|
+
this.loadOne(name);
|
|
6356
|
+
});
|
|
6357
|
+
}
|
|
6358
|
+
load(languages, namespaces, callback) {
|
|
6359
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
6360
|
+
}
|
|
6361
|
+
reload(languages, namespaces, callback) {
|
|
6362
|
+
this.prepareLoading(languages, namespaces, { reload: true }, callback);
|
|
6363
|
+
}
|
|
6364
|
+
loadOne(name, prefix = "") {
|
|
6365
|
+
const s = name.split("|");
|
|
6366
|
+
const lng = s[0];
|
|
6367
|
+
const ns = s[1];
|
|
6368
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
6369
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
6370
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
6371
|
+
this.loaded(name, err, data);
|
|
6372
|
+
});
|
|
6373
|
+
}
|
|
6374
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
|
|
6375
|
+
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
6376
|
+
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!!!");
|
|
6377
|
+
return;
|
|
6378
|
+
}
|
|
6379
|
+
if (key === void 0 || key === null || key === "") return;
|
|
6380
|
+
if (this.backend?.create) {
|
|
6381
|
+
const opts = {
|
|
6382
|
+
...options,
|
|
6383
|
+
isUpdate
|
|
6384
|
+
};
|
|
6385
|
+
const fc = this.backend.create.bind(this.backend);
|
|
6386
|
+
if (fc.length < 6) try {
|
|
6387
|
+
let r;
|
|
6388
|
+
if (fc.length === 5) r = fc(languages, namespace, key, fallbackValue, opts);
|
|
6389
|
+
else r = fc(languages, namespace, key, fallbackValue);
|
|
6390
|
+
if (r && typeof r.then === "function") r.then((data) => clb(null, data)).catch(clb);
|
|
6391
|
+
else clb(null, r);
|
|
6392
|
+
} catch (err) {
|
|
6393
|
+
clb(err);
|
|
6394
|
+
}
|
|
6395
|
+
else fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
6396
|
+
}
|
|
6397
|
+
if (!languages || !languages[0]) return;
|
|
6398
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
6399
|
+
}
|
|
6400
|
+
};
|
|
6401
|
+
var get = () => ({
|
|
6402
|
+
debug: false,
|
|
6403
|
+
initAsync: true,
|
|
6404
|
+
ns: ["translation"],
|
|
6405
|
+
defaultNS: ["translation"],
|
|
6406
|
+
fallbackLng: ["dev"],
|
|
6407
|
+
fallbackNS: false,
|
|
6408
|
+
supportedLngs: false,
|
|
6409
|
+
nonExplicitSupportedLngs: false,
|
|
6410
|
+
load: "all",
|
|
6411
|
+
preload: false,
|
|
6412
|
+
simplifyPluralSuffix: true,
|
|
6413
|
+
keySeparator: ".",
|
|
6414
|
+
nsSeparator: ":",
|
|
6415
|
+
pluralSeparator: "_",
|
|
6416
|
+
contextSeparator: "_",
|
|
6417
|
+
partialBundledLanguages: false,
|
|
6418
|
+
saveMissing: false,
|
|
6419
|
+
updateMissing: false,
|
|
6420
|
+
saveMissingTo: "fallback",
|
|
6421
|
+
saveMissingPlurals: true,
|
|
6422
|
+
missingKeyHandler: false,
|
|
6423
|
+
missingInterpolationHandler: false,
|
|
6424
|
+
postProcess: false,
|
|
6425
|
+
postProcessPassResolved: false,
|
|
6426
|
+
returnNull: false,
|
|
6427
|
+
returnEmptyString: true,
|
|
6428
|
+
returnObjects: false,
|
|
6429
|
+
joinArrays: false,
|
|
6430
|
+
returnedObjectHandler: false,
|
|
6431
|
+
parseMissingKeyHandler: false,
|
|
6432
|
+
appendNamespaceToMissingKey: false,
|
|
6433
|
+
appendNamespaceToCIMode: false,
|
|
6434
|
+
overloadTranslationOptionHandler: (args) => {
|
|
6435
|
+
let ret = {};
|
|
6436
|
+
if (typeof args[1] === "object") ret = args[1];
|
|
6437
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
6438
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
6439
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
6440
|
+
const options = args[3] || args[2];
|
|
6441
|
+
Object.keys(options).forEach((key) => {
|
|
6442
|
+
ret[key] = options[key];
|
|
6443
|
+
});
|
|
6444
|
+
}
|
|
6445
|
+
return ret;
|
|
6446
|
+
},
|
|
6447
|
+
interpolation: {
|
|
6448
|
+
escapeValue: true,
|
|
6449
|
+
format: (value) => value,
|
|
6450
|
+
prefix: "{{",
|
|
6451
|
+
suffix: "}}",
|
|
6452
|
+
formatSeparator: ",",
|
|
6453
|
+
unescapePrefix: "-",
|
|
6454
|
+
nestingPrefix: "$t(",
|
|
6455
|
+
nestingSuffix: ")",
|
|
6456
|
+
nestingOptionsSeparator: ",",
|
|
6457
|
+
maxReplaces: 1e3,
|
|
6458
|
+
skipOnVariables: true
|
|
6459
|
+
},
|
|
6460
|
+
cacheInBuiltFormats: true
|
|
6461
|
+
});
|
|
6462
|
+
var transformOptions = (options) => {
|
|
6463
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
6464
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
6465
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
6466
|
+
if (options.supportedLngs?.indexOf?.("cimode") < 0) options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
6467
|
+
if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
|
|
6468
|
+
return options;
|
|
6469
|
+
};
|
|
6470
|
+
var noop = () => {};
|
|
6471
|
+
var bindMemberFunctions = (inst) => {
|
|
6472
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(inst)).forEach((mem) => {
|
|
6473
|
+
if (typeof inst[mem] === "function") inst[mem] = inst[mem].bind(inst);
|
|
6474
|
+
});
|
|
6475
|
+
};
|
|
6476
|
+
var SUPPORT_NOTICE_KEY = "__i18next_supportNoticeShown";
|
|
6477
|
+
var getSupportNoticeShown = () => {
|
|
6478
|
+
if (typeof globalThis !== "undefined" && !!globalThis[SUPPORT_NOTICE_KEY]) return true;
|
|
6479
|
+
if (typeof process !== "undefined" && process.env && process.env.I18NEXT_NO_SUPPORT_NOTICE) return true;
|
|
6480
|
+
if (typeof process !== "undefined" && process.env && process.env.NODE_ENV === "production") return true;
|
|
6481
|
+
return false;
|
|
6482
|
+
};
|
|
6483
|
+
var setSupportNoticeShown = () => {
|
|
6484
|
+
if (typeof globalThis !== "undefined") globalThis[SUPPORT_NOTICE_KEY] = true;
|
|
6485
|
+
};
|
|
6486
|
+
var usesLocize = (inst) => {
|
|
6487
|
+
if (inst?.modules?.backend?.name?.indexOf("Locize") > 0) return true;
|
|
6488
|
+
if (inst?.modules?.backend?.constructor?.name?.indexOf("Locize") > 0) return true;
|
|
6489
|
+
if (inst?.options?.backend?.backends) {
|
|
6490
|
+
if (inst.options.backend.backends.some((b) => b?.name?.indexOf("Locize") > 0 || b?.constructor?.name?.indexOf("Locize") > 0)) return true;
|
|
6491
|
+
}
|
|
6492
|
+
if (inst?.options?.backend?.projectId) return true;
|
|
6493
|
+
if (inst?.options?.backend?.backendOptions) {
|
|
6494
|
+
if (inst.options.backend.backendOptions.some((b) => b?.projectId)) return true;
|
|
6495
|
+
}
|
|
6496
|
+
return false;
|
|
6497
|
+
};
|
|
6498
|
+
var instance = class I18n extends EventEmitter {
|
|
6499
|
+
constructor(options = {}, callback) {
|
|
6500
|
+
super();
|
|
6501
|
+
this.options = transformOptions(options);
|
|
6502
|
+
this.services = {};
|
|
6503
|
+
this.logger = baseLogger;
|
|
6504
|
+
this.modules = { external: [] };
|
|
6505
|
+
bindMemberFunctions(this);
|
|
6506
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
6507
|
+
if (!this.options.initAsync) {
|
|
6508
|
+
this.init(options, callback);
|
|
6509
|
+
return this;
|
|
6510
|
+
}
|
|
6511
|
+
setTimeout(() => {
|
|
6512
|
+
this.init(options, callback);
|
|
6513
|
+
}, 0);
|
|
6514
|
+
}
|
|
6515
|
+
}
|
|
6516
|
+
init(options = {}, callback) {
|
|
6517
|
+
this.isInitializing = true;
|
|
6518
|
+
if (typeof options === "function") {
|
|
6519
|
+
callback = options;
|
|
6520
|
+
options = {};
|
|
6521
|
+
}
|
|
6522
|
+
if (options.defaultNS == null && options.ns) {
|
|
6523
|
+
if (isString(options.ns)) options.defaultNS = options.ns;
|
|
6524
|
+
else if (options.ns.indexOf("translation") < 0) options.defaultNS = options.ns[0];
|
|
6525
|
+
}
|
|
6526
|
+
const defOpts = get();
|
|
6527
|
+
this.options = {
|
|
6528
|
+
...defOpts,
|
|
6529
|
+
...this.options,
|
|
6530
|
+
...transformOptions(options)
|
|
6531
|
+
};
|
|
6532
|
+
this.options.interpolation = {
|
|
6533
|
+
...defOpts.interpolation,
|
|
6534
|
+
...this.options.interpolation
|
|
6535
|
+
};
|
|
6536
|
+
if (options.keySeparator !== void 0) this.options.userDefinedKeySeparator = options.keySeparator;
|
|
6537
|
+
if (options.nsSeparator !== void 0) this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
6538
|
+
if (typeof this.options.overloadTranslationOptionHandler !== "function") this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
|
|
6539
|
+
if (this.options.showSupportNotice !== false && !usesLocize(this) && !getSupportNoticeShown()) {
|
|
6540
|
+
if (typeof console !== "undefined" && typeof console.info !== "undefined") console.info("🌐 i18next is made possible by our own product, Locize — consider powering your project with managed localization (AI, CDN, integrations): https://locize.com 💙");
|
|
6541
|
+
setSupportNoticeShown();
|
|
6542
|
+
}
|
|
6543
|
+
const createClassOnDemand = (ClassOrObject) => {
|
|
6544
|
+
if (!ClassOrObject) return null;
|
|
6545
|
+
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
6546
|
+
return ClassOrObject;
|
|
6547
|
+
};
|
|
6548
|
+
if (!this.options.isClone) {
|
|
6549
|
+
if (this.modules.logger) baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
6550
|
+
else baseLogger.init(null, this.options);
|
|
6551
|
+
let formatter;
|
|
6552
|
+
if (this.modules.formatter) formatter = this.modules.formatter;
|
|
6553
|
+
else formatter = Formatter;
|
|
6554
|
+
const lu = new LanguageUtil(this.options);
|
|
6555
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
6556
|
+
const s = this.services;
|
|
6557
|
+
s.logger = baseLogger;
|
|
6558
|
+
s.resourceStore = this.store;
|
|
6559
|
+
s.languageUtils = lu;
|
|
6560
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
6561
|
+
prepend: this.options.pluralSeparator,
|
|
6562
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
6563
|
+
});
|
|
6564
|
+
if (this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format) this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
|
|
6565
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
6566
|
+
s.formatter = createClassOnDemand(formatter);
|
|
6567
|
+
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
6568
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
6569
|
+
}
|
|
6570
|
+
s.interpolator = new Interpolator(this.options);
|
|
6571
|
+
s.utils = { hasLoadedNamespace: this.hasLoadedNamespace.bind(this) };
|
|
6572
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
6573
|
+
s.backendConnector.on("*", (event, ...args) => {
|
|
6574
|
+
this.emit(event, ...args);
|
|
6575
|
+
});
|
|
6576
|
+
if (this.modules.languageDetector) {
|
|
6577
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
6578
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
6579
|
+
}
|
|
6580
|
+
if (this.modules.i18nFormat) {
|
|
6581
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
6582
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
6583
|
+
}
|
|
6584
|
+
this.translator = new Translator(this.services, this.options);
|
|
6585
|
+
this.translator.on("*", (event, ...args) => {
|
|
6586
|
+
this.emit(event, ...args);
|
|
6587
|
+
});
|
|
6588
|
+
this.modules.external.forEach((m) => {
|
|
6589
|
+
if (m.init) m.init(this);
|
|
6590
|
+
});
|
|
6591
|
+
}
|
|
6592
|
+
this.format = this.options.interpolation.format;
|
|
6593
|
+
if (!callback) callback = noop;
|
|
6594
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
6595
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
6596
|
+
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
6597
|
+
}
|
|
6598
|
+
if (!this.services.languageDetector && !this.options.lng) this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
6599
|
+
[
|
|
6600
|
+
"getResource",
|
|
6601
|
+
"hasResourceBundle",
|
|
6602
|
+
"getResourceBundle",
|
|
6603
|
+
"getDataByLanguage"
|
|
6604
|
+
].forEach((fcName) => {
|
|
6605
|
+
this[fcName] = (...args) => this.store[fcName](...args);
|
|
6606
|
+
});
|
|
6607
|
+
[
|
|
6608
|
+
"addResource",
|
|
6609
|
+
"addResources",
|
|
6610
|
+
"addResourceBundle",
|
|
6611
|
+
"removeResourceBundle"
|
|
6612
|
+
].forEach((fcName) => {
|
|
6613
|
+
this[fcName] = (...args) => {
|
|
6614
|
+
this.store[fcName](...args);
|
|
6615
|
+
return this;
|
|
6616
|
+
};
|
|
6617
|
+
});
|
|
6618
|
+
const deferred = defer();
|
|
6619
|
+
const load = () => {
|
|
6620
|
+
const finish = (err, t) => {
|
|
6621
|
+
this.isInitializing = false;
|
|
6622
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
6623
|
+
this.isInitialized = true;
|
|
6624
|
+
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
6625
|
+
this.emit("initialized", this.options);
|
|
6626
|
+
deferred.resolve(t);
|
|
6627
|
+
callback(err, t);
|
|
6628
|
+
};
|
|
6629
|
+
if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
6630
|
+
this.changeLanguage(this.options.lng, finish);
|
|
6631
|
+
};
|
|
6632
|
+
if (this.options.resources || !this.options.initAsync) load();
|
|
6633
|
+
else setTimeout(load, 0);
|
|
6634
|
+
return deferred;
|
|
6635
|
+
}
|
|
6636
|
+
loadResources(language, callback = noop) {
|
|
6637
|
+
let usedCallback = callback;
|
|
6638
|
+
const usedLng = isString(language) ? language : this.language;
|
|
6639
|
+
if (typeof language === "function") usedCallback = language;
|
|
6640
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
6641
|
+
if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
6642
|
+
const toLoad = [];
|
|
6643
|
+
const append = (lng) => {
|
|
6644
|
+
if (!lng) return;
|
|
6645
|
+
if (lng === "cimode") return;
|
|
6646
|
+
this.services.languageUtils.toResolveHierarchy(lng).forEach((l) => {
|
|
6647
|
+
if (l === "cimode") return;
|
|
6648
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
6649
|
+
});
|
|
6650
|
+
};
|
|
6651
|
+
if (!usedLng) this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach((l) => append(l));
|
|
6652
|
+
else append(usedLng);
|
|
6653
|
+
this.options.preload?.forEach?.((l) => append(l));
|
|
6654
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
6655
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
6656
|
+
usedCallback(e);
|
|
6657
|
+
});
|
|
6658
|
+
} else usedCallback(null);
|
|
6659
|
+
}
|
|
6660
|
+
reloadResources(lngs, ns, callback) {
|
|
6661
|
+
const deferred = defer();
|
|
6662
|
+
if (typeof lngs === "function") {
|
|
6663
|
+
callback = lngs;
|
|
6664
|
+
lngs = void 0;
|
|
6665
|
+
}
|
|
6666
|
+
if (typeof ns === "function") {
|
|
6667
|
+
callback = ns;
|
|
6668
|
+
ns = void 0;
|
|
6669
|
+
}
|
|
6670
|
+
if (!lngs) lngs = this.languages;
|
|
6671
|
+
if (!ns) ns = this.options.ns;
|
|
6672
|
+
if (!callback) callback = noop;
|
|
6673
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
6674
|
+
deferred.resolve();
|
|
6675
|
+
callback(err);
|
|
6676
|
+
});
|
|
6677
|
+
return deferred;
|
|
6678
|
+
}
|
|
6679
|
+
use(module) {
|
|
6680
|
+
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
6681
|
+
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
6682
|
+
if (module.type === "backend") this.modules.backend = module;
|
|
6683
|
+
if (module.type === "logger" || module.log && module.warn && module.error) this.modules.logger = module;
|
|
6684
|
+
if (module.type === "languageDetector") this.modules.languageDetector = module;
|
|
6685
|
+
if (module.type === "i18nFormat") this.modules.i18nFormat = module;
|
|
6686
|
+
if (module.type === "postProcessor") postProcessor.addPostProcessor(module);
|
|
6687
|
+
if (module.type === "formatter") this.modules.formatter = module;
|
|
6688
|
+
if (module.type === "3rdParty") this.modules.external.push(module);
|
|
6689
|
+
return this;
|
|
6690
|
+
}
|
|
6691
|
+
setResolvedLanguage(l) {
|
|
6692
|
+
if (!l || !this.languages) return;
|
|
6693
|
+
if (["cimode", "dev"].indexOf(l) > -1) return;
|
|
6694
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
6695
|
+
const lngInLngs = this.languages[li];
|
|
6696
|
+
if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
|
|
6697
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
6698
|
+
this.resolvedLanguage = lngInLngs;
|
|
6699
|
+
break;
|
|
6700
|
+
}
|
|
6701
|
+
}
|
|
6702
|
+
if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
|
|
6703
|
+
this.resolvedLanguage = l;
|
|
6704
|
+
this.languages.unshift(l);
|
|
6705
|
+
}
|
|
6706
|
+
}
|
|
6707
|
+
changeLanguage(lng, callback) {
|
|
6708
|
+
this.isLanguageChangingTo = lng;
|
|
6709
|
+
const deferred = defer();
|
|
6710
|
+
this.emit("languageChanging", lng);
|
|
6711
|
+
const setLngProps = (l) => {
|
|
6712
|
+
this.language = l;
|
|
6713
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
6714
|
+
this.resolvedLanguage = void 0;
|
|
6715
|
+
this.setResolvedLanguage(l);
|
|
6716
|
+
};
|
|
6717
|
+
const done = (err, l) => {
|
|
6718
|
+
if (l) {
|
|
6719
|
+
if (this.isLanguageChangingTo === lng) {
|
|
6720
|
+
setLngProps(l);
|
|
6721
|
+
this.translator.changeLanguage(l);
|
|
6722
|
+
this.isLanguageChangingTo = void 0;
|
|
6723
|
+
this.emit("languageChanged", l);
|
|
6724
|
+
this.logger.log("languageChanged", l);
|
|
6725
|
+
}
|
|
6726
|
+
} else this.isLanguageChangingTo = void 0;
|
|
6727
|
+
deferred.resolve((...args) => this.t(...args));
|
|
6728
|
+
if (callback) callback(err, (...args) => this.t(...args));
|
|
6729
|
+
};
|
|
6730
|
+
const setLng = (lngs) => {
|
|
6731
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
6732
|
+
const fl = isString(lngs) ? lngs : lngs && lngs[0];
|
|
6733
|
+
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
6734
|
+
if (l) {
|
|
6735
|
+
if (!this.language) setLngProps(l);
|
|
6736
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
6737
|
+
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
6738
|
+
}
|
|
6739
|
+
this.loadResources(l, (err) => {
|
|
6740
|
+
done(err, l);
|
|
6741
|
+
});
|
|
6742
|
+
};
|
|
6743
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) setLng(this.services.languageDetector.detect());
|
|
6744
|
+
else if (!lng && this.services.languageDetector && this.services.languageDetector.async) if (this.services.languageDetector.detect.length === 0) this.services.languageDetector.detect().then(setLng);
|
|
6745
|
+
else this.services.languageDetector.detect(setLng);
|
|
6746
|
+
else setLng(lng);
|
|
6747
|
+
return deferred;
|
|
6748
|
+
}
|
|
6749
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
6750
|
+
const fixedT = (key, opts, ...rest) => {
|
|
6751
|
+
let o;
|
|
6752
|
+
if (typeof opts !== "object") o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
6753
|
+
else o = { ...opts };
|
|
6754
|
+
o.lng = o.lng || fixedT.lng;
|
|
6755
|
+
o.lngs = o.lngs || fixedT.lngs;
|
|
6756
|
+
o.ns = o.ns || fixedT.ns;
|
|
6757
|
+
if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
6758
|
+
const selectorOpts = {
|
|
6759
|
+
...this.options,
|
|
6760
|
+
...o
|
|
6761
|
+
};
|
|
6762
|
+
if (typeof o.keyPrefix === "function") o.keyPrefix = keysFromSelector(o.keyPrefix, selectorOpts);
|
|
6763
|
+
const keySeparator = this.options.keySeparator || ".";
|
|
6764
|
+
let resultKey;
|
|
6765
|
+
if (o.keyPrefix && Array.isArray(key)) resultKey = key.map((k) => {
|
|
6766
|
+
if (typeof k === "function") k = keysFromSelector(k, selectorOpts);
|
|
6767
|
+
return `${o.keyPrefix}${keySeparator}${k}`;
|
|
6768
|
+
});
|
|
6769
|
+
else {
|
|
6770
|
+
if (typeof key === "function") key = keysFromSelector(key, selectorOpts);
|
|
6771
|
+
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
6772
|
+
}
|
|
6773
|
+
return this.t(resultKey, o);
|
|
6774
|
+
};
|
|
6775
|
+
if (isString(lng)) fixedT.lng = lng;
|
|
6776
|
+
else fixedT.lngs = lng;
|
|
6777
|
+
fixedT.ns = ns;
|
|
6778
|
+
fixedT.keyPrefix = keyPrefix;
|
|
6779
|
+
return fixedT;
|
|
6780
|
+
}
|
|
6781
|
+
t(...args) {
|
|
6782
|
+
return this.translator?.translate(...args);
|
|
6783
|
+
}
|
|
6784
|
+
exists(...args) {
|
|
6785
|
+
return this.translator?.exists(...args);
|
|
6786
|
+
}
|
|
6787
|
+
setDefaultNamespace(ns) {
|
|
6788
|
+
this.options.defaultNS = ns;
|
|
6789
|
+
}
|
|
6790
|
+
hasLoadedNamespace(ns, options = {}) {
|
|
6791
|
+
if (!this.isInitialized) {
|
|
6792
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
6793
|
+
return false;
|
|
6794
|
+
}
|
|
6795
|
+
if (!this.languages || !this.languages.length) {
|
|
6796
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
6797
|
+
return false;
|
|
6798
|
+
}
|
|
6799
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
6800
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
6801
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
6802
|
+
if (lng.toLowerCase() === "cimode") return true;
|
|
6803
|
+
const loadNotPending = (l, n) => {
|
|
6804
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
6805
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
6806
|
+
};
|
|
6807
|
+
if (options.precheck) {
|
|
6808
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
6809
|
+
if (preResult !== void 0) return preResult;
|
|
6810
|
+
}
|
|
6811
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
6812
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
6813
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
6814
|
+
return false;
|
|
6815
|
+
}
|
|
6816
|
+
loadNamespaces(ns, callback) {
|
|
6817
|
+
const deferred = defer();
|
|
6818
|
+
if (!this.options.ns) {
|
|
6819
|
+
if (callback) callback();
|
|
6820
|
+
return Promise.resolve();
|
|
6821
|
+
}
|
|
6822
|
+
if (isString(ns)) ns = [ns];
|
|
6823
|
+
ns.forEach((n) => {
|
|
6824
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
6825
|
+
});
|
|
6826
|
+
this.loadResources((err) => {
|
|
6827
|
+
deferred.resolve();
|
|
6828
|
+
if (callback) callback(err);
|
|
6829
|
+
});
|
|
6830
|
+
return deferred;
|
|
6831
|
+
}
|
|
6832
|
+
loadLanguages(lngs, callback) {
|
|
6833
|
+
const deferred = defer();
|
|
6834
|
+
if (isString(lngs)) lngs = [lngs];
|
|
6835
|
+
const preloaded = this.options.preload || [];
|
|
6836
|
+
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
6837
|
+
if (!newLngs.length) {
|
|
6838
|
+
if (callback) callback();
|
|
6839
|
+
return Promise.resolve();
|
|
6840
|
+
}
|
|
6841
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
6842
|
+
this.loadResources((err) => {
|
|
6843
|
+
deferred.resolve();
|
|
6844
|
+
if (callback) callback(err);
|
|
6845
|
+
});
|
|
6846
|
+
return deferred;
|
|
6847
|
+
}
|
|
6848
|
+
dir(lng) {
|
|
6849
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
6850
|
+
if (!lng) return "rtl";
|
|
6851
|
+
try {
|
|
6852
|
+
const l = new Intl.Locale(lng);
|
|
6853
|
+
if (l && l.getTextInfo) {
|
|
6854
|
+
const ti = l.getTextInfo();
|
|
6855
|
+
if (ti && ti.direction) return ti.direction;
|
|
6856
|
+
}
|
|
6857
|
+
} catch (e) {}
|
|
6858
|
+
const rtlLngs = [
|
|
6859
|
+
"ar",
|
|
6860
|
+
"shu",
|
|
6861
|
+
"sqr",
|
|
6862
|
+
"ssh",
|
|
6863
|
+
"xaa",
|
|
6864
|
+
"yhd",
|
|
6865
|
+
"yud",
|
|
6866
|
+
"aao",
|
|
6867
|
+
"abh",
|
|
6868
|
+
"abv",
|
|
6869
|
+
"acm",
|
|
6870
|
+
"acq",
|
|
6871
|
+
"acw",
|
|
6872
|
+
"acx",
|
|
6873
|
+
"acy",
|
|
6874
|
+
"adf",
|
|
6875
|
+
"ads",
|
|
6876
|
+
"aeb",
|
|
6877
|
+
"aec",
|
|
6878
|
+
"afb",
|
|
6879
|
+
"ajp",
|
|
6880
|
+
"apc",
|
|
6881
|
+
"apd",
|
|
6882
|
+
"arb",
|
|
6883
|
+
"arq",
|
|
6884
|
+
"ars",
|
|
6885
|
+
"ary",
|
|
6886
|
+
"arz",
|
|
6887
|
+
"auz",
|
|
6888
|
+
"avl",
|
|
6889
|
+
"ayh",
|
|
6890
|
+
"ayl",
|
|
6891
|
+
"ayn",
|
|
6892
|
+
"ayp",
|
|
6893
|
+
"bbz",
|
|
6894
|
+
"pga",
|
|
6895
|
+
"he",
|
|
6896
|
+
"iw",
|
|
6897
|
+
"ps",
|
|
6898
|
+
"pbt",
|
|
6899
|
+
"pbu",
|
|
6900
|
+
"pst",
|
|
6901
|
+
"prp",
|
|
6902
|
+
"prd",
|
|
6903
|
+
"ug",
|
|
6904
|
+
"ur",
|
|
6905
|
+
"ydd",
|
|
6906
|
+
"yds",
|
|
6907
|
+
"yih",
|
|
6908
|
+
"ji",
|
|
6909
|
+
"yi",
|
|
6910
|
+
"hbo",
|
|
6911
|
+
"men",
|
|
6912
|
+
"xmn",
|
|
6913
|
+
"fa",
|
|
6914
|
+
"jpr",
|
|
6915
|
+
"peo",
|
|
6916
|
+
"pes",
|
|
6917
|
+
"prs",
|
|
6918
|
+
"dv",
|
|
6919
|
+
"sam",
|
|
6920
|
+
"ckb"
|
|
6921
|
+
];
|
|
6922
|
+
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
6923
|
+
if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
|
|
6924
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
6925
|
+
}
|
|
6926
|
+
static createInstance(options = {}, callback) {
|
|
6927
|
+
const instance = new I18n(options, callback);
|
|
6928
|
+
instance.createInstance = I18n.createInstance;
|
|
6929
|
+
return instance;
|
|
6930
|
+
}
|
|
6931
|
+
cloneInstance(options = {}, callback = noop) {
|
|
6932
|
+
const forkResourceStore = options.forkResourceStore;
|
|
6933
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
6934
|
+
const mergedOptions = {
|
|
6935
|
+
...this.options,
|
|
6936
|
+
...options,
|
|
6937
|
+
isClone: true
|
|
6938
|
+
};
|
|
6939
|
+
const clone = new I18n(mergedOptions);
|
|
6940
|
+
if (options.debug !== void 0 || options.prefix !== void 0) clone.logger = clone.logger.clone(options);
|
|
6941
|
+
[
|
|
6942
|
+
"store",
|
|
6943
|
+
"services",
|
|
6944
|
+
"language"
|
|
6945
|
+
].forEach((m) => {
|
|
6946
|
+
clone[m] = this[m];
|
|
6947
|
+
});
|
|
6948
|
+
clone.services = { ...this.services };
|
|
6949
|
+
clone.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
|
|
6950
|
+
if (forkResourceStore) {
|
|
6951
|
+
clone.store = new ResourceStore(Object.keys(this.store.data).reduce((prev, l) => {
|
|
6952
|
+
prev[l] = { ...this.store.data[l] };
|
|
6953
|
+
prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
|
|
6954
|
+
acc[n] = { ...prev[l][n] };
|
|
6955
|
+
return acc;
|
|
6956
|
+
}, prev[l]);
|
|
6957
|
+
return prev;
|
|
6958
|
+
}, {}), mergedOptions);
|
|
6959
|
+
clone.services.resourceStore = clone.store;
|
|
6960
|
+
}
|
|
6961
|
+
if (options.interpolation) {
|
|
6962
|
+
const mergedInterpolation = {
|
|
6963
|
+
...get().interpolation,
|
|
6964
|
+
...this.options.interpolation,
|
|
6965
|
+
...options.interpolation
|
|
6966
|
+
};
|
|
6967
|
+
const mergedForInterpolator = {
|
|
6968
|
+
...mergedOptions,
|
|
6969
|
+
interpolation: mergedInterpolation
|
|
6970
|
+
};
|
|
6971
|
+
clone.services.interpolator = new Interpolator(mergedForInterpolator);
|
|
6972
|
+
}
|
|
6973
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
6974
|
+
clone.translator.on("*", (event, ...args) => {
|
|
6975
|
+
clone.emit(event, ...args);
|
|
6976
|
+
});
|
|
6977
|
+
clone.init(mergedOptions, callback);
|
|
6978
|
+
clone.translator.options = mergedOptions;
|
|
6979
|
+
clone.translator.backendConnector.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
|
|
6980
|
+
return clone;
|
|
6981
|
+
}
|
|
6982
|
+
toJSON() {
|
|
6983
|
+
return {
|
|
6984
|
+
options: this.options,
|
|
6985
|
+
store: this.store,
|
|
6986
|
+
language: this.language,
|
|
6987
|
+
languages: this.languages,
|
|
6988
|
+
resolvedLanguage: this.resolvedLanguage
|
|
6989
|
+
};
|
|
6990
|
+
}
|
|
6991
|
+
}.createInstance();
|
|
6992
|
+
instance.createInstance;
|
|
6993
|
+
instance.dir;
|
|
6994
|
+
instance.init;
|
|
6995
|
+
instance.loadResources;
|
|
6996
|
+
instance.reloadResources;
|
|
6997
|
+
instance.use;
|
|
6998
|
+
instance.changeLanguage;
|
|
6999
|
+
instance.getFixedT;
|
|
7000
|
+
instance.t;
|
|
7001
|
+
instance.exists;
|
|
7002
|
+
instance.setDefaultNamespace;
|
|
7003
|
+
instance.hasLoadedNamespace;
|
|
7004
|
+
instance.loadNamespaces;
|
|
7005
|
+
instance.loadLanguages;
|
|
7006
|
+
//#endregion
|
|
7007
|
+
//#region ../../shared/translator/dist/index.js
|
|
7008
|
+
instance.init({
|
|
7009
|
+
fallbackLng: "en",
|
|
7010
|
+
lng: "en",
|
|
7011
|
+
showSupportNotice: !1,
|
|
7012
|
+
resources: {
|
|
7013
|
+
en: e$1,
|
|
7014
|
+
es: e
|
|
7015
|
+
}
|
|
7016
|
+
});
|
|
7017
|
+
//#endregion
|
|
7018
|
+
//#region src/i18n.ts
|
|
7019
|
+
var { translator } = {
|
|
7020
|
+
translator: {
|
|
7021
|
+
...instance,
|
|
7022
|
+
t: (e, t) => {
|
|
7023
|
+
let { lng: r } = t;
|
|
7024
|
+
switch (r) {
|
|
7025
|
+
case "en_US":
|
|
7026
|
+
case "en-US":
|
|
7027
|
+
t.lng = "en";
|
|
7028
|
+
break;
|
|
7029
|
+
case "es_ES":
|
|
7030
|
+
case "es-ES":
|
|
7031
|
+
case "es_MX":
|
|
7032
|
+
case "es-MX":
|
|
7033
|
+
t.lng = "es";
|
|
7034
|
+
break;
|
|
7035
|
+
default: break;
|
|
7036
|
+
}
|
|
7037
|
+
return instance.t(e, {
|
|
7038
|
+
lng: r,
|
|
7039
|
+
...t
|
|
7040
|
+
});
|
|
7041
|
+
}
|
|
7042
|
+
},
|
|
7043
|
+
languageOptions: [{
|
|
7044
|
+
value: "en_US",
|
|
7045
|
+
label: "English (US)"
|
|
7046
|
+
}, {
|
|
7047
|
+
value: "es_ES",
|
|
7048
|
+
label: "Spanish"
|
|
7049
|
+
}]
|
|
7050
|
+
};
|
|
7051
|
+
/**
|
|
7052
|
+
* A learner-facing string in `language`, the model's `language`. i18next falls
|
|
7053
|
+
* back to English for a language or key it does not hold.
|
|
7054
|
+
*/
|
|
7055
|
+
function t(key, language) {
|
|
7056
|
+
return translator.t(`translation:simpleCloze:${key}`, { lng: language });
|
|
7057
|
+
}
|
|
7058
|
+
//#endregion
|
|
4381
7059
|
//#region src/print/Print.svelte
|
|
4382
|
-
var root = /* @__PURE__ */ from_html(`<div class="
|
|
4383
|
-
var root_1 = /* @__PURE__ */ from_html(`<div class="
|
|
7060
|
+
var root = /* @__PURE__ */ from_html(`<div class="simple-cloze-print-teacher-instructions svelte-1fx5wwa"></div>`);
|
|
7061
|
+
var root_1 = /* @__PURE__ */ from_html(`<div class="simple-cloze-print-prompt svelte-1fx5wwa"></div>`);
|
|
7062
|
+
var root_2 = /* @__PURE__ */ from_html(`<span class="simple-cloze-print-key-label svelte-1fx5wwa"> </span> <span class="simple-cloze-print-blank simple-cloze-print-blank--key svelte-1fx5wwa"> </span>`, 1);
|
|
7063
|
+
var root_3 = /* @__PURE__ */ from_html(`<span class="simple-cloze-print-blank svelte-1fx5wwa" role="img"></span>`);
|
|
7064
|
+
var root_4 = /* @__PURE__ */ from_html(`<div class="simple-cloze-print svelte-1fx5wwa"><!> <!> <div class="simple-cloze-print-response svelte-1fx5wwa"><!></div></div>`);
|
|
4384
7065
|
var $$css = {
|
|
4385
7066
|
hash: "svelte-1fx5wwa",
|
|
4386
|
-
code: "\n
|
|
7067
|
+
code: "\n /* Self-contained: print players ship no Tailwind or CSS reset. */.simple-cloze-print.svelte-1fx5wwa {padding:1rem;color:var(--pie-text, black);}.simple-cloze-print-teacher-instructions.svelte-1fx5wwa,\n .simple-cloze-print-prompt.svelte-1fx5wwa {margin-bottom:1rem;}.simple-cloze-print-teacher-instructions.svelte-1fx5wwa p,\n .simple-cloze-print-prompt.svelte-1fx5wwa p {margin:0.5em 0;}.simple-cloze-print-prompt.svelte-1fx5wwa strong {font-weight:600;}.simple-cloze-print-response.svelte-1fx5wwa {display:inline-flex;align-items:baseline;gap:0.5rem;}.simple-cloze-print-key-label.svelte-1fx5wwa {font-size:0.875rem;line-height:1.25rem;font-weight:600;}.simple-cloze-print-blank.svelte-1fx5wwa {display:inline-block;min-width:12rem;min-height:1.5rem;padding:0.5rem 0.75rem;border-bottom:2px solid var(--pie-text, black);}.simple-cloze-print-blank--key.svelte-1fx5wwa {min-width:6rem;font-weight:600;}\n\n @media print {.simple-cloze-print.svelte-1fx5wwa {padding:0;}\n }"
|
|
4387
7068
|
};
|
|
4388
7069
|
function Print($$anchor, $$props) {
|
|
4389
7070
|
push($$props, true);
|
|
4390
7071
|
append_styles($$anchor, $$css);
|
|
4391
|
-
let model = prop($$props, "model", 7, null);
|
|
4392
|
-
|
|
7072
|
+
let model = prop($$props, "model", 7, null), options = prop($$props, "options", 7, null);
|
|
7073
|
+
const isInstructor = /* @__PURE__ */ user_derived(() => options()?.role === "instructor");
|
|
7074
|
+
const prompt = /* @__PURE__ */ user_derived(() => model()?.promptEnabled !== false && typeof model()?.prompt === "string" ? model().prompt : "");
|
|
7075
|
+
const correctAnswer = /* @__PURE__ */ user_derived(() => toPlainText(model()?.correctAnswer));
|
|
7076
|
+
const showAnswerKey = /* @__PURE__ */ user_derived(() => get$1(isInstructor) && !!get$1(correctAnswer));
|
|
7077
|
+
const teacherInstructions = /* @__PURE__ */ user_derived(() => get$1(isInstructor) && model()?.teacherInstructionsEnabled !== false ? model()?.teacherInstructions || "" : "");
|
|
7078
|
+
let promptElement = /* @__PURE__ */ state(null);
|
|
4393
7079
|
user_effect(() => {
|
|
4394
|
-
|
|
7080
|
+
if (!get$1(promptElement) || !get$1(prompt)) return;
|
|
7081
|
+
const warn = (err) => console.warn("simple-cloze: MathJax render failed", err);
|
|
7082
|
+
try {
|
|
7083
|
+
Promise.resolve(c(get$1(promptElement))).catch(warn);
|
|
7084
|
+
} catch (err) {
|
|
7085
|
+
warn(err);
|
|
7086
|
+
}
|
|
4395
7087
|
});
|
|
4396
7088
|
var $$exports = {
|
|
4397
7089
|
get model() {
|
|
@@ -4400,32 +7092,80 @@ function Print($$anchor, $$props) {
|
|
|
4400
7092
|
set model($$value = null) {
|
|
4401
7093
|
model($$value);
|
|
4402
7094
|
flushSync();
|
|
7095
|
+
},
|
|
7096
|
+
get options() {
|
|
7097
|
+
return options();
|
|
7098
|
+
},
|
|
7099
|
+
set options($$value = null) {
|
|
7100
|
+
options($$value);
|
|
7101
|
+
flushSync();
|
|
4403
7102
|
}
|
|
4404
7103
|
};
|
|
4405
|
-
var div =
|
|
7104
|
+
var div = root_4();
|
|
4406
7105
|
var node = child(div);
|
|
4407
7106
|
var consequent = ($$anchor) => {
|
|
4408
7107
|
var div_1 = root();
|
|
4409
|
-
html(div_1, () => get(
|
|
7108
|
+
html(div_1, () => get$1(teacherInstructions), true);
|
|
4410
7109
|
reset(div_1);
|
|
4411
7110
|
append($$anchor, div_1);
|
|
4412
7111
|
};
|
|
4413
7112
|
if_block(node, ($$render) => {
|
|
4414
|
-
if (get(
|
|
7113
|
+
if (get$1(teacherInstructions)) $$render(consequent);
|
|
7114
|
+
});
|
|
7115
|
+
var node_1 = sibling(node, 2);
|
|
7116
|
+
var consequent_1 = ($$anchor) => {
|
|
7117
|
+
var div_2 = root_1();
|
|
7118
|
+
html(div_2, () => get$1(prompt), true);
|
|
7119
|
+
reset(div_2);
|
|
7120
|
+
bind_this(div_2, ($$value) => set(promptElement, $$value), () => get$1(promptElement));
|
|
7121
|
+
append($$anchor, div_2);
|
|
7122
|
+
};
|
|
7123
|
+
if_block(node_1, ($$render) => {
|
|
7124
|
+
if (get$1(prompt)) $$render(consequent_1);
|
|
4415
7125
|
});
|
|
4416
|
-
|
|
7126
|
+
var div_3 = sibling(node_1, 2);
|
|
7127
|
+
var node_2 = child(div_3);
|
|
7128
|
+
var consequent_2 = ($$anchor) => {
|
|
7129
|
+
var fragment = root_2();
|
|
7130
|
+
var span = first_child(fragment);
|
|
7131
|
+
var text = only_child(span, true);
|
|
7132
|
+
var text_1 = only_child(sibling(span, 2), true);
|
|
7133
|
+
template_effect(($0) => {
|
|
7134
|
+
set_text(text, $0);
|
|
7135
|
+
set_text(text_1, get$1(correctAnswer));
|
|
7136
|
+
}, [() => t("printCorrectAnswer", model()?.language)]);
|
|
7137
|
+
append($$anchor, fragment);
|
|
7138
|
+
};
|
|
7139
|
+
var alternate = ($$anchor) => {
|
|
7140
|
+
var span_2 = root_3();
|
|
7141
|
+
template_effect(($0) => set_attribute(span_2, "aria-label", $0), [() => t("printAnswerBlank", model()?.language)]);
|
|
7142
|
+
append($$anchor, span_2);
|
|
7143
|
+
};
|
|
7144
|
+
if_block(node_2, ($$render) => {
|
|
7145
|
+
if (get$1(showAnswerKey)) $$render(consequent_2);
|
|
7146
|
+
else $$render(alternate, -1);
|
|
7147
|
+
});
|
|
7148
|
+
reset(div_3);
|
|
4417
7149
|
reset(div);
|
|
4418
7150
|
append($$anchor, div);
|
|
4419
7151
|
return pop($$exports);
|
|
4420
7152
|
}
|
|
4421
|
-
create_custom_element(Print, {
|
|
7153
|
+
create_custom_element(Print, {
|
|
7154
|
+
model: { type: "Object" },
|
|
7155
|
+
options: { type: "Object" }
|
|
7156
|
+
}, [], []);
|
|
4422
7157
|
//#endregion
|
|
4423
7158
|
//#region src/print/index.ts
|
|
4424
7159
|
var SvelteElementClass = Print.element;
|
|
7160
|
+
/**
|
|
7161
|
+
* Print players set `el.options = config.options` and then `el.model = m`;
|
|
7162
|
+
* `options.role` decides whether the answer key is printed.
|
|
7163
|
+
*/
|
|
4425
7164
|
var SimpleClozePrint = class extends SvelteElementClass {
|
|
4426
7165
|
constructor(..._args) {
|
|
4427
7166
|
super(..._args);
|
|
4428
7167
|
_defineProperty(this, "_model", null);
|
|
7168
|
+
_defineProperty(this, "_options", null);
|
|
4429
7169
|
}
|
|
4430
7170
|
set model(m) {
|
|
4431
7171
|
this._model = m;
|
|
@@ -4434,6 +7174,13 @@ var SimpleClozePrint = class extends SvelteElementClass {
|
|
|
4434
7174
|
get model() {
|
|
4435
7175
|
return this._model;
|
|
4436
7176
|
}
|
|
7177
|
+
set options(o) {
|
|
7178
|
+
this._options = o;
|
|
7179
|
+
super.options = o;
|
|
7180
|
+
}
|
|
7181
|
+
get options() {
|
|
7182
|
+
return this._options;
|
|
7183
|
+
}
|
|
4437
7184
|
};
|
|
4438
7185
|
//#endregion
|
|
4439
7186
|
export { SimpleClozePrint as default };
|