@deriv-com/translations 1.2.3 → 1.2.4

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 V } from "../i18nInstance-D20fwFYr.js";
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 S(e) {
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 B(e, t) {
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(B, "") + "</" + t.name + ">";
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 = S(f);
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 = S(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)) {
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 + B("", n);
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 R(e) {
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 L(e, t) {
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 = L(c, t);
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(R(l)) : typeof l == "object" && !D(l) && Object.assign(f, l));
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 = R(m), O = x(v, u.children, l);
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 C = r.children && r.children[0] && r.children[0].content && n.services.interpolator.interpolate(r.children[0].content, j, n.language);
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), A = 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);
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) || A) {
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] ? C : null;
225
+ const $ = r.children[0] ? A : null;
226
226
  $ && h.push($);
227
227
  } else
228
- b(d, C, h, k, r.children.length !== 1 || !C);
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 R(y[0]);
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 || V();
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) || ((A) => A);
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 = L(t, u), O = f || v || u.transEmptyNodeValue || p, {
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
- }, C = {
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, C) : O;
295
- c && Object.keys(c).forEach((A) => {
296
- const P = c[A];
297
- if (typeof P.type == "function" || !P.props || !P.props.children || E.indexOf(`${A}/>`) < 0 && E.indexOf(`${A} />`) < 0)
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[A] = T(I);
302
+ c[C] = T(I);
303
303
  });
304
- const d = pe(c || t, E, y, u, C, b), N = o !== void 0 ? o : u.defaultTransParent;
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 || V(), l = w || u && u.t.bind(u);
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 f, createElement as c, createContext as g, useState as u, useEffect as m } from "react";
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(a) {
6
+ function v(t) {
7
7
  let {
8
8
  i18n: e,
9
- defaultNS: r,
9
+ defaultNS: o,
10
10
  children: n
11
- } = a;
12
- const o = f(() => ({
11
+ } = t;
12
+ const a = m(() => ({
13
13
  i18n: e,
14
- defaultNS: r
15
- }), [e, r]);
16
- return c(p.Provider, {
17
- value: o
14
+ defaultNS: o
15
+ }), [e, o]);
16
+ return d(p.Provider, {
17
+ value: a
18
18
  }, n);
19
19
  }
20
- const x = g(null);
20
+ const x = f(null);
21
21
  function S({
22
- defaultLang: a,
22
+ defaultLang: t,
23
23
  i18nInstance: e,
24
- children: r
24
+ children: o
25
25
  }) {
26
- const [n, o] = u(a || ""), [l, s] = u(!1), d = (t) => {
27
- e.changeLanguage(t), o(t), localStorage.setItem(L, t);
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 m(() => {
29
+ return g(() => {
30
30
  if (e) {
31
- const t = e.language;
32
- o(t), e.on("initialized", () => {
33
- s(!0);
31
+ const r = e.language || t || "";
32
+ a(r), e.on("initialized", () => {
33
+ l(!0);
34
34
  });
35
35
  }
36
- }, [e]), !e || !l ? null : /* @__PURE__ */ i(v, { i18n: e, children: /* @__PURE__ */ i(
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: d
41
+ switchLanguage: c
42
42
  },
43
- children: r
43
+ children: o
44
44
  }
45
45
  ) });
46
46
  }
@@ -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
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "private": false,
19
- "version": "1.2.3",
19
+ "version": "1.2.4",
20
20
  "scripts": {
21
21
  "dev": "vite",
22
22
  "build": "tsc && vite build && cp ./src/scripts/deriv-extract-translations.cjs ./dist/deriv-extract-translations.cjs",