typed-locales 1.0.61 → 1.0.63
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.d.ts","sourceRoot":"","sources":["../../src/adapters/react.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/adapters/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAEf,OAAO,EACN,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,OAAO,EAEZ,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAMD,KAAK,gBAAgB,GAAG;KACtB,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM;CAC5B,GAAG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,KAAK,iBAAiB,GAAG,gBAAgB,EAAE,CAAC;AA0B5C,eAAO,MAAM,SAAS,GACrB,qBAAqB,MAAM,EAC3B,iBAAiB,MAAM,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,EACpE,iBAAiB,eAAe,EAChC,eAAe,OAAO,EACtB,oBAAoB,iBAAiB,oBAEM;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,4CAoFxE,CAAC;AAEF,eAAO,MAAM,cAAc,8BAM1B,CAAC"}
|
package/dist/adapters/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useContext, useState } from 'react';
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, useState, } from 'react';
|
|
3
3
|
import { getTranslate, } from '../index.js';
|
|
4
4
|
const TranslationContext = createContext(undefined);
|
|
5
5
|
const addExtraTranslations = (translation, extraTranslations, locale) => {
|
|
@@ -23,7 +23,7 @@ const addExtraTranslations = (translation, extraTranslations, locale) => {
|
|
|
23
23
|
// Initial translation always should be loaded
|
|
24
24
|
export const initReact = (defaultTranslations, allTranslations, extraFormatters, defaultLocale, extraTranslations) => {
|
|
25
25
|
const TranslationProvider = ({ children }) => {
|
|
26
|
-
const defaultTranslate = getTranslate(addExtraTranslations(defaultTranslations, extraTranslations ?? [], defaultLocale), defaultLocale, extraFormatters);
|
|
26
|
+
const defaultTranslate = useMemo(() => getTranslate(addExtraTranslations(defaultTranslations, extraTranslations ?? [], defaultLocale), defaultLocale, extraFormatters), []);
|
|
27
27
|
const [state, setState] = useState({
|
|
28
28
|
isLoading: false,
|
|
29
29
|
locale: defaultLocale,
|
|
@@ -35,6 +35,9 @@ export const initReact = (defaultTranslations, allTranslations, extraFormatters,
|
|
|
35
35
|
}
|
|
36
36
|
try {
|
|
37
37
|
const translationOrLoader = allTranslations[targetLocale];
|
|
38
|
+
if (!translationOrLoader) {
|
|
39
|
+
throw new Error(`Translation loader for locale ${targetLocale} not found`);
|
|
40
|
+
}
|
|
38
41
|
const translationData = (await translationOrLoader().then(t => t.default));
|
|
39
42
|
setState({
|
|
40
43
|
isLoading: false,
|
|
@@ -47,7 +50,7 @@ export const initReact = (defaultTranslations, allTranslations, extraFormatters,
|
|
|
47
50
|
setState(previous => ({ ...previous, isLoading: false }));
|
|
48
51
|
}
|
|
49
52
|
return targetLocale;
|
|
50
|
-
}, [
|
|
53
|
+
}, [defaultTranslate, state.locale]);
|
|
51
54
|
return (_jsx(TranslationContext.Provider, { value: {
|
|
52
55
|
isLoading: state.isLoading,
|
|
53
56
|
locale: state.locale,
|