@deriv-com/translations 1.3.4 → 1.3.6
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 +6 -6
- package/dist/provider/translation-provider.js +13 -13
- package/dist/utils/lang-utils.d.ts +1 -1
- package/dist/utils/lang-utils.js +10 -10
- package/dist/utils/localize.d.ts +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ This is a localization library that uses `i18next`, `react-i18next`, and a custo
|
|
|
10
10
|
- [Usage](#usage)
|
|
11
11
|
- [`initializeI18n`](#initializei18n)
|
|
12
12
|
- [`<Localize />`](#localize-component-example)
|
|
13
|
-
- [
|
|
13
|
+
- [`localize`](#localize-example)
|
|
14
14
|
- [`useTranslations` Hook](#usetranslations-hook)
|
|
15
15
|
- [Syncing translations to CDN](#syncing-translations)
|
|
16
16
|
- [Example usage of the action in the workflow file](#example-usage-of-the-action-in-the-workflow-file)
|
|
@@ -100,16 +100,16 @@ import { Localize } from "@deriv-com/translations";
|
|
|
100
100
|
/>;
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
###
|
|
103
|
+
### `localize` example:
|
|
104
104
|
|
|
105
|
-
> Note that the `localize` function
|
|
105
|
+
> Note that the `localize` function will not get the update from i18n instance once there is any changes like resource loaded or language change. This `localize` function is not to be used to wrap strings in components and only suitable for util/mapper functions which would not cause issues with string not getting updated.
|
|
106
106
|
|
|
107
107
|
```jsx
|
|
108
108
|
import { localize } from "@deriv-com/translations";
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
const getNotification = () => ({
|
|
111
|
+
all: localize("all notifications"),
|
|
112
|
+
});
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
### `useTranslations` Hook
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { I as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { I as f, j as s } from "../jsx-runtime-ClgrxkDP.js";
|
|
2
|
+
import { useMemo as g, createElement as m, createContext as d, useState as i, useEffect as x } from "react";
|
|
3
3
|
import "../crc32-LCGpXEbE.js";
|
|
4
4
|
import { L } from "../constants-D-_KboaS.js";
|
|
5
5
|
function p(t) {
|
|
6
6
|
let {
|
|
7
7
|
i18n: e,
|
|
8
8
|
defaultNS: o,
|
|
9
|
-
children:
|
|
9
|
+
children: a
|
|
10
10
|
} = t;
|
|
11
|
-
const
|
|
11
|
+
const n = g(() => ({
|
|
12
12
|
i18n: e,
|
|
13
13
|
defaultNS: o
|
|
14
14
|
}), [e, o]);
|
|
15
|
-
return f
|
|
16
|
-
value:
|
|
17
|
-
},
|
|
15
|
+
return m(f.Provider, {
|
|
16
|
+
value: n
|
|
17
|
+
}, a);
|
|
18
18
|
}
|
|
19
|
-
const v =
|
|
19
|
+
const v = d(null);
|
|
20
20
|
function P({
|
|
21
21
|
defaultLang: t,
|
|
22
22
|
i18nInstance: e,
|
|
23
23
|
children: o
|
|
24
24
|
}) {
|
|
25
|
-
const [
|
|
26
|
-
e.changeLanguage(r),
|
|
25
|
+
const [a, n] = i(t || ""), [u, l] = i(!1), c = (r) => {
|
|
26
|
+
e.changeLanguage(r), n(r), localStorage.setItem(L, JSON.stringify(r));
|
|
27
27
|
};
|
|
28
28
|
return x(() => {
|
|
29
29
|
if (e) {
|
|
30
30
|
const r = e.language || t || "";
|
|
31
|
-
|
|
31
|
+
n(r), l(!0);
|
|
32
32
|
}
|
|
33
|
-
}, [e, t]), !e || !
|
|
33
|
+
}, [e, t]), !e || !u ? null : /* @__PURE__ */ s.jsx(p, { i18n: e, children: /* @__PURE__ */ s.jsx(
|
|
34
34
|
v.Provider,
|
|
35
35
|
{
|
|
36
36
|
value: {
|
|
37
|
-
currentLang:
|
|
37
|
+
currentLang: a,
|
|
38
38
|
switchLanguage: c
|
|
39
39
|
},
|
|
40
40
|
children: o
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { constants } from './index';
|
|
2
2
|
type LanguageCode = keyof typeof constants.ALL_LANGUAGES;
|
|
3
|
-
export declare const getInitialLanguage: () =>
|
|
3
|
+
export declare const getInitialLanguage: () => any;
|
|
4
4
|
export declare const loadIncontextTranslation: (lang: LanguageCode) => void;
|
|
5
5
|
/**
|
|
6
6
|
* Filter out unsupported languages and return an Object containing language code and language name
|
package/dist/utils/lang-utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import "../crc32-LCGpXEbE.js";
|
|
2
|
-
import { L as
|
|
2
|
+
import { L as s, D as o, A as c } from "../constants-D-_KboaS.js";
|
|
3
3
|
const l = () => {
|
|
4
|
-
const a = new URLSearchParams(window.location.search).get("lang"), t = localStorage.getItem(
|
|
4
|
+
const a = new URLSearchParams(window.location.search).get("lang"), t = JSON.parse(localStorage.getItem(s));
|
|
5
5
|
if (a) {
|
|
6
6
|
const e = a.toUpperCase();
|
|
7
|
-
return localStorage.setItem(
|
|
7
|
+
return localStorage.setItem(s, JSON.stringify(e)), e;
|
|
8
8
|
}
|
|
9
|
-
return t ||
|
|
10
|
-
}, u = (
|
|
11
|
-
if (
|
|
9
|
+
return t || o;
|
|
10
|
+
}, u = (r) => {
|
|
11
|
+
if (r.toUpperCase() === "ACH") {
|
|
12
12
|
const t = document.createElement("script");
|
|
13
13
|
t.type = "text/javascript", t.text = `
|
|
14
14
|
var _jipt = []; _jipt.push(['project', 'deriv-app']);
|
|
@@ -17,12 +17,12 @@ const l = () => {
|
|
|
17
17
|
document.head.appendChild(crowdin);
|
|
18
18
|
`, document.head.appendChild(t);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
21
|
-
const a = ["ACH", ...
|
|
22
|
-
return Object.keys(
|
|
20
|
+
}, g = (r = []) => {
|
|
21
|
+
const a = ["ACH", ...r];
|
|
22
|
+
return Object.keys(c).filter((e) => !a.includes(e)).reduce((e, n) => (e[n] = c[n], e), {});
|
|
23
23
|
};
|
|
24
24
|
export {
|
|
25
|
-
|
|
25
|
+
g as getAllowedLanguages,
|
|
26
26
|
l as getInitialLanguage,
|
|
27
27
|
u as loadIncontextTranslation
|
|
28
28
|
};
|
package/dist/utils/localize.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
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
|
-
*
|
|
4
2
|
* @param {string} string
|
|
5
3
|
* @param {Record<string, unknown>} values
|
|
6
4
|
* @returns {string}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"deriv-extract-translations": "./dist/deriv-extract-translations.cjs"
|
|
11
11
|
},
|
|
12
12
|
"private": false,
|
|
13
|
-
"version": "1.3.
|
|
13
|
+
"version": "1.3.6",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"dev": "vite",
|
|
16
16
|
"build": "tsc && vite build && cp ./src/scripts/deriv-extract-translations.cjs ./dist/deriv-extract-translations.cjs",
|