@deriv-com/translations 1.2.3 → 1.2.5
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/README.md
CHANGED
|
@@ -102,7 +102,7 @@ import { Localize } from "@deriv-com/translations";
|
|
|
102
102
|
|
|
103
103
|
### ~~`localize`~~ example:
|
|
104
104
|
|
|
105
|
-
> Note that the `localize` function is deprecated and should be replaced with the `useTranslations` hook or the `Localize` component. the example of the `localize` function is provided for backward compatibility.
|
|
105
|
+
> Note that the `localize` function is deprecated and should be replaced with the `useTranslations` hook or the `Localize` component. this function will not get the update from i18n instance once there is any changes like resource loaded or language change. the example of the `localize` function is provided for backward compatibility.
|
|
106
106
|
|
|
107
107
|
```jsx
|
|
108
108
|
import { localize } from "@deriv-com/translations";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { i18n } from "i18next";
|
|
2
|
+
type TLocalizeProps = {
|
|
3
|
+
i18n_default_text: string;
|
|
4
|
+
values?: object;
|
|
5
|
+
components?: JSX.Element[];
|
|
6
|
+
options?: Record<string, unknown>;
|
|
7
|
+
shouldUnescape?: boolean;
|
|
8
|
+
i18n?: i18n;
|
|
9
|
+
};
|
|
10
|
+
declare const Localize: React.ComponentType<TLocalizeProps>;
|
|
11
|
+
export default Localize;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as W } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as T, isValidElement as D, Fragment as z, cloneElement as M, Children as _, useContext as J, forwardRef as U } from "react";
|
|
3
3
|
import { w as X, a as K, g as Y, u as Z } from "../useTranslation-DWHGHs02.js";
|
|
4
|
-
import { g as q, b as
|
|
4
|
+
import { g as q, b as S } from "../i18nInstance-D20fwFYr.js";
|
|
5
5
|
import { I as G } from "../context-f4Bcf4Hs.js";
|
|
6
6
|
function Q(e) {
|
|
7
7
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
@@ -24,7 +24,7 @@ var ee = {
|
|
|
24
24
|
};
|
|
25
25
|
const te = /* @__PURE__ */ Q(ee);
|
|
26
26
|
var ne = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
27
|
-
function
|
|
27
|
+
function R(e) {
|
|
28
28
|
var t = { type: "tag", name: "", voidElement: !1, attrs: {}, children: [] }, n = e.match(/<\/?([^\s]+?)[/\s>]/);
|
|
29
29
|
if (n && (t.name = n[1], (te[n[1]] || e.charAt(e.length - 2) === "/") && (t.voidElement = !0), t.name.startsWith("!--"))) {
|
|
30
30
|
var o = e.indexOf("-->");
|
|
@@ -40,7 +40,7 @@ function S(e) {
|
|
|
40
40
|
return t;
|
|
41
41
|
}
|
|
42
42
|
var se = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g, re = /^\s*$/, oe = /* @__PURE__ */ Object.create(null);
|
|
43
|
-
function
|
|
43
|
+
function V(e, t) {
|
|
44
44
|
switch (t.type) {
|
|
45
45
|
case "text":
|
|
46
46
|
return e + t.content;
|
|
@@ -50,7 +50,7 @@ function B(e, t) {
|
|
|
50
50
|
for (var p in n)
|
|
51
51
|
o.push(p + '="' + n[p] + '"');
|
|
52
52
|
return o.length ? " " + o.join(" ") : "";
|
|
53
|
-
}(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(
|
|
53
|
+
}(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(V, "") + "</" + t.name + ">";
|
|
54
54
|
case "comment":
|
|
55
55
|
return e + "<!--" + t.comment + "-->";
|
|
56
56
|
}
|
|
@@ -70,10 +70,10 @@ var ae = { parse: function(e, t) {
|
|
|
70
70
|
}
|
|
71
71
|
var g, j = f.charAt(1) !== "/", w = f.startsWith("<!--"), b = c + f.length, x = e.charAt(b);
|
|
72
72
|
if (w) {
|
|
73
|
-
var y =
|
|
73
|
+
var y = R(f);
|
|
74
74
|
return s < 0 ? (o.push(y), o) : ((g = p[s]).children.push(y), o);
|
|
75
75
|
}
|
|
76
|
-
if (j && (s++, (n =
|
|
76
|
+
if (j && (s++, (n = R(f)).type === "tag" && t.components[n.name] && (n.type = "component", i = !0), n.voidElement || i || !x || x === "<" || n.children.push({ type: "text", content: e.slice(b, e.indexOf("<", b)) }), s === 0 && o.push(n), (g = p[s - 1]) && g.children.push(n), p[s] = n), (!j || n.voidElement) && (s > -1 && (n.voidElement || n.name === f.slice(2, -1)) && (s--, n = s === -1 ? o : p[s]), !i && x !== "<" && x)) {
|
|
77
77
|
g = s === -1 ? o : p[s].children;
|
|
78
78
|
var m = e.indexOf("<", b), u = e.slice(b, m === -1 ? void 0 : m);
|
|
79
79
|
re.test(u) && (u = " "), (m > -1 && s + g.length >= 0 || u !== " ") && g.push({ type: "text", content: u });
|
|
@@ -81,7 +81,7 @@ var ae = { parse: function(e, t) {
|
|
|
81
81
|
}), o;
|
|
82
82
|
}, stringify: function(e) {
|
|
83
83
|
return e.reduce(function(t, n) {
|
|
84
|
-
return t +
|
|
84
|
+
return t + V("", n);
|
|
85
85
|
}, "");
|
|
86
86
|
} };
|
|
87
87
|
function H(e, t) {
|
|
@@ -90,7 +90,7 @@ function H(e, t) {
|
|
|
90
90
|
const n = e.props ? e.props.children : e.children;
|
|
91
91
|
return t ? n.length > 0 : !!n;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function L(e) {
|
|
94
94
|
if (!e)
|
|
95
95
|
return [];
|
|
96
96
|
const t = e.props ? e.props.children : e.children;
|
|
@@ -108,7 +108,7 @@ function le(e, t) {
|
|
|
108
108
|
};
|
|
109
109
|
return n.props = Object.assign(e.props, t.props), n;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function B(e, t) {
|
|
112
112
|
if (!e)
|
|
113
113
|
return "";
|
|
114
114
|
let n = "";
|
|
@@ -127,7 +127,7 @@ function L(e, t) {
|
|
|
127
127
|
else if (f && a === 1 && typeof c == "string")
|
|
128
128
|
n += `<${s.type}>${c}</${s.type}>`;
|
|
129
129
|
else {
|
|
130
|
-
const g =
|
|
130
|
+
const g = B(c, t);
|
|
131
131
|
n += `<${i}>${g}</${i}>`;
|
|
132
132
|
}
|
|
133
133
|
} else if (s === null)
|
|
@@ -155,7 +155,7 @@ function pe(e, t, n, o, p, s) {
|
|
|
155
155
|
const f = {};
|
|
156
156
|
function c(m) {
|
|
157
157
|
F(m).forEach((l) => {
|
|
158
|
-
typeof l != "string" && (H(l) ? c(
|
|
158
|
+
typeof l != "string" && (H(l) ? c(L(l)) : typeof l == "object" && !D(l) && Object.assign(f, l));
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
c(e);
|
|
@@ -164,7 +164,7 @@ function pe(e, t, n, o, p, s) {
|
|
|
164
164
|
...p
|
|
165
165
|
};
|
|
166
166
|
function w(m, u, l) {
|
|
167
|
-
const v =
|
|
167
|
+
const v = L(m), O = x(v, u.children, l);
|
|
168
168
|
return ie(v) && O.length === 0 || m.props && m.props.i18nIsDynamicList ? v : O;
|
|
169
169
|
}
|
|
170
170
|
function b(m, u, l, v, O) {
|
|
@@ -184,17 +184,17 @@ function pe(e, t, n, o, p, s) {
|
|
|
184
184
|
function x(m, u, l) {
|
|
185
185
|
const v = F(m);
|
|
186
186
|
return F(u).reduce((h, r, k) => {
|
|
187
|
-
const
|
|
187
|
+
const A = r.children && r.children[0] && r.children[0].content && n.services.interpolator.interpolate(r.children[0].content, j, n.language);
|
|
188
188
|
if (r.type === "tag") {
|
|
189
189
|
let E = v[parseInt(r.name, 10)];
|
|
190
190
|
l.length === 1 && !E && (E = l[0][r.name]), E || (E = {});
|
|
191
191
|
const d = Object.keys(r.attrs).length !== 0 ? le({
|
|
192
192
|
props: r.attrs
|
|
193
|
-
}, E) : E, N = D(d),
|
|
193
|
+
}, E) : E, N = D(d), C = N && H(r, !0) && !r.voidElement, P = a && typeof d == "object" && d.dummy && !N, I = typeof e == "object" && e !== null && Object.hasOwnProperty.call(e, r.name);
|
|
194
194
|
if (typeof d == "string") {
|
|
195
195
|
const $ = n.services.interpolator.interpolate(d, j, n.language);
|
|
196
196
|
h.push($);
|
|
197
|
-
} else if (H(d) ||
|
|
197
|
+
} else if (H(d) || C) {
|
|
198
198
|
const $ = w(d, r, l);
|
|
199
199
|
b(d, $, h, k);
|
|
200
200
|
} else if (P) {
|
|
@@ -222,10 +222,10 @@ function pe(e, t, n, o, p, s) {
|
|
|
222
222
|
h.push(`<${r.name}>${$}</${r.name}>`);
|
|
223
223
|
}
|
|
224
224
|
else if (typeof d == "object" && !N) {
|
|
225
|
-
const $ = r.children[0] ?
|
|
225
|
+
const $ = r.children[0] ? A : null;
|
|
226
226
|
$ && h.push($);
|
|
227
227
|
} else
|
|
228
|
-
b(d,
|
|
228
|
+
b(d, A, h, k, r.children.length !== 1 || !A);
|
|
229
229
|
} else if (r.type === "text") {
|
|
230
230
|
const E = o.transWrapTextNodes, d = s ? o.unescape(n.services.interpolator.interpolate(r.content, j, n.language)) : n.services.interpolator.interpolate(r.content, j, n.language);
|
|
231
231
|
E ? h.push(T(E, {
|
|
@@ -239,7 +239,7 @@ function pe(e, t, n, o, p, s) {
|
|
|
239
239
|
dummy: !0,
|
|
240
240
|
children: e || []
|
|
241
241
|
}], g, F(e || []));
|
|
242
|
-
return
|
|
242
|
+
return L(y[0]);
|
|
243
243
|
}
|
|
244
244
|
function ue(e) {
|
|
245
245
|
let {
|
|
@@ -258,10 +258,10 @@ function ue(e) {
|
|
|
258
258
|
shouldUnescape: b,
|
|
259
259
|
...x
|
|
260
260
|
} = e;
|
|
261
|
-
const y = j ||
|
|
261
|
+
const y = j || S();
|
|
262
262
|
if (!y)
|
|
263
263
|
return X("You will need to pass in an i18next instance by using i18nextReactModule"), t;
|
|
264
|
-
const m = w || y.t.bind(y) || ((
|
|
264
|
+
const m = w || y.t.bind(y) || ((C) => C);
|
|
265
265
|
s && (i.context = s);
|
|
266
266
|
const u = {
|
|
267
267
|
...q(),
|
|
@@ -269,7 +269,7 @@ function ue(e) {
|
|
|
269
269
|
};
|
|
270
270
|
let l = g || m.ns || y.options && y.options.defaultNS;
|
|
271
271
|
l = typeof l == "string" ? [l] : l || ["translation"];
|
|
272
|
-
const v =
|
|
272
|
+
const v = B(t, u), O = f || v || u.transEmptyNodeValue || p, {
|
|
273
273
|
hashTransKey: h
|
|
274
274
|
} = u, r = p || (h ? h(v || O) : v || O);
|
|
275
275
|
y.options && y.options.interpolation && y.options.interpolation.defaultVariables && (a = a && Object.keys(a).length > 0 ? {
|
|
@@ -284,24 +284,24 @@ function ue(e) {
|
|
|
284
284
|
prefix: "#$?",
|
|
285
285
|
suffix: "?$#"
|
|
286
286
|
}
|
|
287
|
-
},
|
|
287
|
+
}, A = {
|
|
288
288
|
...i,
|
|
289
289
|
count: n,
|
|
290
290
|
...a,
|
|
291
291
|
...k,
|
|
292
292
|
defaultValue: O,
|
|
293
293
|
ns: l
|
|
294
|
-
}, E = r ? m(r,
|
|
295
|
-
c && Object.keys(c).forEach((
|
|
296
|
-
const P = c[
|
|
297
|
-
if (typeof P.type == "function" || !P.props || !P.props.children || E.indexOf(`${
|
|
294
|
+
}, E = r ? m(r, A) : O;
|
|
295
|
+
c && Object.keys(c).forEach((C) => {
|
|
296
|
+
const P = c[C];
|
|
297
|
+
if (typeof P.type == "function" || !P.props || !P.props.children || E.indexOf(`${C}/>`) < 0 && E.indexOf(`${C} />`) < 0)
|
|
298
298
|
return;
|
|
299
299
|
function I() {
|
|
300
300
|
return T(z, null, P);
|
|
301
301
|
}
|
|
302
|
-
c[
|
|
302
|
+
c[C] = T(I);
|
|
303
303
|
});
|
|
304
|
-
const d = pe(c || t, E, y, u,
|
|
304
|
+
const d = pe(c || t, E, y, u, A, b), N = o !== void 0 ? o : u.defaultTransParent;
|
|
305
305
|
return N ? T(N, x, d) : d;
|
|
306
306
|
}
|
|
307
307
|
function ce(e) {
|
|
@@ -324,7 +324,7 @@ function ce(e) {
|
|
|
324
324
|
const {
|
|
325
325
|
i18n: y,
|
|
326
326
|
defaultNS: m
|
|
327
|
-
} = J(G) || {}, u = j || y ||
|
|
327
|
+
} = J(G) || {}, u = j || y || S(), l = w || u && u.t.bind(u);
|
|
328
328
|
return ue({
|
|
329
329
|
children: t,
|
|
330
330
|
count: n,
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo as
|
|
2
|
+
import { useMemo as m, createElement as d, createContext as f, useState as u, useEffect as g } from "react";
|
|
3
3
|
import "../crc32-LCGpXEbE.js";
|
|
4
4
|
import { L } from "../constants-C3Rdpvgf.js";
|
|
5
5
|
import { I as p } from "../context-f4Bcf4Hs.js";
|
|
6
|
-
function v(
|
|
6
|
+
function v(t) {
|
|
7
7
|
let {
|
|
8
8
|
i18n: e,
|
|
9
|
-
defaultNS:
|
|
9
|
+
defaultNS: o,
|
|
10
10
|
children: n
|
|
11
|
-
} =
|
|
12
|
-
const
|
|
11
|
+
} = t;
|
|
12
|
+
const a = m(() => ({
|
|
13
13
|
i18n: e,
|
|
14
|
-
defaultNS:
|
|
15
|
-
}), [e,
|
|
16
|
-
return
|
|
17
|
-
value:
|
|
14
|
+
defaultNS: o
|
|
15
|
+
}), [e, o]);
|
|
16
|
+
return d(p.Provider, {
|
|
17
|
+
value: a
|
|
18
18
|
}, n);
|
|
19
19
|
}
|
|
20
|
-
const x =
|
|
20
|
+
const x = f(null);
|
|
21
21
|
function S({
|
|
22
|
-
defaultLang:
|
|
22
|
+
defaultLang: t,
|
|
23
23
|
i18nInstance: e,
|
|
24
|
-
children:
|
|
24
|
+
children: o
|
|
25
25
|
}) {
|
|
26
|
-
const [n,
|
|
27
|
-
e.changeLanguage(
|
|
26
|
+
const [n, a] = u(t || ""), [s, l] = u(!1), c = (r) => {
|
|
27
|
+
e.changeLanguage(r), a(r), localStorage.setItem(L, r);
|
|
28
28
|
};
|
|
29
|
-
return
|
|
29
|
+
return g(() => {
|
|
30
30
|
if (e) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const r = e.language || t || "";
|
|
32
|
+
a(r), e.on("initialized", () => {
|
|
33
|
+
l(!0);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
}, [e]), !e || !
|
|
36
|
+
}, [e, t]), !e || !s ? null : /* @__PURE__ */ i(v, { i18n: e, children: /* @__PURE__ */ i(
|
|
37
37
|
x.Provider,
|
|
38
38
|
{
|
|
39
39
|
value: {
|
|
40
40
|
currentLang: n,
|
|
41
|
-
switchLanguage:
|
|
41
|
+
switchLanguage: c
|
|
42
42
|
},
|
|
43
|
-
children:
|
|
43
|
+
children: o
|
|
44
44
|
}
|
|
45
45
|
) });
|
|
46
46
|
}
|
package/dist/utils/localize.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @deprecated use the `localize` function from the `useTranslations` hook, this function will not get the update from i18n instance once there is any changes like resource loaded or language changed
|
|
3
|
+
*
|
|
2
4
|
* @param {string} string
|
|
3
5
|
* @param {Record<string, unknown>} values
|
|
4
6
|
* @returns {string}
|
package/package.json
CHANGED