typed-locales 1.0.23 → 1.0.25
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-utilities.d.ts","sourceRoot":"","sources":["../src/react-utilities.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"react-utilities.d.ts","sourceRoot":"","sources":["../src/react-utilities.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4E,MAAM,OAAO,CAAC;AAEjG,OAAO,EAAE,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAqB,MAAM,SAAS,CAAC;AAEtH,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAGD,eAAO,MAAM,SAAS,GACrB,iBAAiB,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,CAAC,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,EACxF,eAAe,OAAO,EACtB,iBAAiB,eAAe;wCAGW;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;CA+DxE,CAAC"}
|
package/dist/react-utilities.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useState } from 'react';
|
|
2
|
+
import { createContext, useCallback, useContext, useState } from 'react';
|
|
3
3
|
import { getTranslate } from './index.js';
|
|
4
4
|
// Initial translation always should be loaded
|
|
5
5
|
export const initReact = (allTranslations, initialLocale, extraFormatters) => {
|
|
@@ -10,14 +10,16 @@ export const initReact = (allTranslations, initialLocale, extraFormatters) => {
|
|
|
10
10
|
t: getTranslate(allTranslations[initialLocale], initialLocale, extraFormatters),
|
|
11
11
|
isLoading: false,
|
|
12
12
|
}));
|
|
13
|
-
const setLocaleInternal = async (targetLocale) => {
|
|
13
|
+
const setLocaleInternal = useCallback(async (targetLocale) => {
|
|
14
|
+
if (state.locale === targetLocale)
|
|
15
|
+
return;
|
|
14
16
|
try {
|
|
15
17
|
const translationOrLoader = allTranslations[targetLocale];
|
|
16
18
|
if (typeof translationOrLoader === 'function') {
|
|
17
|
-
setState({
|
|
18
|
-
...
|
|
19
|
+
setState(prev => ({
|
|
20
|
+
...prev,
|
|
19
21
|
isLoading: true,
|
|
20
|
-
});
|
|
22
|
+
}));
|
|
21
23
|
const translationData = await translationOrLoader();
|
|
22
24
|
setState({
|
|
23
25
|
locale: targetLocale,
|
|
@@ -35,12 +37,12 @@ export const initReact = (allTranslations, initialLocale, extraFormatters) => {
|
|
|
35
37
|
}
|
|
36
38
|
catch (error) {
|
|
37
39
|
console.error(`Failed to load translations for locale ${String(targetLocale)}:`, error);
|
|
38
|
-
setState({
|
|
39
|
-
...
|
|
40
|
+
setState(prev => ({
|
|
41
|
+
...prev,
|
|
40
42
|
isLoading: false,
|
|
41
|
-
});
|
|
43
|
+
}));
|
|
42
44
|
}
|
|
43
|
-
};
|
|
45
|
+
}, [allTranslations, extraFormatters, state.locale]);
|
|
44
46
|
return (_jsx(TranslationContext.Provider, { value: {
|
|
45
47
|
...state,
|
|
46
48
|
setLocale: setLocaleInternal,
|