typed-locales 1.0.38 → 1.0.39
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/dist/react.d.ts.map +1 -1
- package/dist/react.js +5 -9
- package/package.json +1 -1
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpG,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAGD,eAAO,MAAM,SAAS,GACrB,oBAAoB,eAAe,EACnC,eAAe,OAAO,EACtB,iBAAiB,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC,GAAG,eAAe,CAAC,EACpF,iBAAiB,eAAe;wCAKW;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;CAkExE,CAAC"}
|
package/dist/react.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 = (initialTranslation, initialLocale, allTranslations, extraFormatters) => {
|
|
@@ -11,7 +11,7 @@ export const initReact = (initialTranslation, initialLocale, allTranslations, ex
|
|
|
11
11
|
locale: initialLocale,
|
|
12
12
|
translate: initialTranslate,
|
|
13
13
|
});
|
|
14
|
-
const
|
|
14
|
+
const setLocale = useCallback(async (targetLocale) => {
|
|
15
15
|
try {
|
|
16
16
|
const translationOrLoader = allTranslations[targetLocale];
|
|
17
17
|
let translationData;
|
|
@@ -32,16 +32,12 @@ export const initReact = (initialTranslation, initialLocale, allTranslations, ex
|
|
|
32
32
|
console.error(`Failed to load translations for locale ${String(targetLocale)}:`, error);
|
|
33
33
|
setState(previous => ({ ...previous, isLoading: false }));
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
return targetLocale;
|
|
36
|
+
}, []);
|
|
36
37
|
return (_jsx(TranslationContext.Provider, { value: {
|
|
37
38
|
isLoading: state.isLoading,
|
|
38
39
|
locale: state.locale,
|
|
39
|
-
setLocale
|
|
40
|
-
if (newLocale !== state.locale) {
|
|
41
|
-
await loadTranslation(newLocale);
|
|
42
|
-
}
|
|
43
|
-
return newLocale;
|
|
44
|
-
},
|
|
40
|
+
setLocale,
|
|
45
41
|
t: state.translate,
|
|
46
42
|
}, children: children }));
|
|
47
43
|
};
|