@snack-uikit/locale 0.13.1-preview-2289a98e.0 → 0.14.0
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/CHANGELOG.md +11 -0
- package/README.md +1 -0
- package/dist/cjs/components/LocaleProvider/LocaleProvider.d.ts +3 -2
- package/dist/cjs/components/LocaleProvider/LocaleProvider.js +3 -2
- package/dist/esm/components/LocaleProvider/LocaleProvider.d.ts +3 -2
- package/dist/esm/components/LocaleProvider/LocaleProvider.js +3 -3
- package/package.json +2 -2
- package/src/components/LocaleProvider/LocaleProvider.tsx +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 0.14.0 (2025-03-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **FF-6326:** locale support for dictionary extensions ([867a28c](https://github.com/cloud-ru-tech/snack-uikit/commit/867a28cf18a8b8c7ee34621daac204533b713d60))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 0.13.0 (2025-03-14)
|
|
7
18
|
|
|
8
19
|
|
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@ const lang = 'en_GB'; // or 'ru_RU' or 'custom_LANG'
|
|
|
54
54
|
| name | type | default value | description |
|
|
55
55
|
|------|------|---------------|-------------|
|
|
56
56
|
| lang* | `string` | - | |
|
|
57
|
+
| fallbackLang | "en-GB" \| "ru-RU" | - | |
|
|
57
58
|
| overrideLocales | `PartialObjectDeep<Record<"en-GB" \| "ru-RU", LocaleDictionary<Dictionary>>>` | - | |
|
|
58
59
|
## useLocale
|
|
59
60
|
`helper`
|
|
@@ -8,6 +8,7 @@ export type LocaleContextType<D extends Dictionary> = {
|
|
|
8
8
|
};
|
|
9
9
|
export type LocaleProviderProps<D extends Dictionary> = {
|
|
10
10
|
lang: LocaleLang | string;
|
|
11
|
+
fallbackLang?: LocaleLang;
|
|
11
12
|
overrideLocales?: OverrideLocales<D>;
|
|
12
13
|
children: ReactNode;
|
|
13
14
|
};
|
|
@@ -19,7 +20,7 @@ type LocaleComponentName<D extends Dictionary> = keyof LocaleDictionary<D>;
|
|
|
19
20
|
type GetLocaleText<D extends Dictionary, T extends keyof LocaleDictionary<D> | undefined = undefined> = (key: DottedTranslationKey<D, T>) => string;
|
|
20
21
|
export declare function createLocaleContext<D extends Dictionary>({ extendedDictionary, defaultLanguage, }: ContextOptions<D>): {
|
|
21
22
|
LocaleContext: import("react").Context<LocaleContextType<D>>;
|
|
22
|
-
LocaleProvider: ({ lang, overrideLocales, children }: LocaleProviderProps<D>) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
LocaleProvider: ({ lang, fallbackLang, overrideLocales, children }: LocaleProviderProps<D>) => import("react/jsx-runtime").JSX.Element;
|
|
23
24
|
useLocale: {
|
|
24
25
|
(): {
|
|
25
26
|
t: GetLocaleText<D>;
|
|
@@ -31,7 +32,7 @@ export declare function createLocaleContext<D extends Dictionary>({ extendedDict
|
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
|
-
export declare const LocaleProvider: ({ lang, overrideLocales, children }: LocaleProviderProps<Dictionary>) => import("react/jsx-runtime").JSX.Element, useLocale: {
|
|
35
|
+
export declare const LocaleProvider: ({ lang, fallbackLang, overrideLocales, children }: LocaleProviderProps<Dictionary>) => import("react/jsx-runtime").JSX.Element, useLocale: {
|
|
35
36
|
(): {
|
|
36
37
|
t: GetLocaleText<Dictionary>;
|
|
37
38
|
lang: LocaleLang;
|
|
@@ -33,6 +33,7 @@ function createLocaleContext(_ref) {
|
|
|
33
33
|
function LocaleProvider(_ref2) {
|
|
34
34
|
let {
|
|
35
35
|
lang,
|
|
36
|
+
fallbackLang = defaultLanguage,
|
|
36
37
|
overrideLocales,
|
|
37
38
|
children
|
|
38
39
|
} = _ref2;
|
|
@@ -46,10 +47,10 @@ function createLocaleContext(_ref) {
|
|
|
46
47
|
let localesObj = locales[lang];
|
|
47
48
|
if (!localesObj) {
|
|
48
49
|
console.warn(`Snack-uikit: localization for lang ${lang} was not found. Make sure you are using correct lang or passed proper locales to LocaleProvider. For now default language (${exports.DEFAULT_LANG}) will be used`);
|
|
49
|
-
localesObj = locales[
|
|
50
|
+
localesObj = locales[fallbackLang];
|
|
50
51
|
}
|
|
51
52
|
return localesObj;
|
|
52
|
-
}, [lang, locales]);
|
|
53
|
+
}, [fallbackLang, lang, locales]);
|
|
53
54
|
return (0, jsx_runtime_1.jsx)(LocaleContext.Provider, {
|
|
54
55
|
value: {
|
|
55
56
|
lang,
|
|
@@ -8,6 +8,7 @@ export type LocaleContextType<D extends Dictionary> = {
|
|
|
8
8
|
};
|
|
9
9
|
export type LocaleProviderProps<D extends Dictionary> = {
|
|
10
10
|
lang: LocaleLang | string;
|
|
11
|
+
fallbackLang?: LocaleLang;
|
|
11
12
|
overrideLocales?: OverrideLocales<D>;
|
|
12
13
|
children: ReactNode;
|
|
13
14
|
};
|
|
@@ -19,7 +20,7 @@ type LocaleComponentName<D extends Dictionary> = keyof LocaleDictionary<D>;
|
|
|
19
20
|
type GetLocaleText<D extends Dictionary, T extends keyof LocaleDictionary<D> | undefined = undefined> = (key: DottedTranslationKey<D, T>) => string;
|
|
20
21
|
export declare function createLocaleContext<D extends Dictionary>({ extendedDictionary, defaultLanguage, }: ContextOptions<D>): {
|
|
21
22
|
LocaleContext: import("react").Context<LocaleContextType<D>>;
|
|
22
|
-
LocaleProvider: ({ lang, overrideLocales, children }: LocaleProviderProps<D>) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
LocaleProvider: ({ lang, fallbackLang, overrideLocales, children }: LocaleProviderProps<D>) => import("react/jsx-runtime").JSX.Element;
|
|
23
24
|
useLocale: {
|
|
24
25
|
(): {
|
|
25
26
|
t: GetLocaleText<D>;
|
|
@@ -31,7 +32,7 @@ export declare function createLocaleContext<D extends Dictionary>({ extendedDict
|
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
|
-
export declare const LocaleProvider: ({ lang, overrideLocales, children }: LocaleProviderProps<Dictionary>) => import("react/jsx-runtime").JSX.Element, useLocale: {
|
|
35
|
+
export declare const LocaleProvider: ({ lang, fallbackLang, overrideLocales, children }: LocaleProviderProps<Dictionary>) => import("react/jsx-runtime").JSX.Element, useLocale: {
|
|
35
36
|
(): {
|
|
36
37
|
t: GetLocaleText<Dictionary>;
|
|
37
38
|
lang: LocaleLang;
|
|
@@ -13,7 +13,7 @@ export function createLocaleContext({ extendedDictionary, defaultLanguage = DEFA
|
|
|
13
13
|
locales: extendedLocales,
|
|
14
14
|
localesByLang: extendedLocales[defaultLanguage],
|
|
15
15
|
});
|
|
16
|
-
function LocaleProvider({ lang, overrideLocales, children }) {
|
|
16
|
+
function LocaleProvider({ lang, fallbackLang = defaultLanguage, overrideLocales, children }) {
|
|
17
17
|
const locales = useMemo(() => {
|
|
18
18
|
if (overrideLocales) {
|
|
19
19
|
return merge({}, extendedLocales, overrideLocales);
|
|
@@ -24,10 +24,10 @@ export function createLocaleContext({ extendedDictionary, defaultLanguage = DEFA
|
|
|
24
24
|
let localesObj = locales[lang];
|
|
25
25
|
if (!localesObj) {
|
|
26
26
|
console.warn(`Snack-uikit: localization for lang ${lang} was not found. Make sure you are using correct lang or passed proper locales to LocaleProvider. For now default language (${DEFAULT_LANG}) will be used`);
|
|
27
|
-
localesObj = locales[
|
|
27
|
+
localesObj = locales[fallbackLang];
|
|
28
28
|
}
|
|
29
29
|
return localesObj;
|
|
30
|
-
}, [lang, locales]);
|
|
30
|
+
}, [fallbackLang, lang, locales]);
|
|
31
31
|
return _jsx(LocaleContext.Provider, { value: { lang, locales, localesByLang }, children: children });
|
|
32
32
|
}
|
|
33
33
|
function useLocale(componentName) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Locale",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.14.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/lodash.merge": "4.6.9"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "2c50d707746c6aeab336e4097df6e4c8494d67a4"
|
|
45
45
|
}
|
|
@@ -23,6 +23,7 @@ export type LocaleContextType<D extends Dictionary> = {
|
|
|
23
23
|
|
|
24
24
|
export type LocaleProviderProps<D extends Dictionary> = {
|
|
25
25
|
lang: LocaleLang | string;
|
|
26
|
+
fallbackLang?: LocaleLang;
|
|
26
27
|
overrideLocales?: OverrideLocales<D>;
|
|
27
28
|
children: ReactNode;
|
|
28
29
|
};
|
|
@@ -56,7 +57,7 @@ export function createLocaleContext<D extends Dictionary>({
|
|
|
56
57
|
localesByLang: extendedLocales[defaultLanguage],
|
|
57
58
|
});
|
|
58
59
|
|
|
59
|
-
function LocaleProvider({ lang, overrideLocales, children }: LocaleProviderProps<D>) {
|
|
60
|
+
function LocaleProvider({ lang, fallbackLang = defaultLanguage, overrideLocales, children }: LocaleProviderProps<D>) {
|
|
60
61
|
const locales = useMemo(() => {
|
|
61
62
|
if (overrideLocales) {
|
|
62
63
|
return merge({}, extendedLocales, overrideLocales);
|
|
@@ -73,11 +74,11 @@ export function createLocaleContext<D extends Dictionary>({
|
|
|
73
74
|
`Snack-uikit: localization for lang ${lang} was not found. Make sure you are using correct lang or passed proper locales to LocaleProvider. For now default language (${DEFAULT_LANG}) will be used`,
|
|
74
75
|
);
|
|
75
76
|
|
|
76
|
-
localesObj = locales[
|
|
77
|
+
localesObj = locales[fallbackLang] as LocaleDictionary<D>;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
return localesObj;
|
|
80
|
-
}, [lang, locales]);
|
|
81
|
+
}, [fallbackLang, lang, locales]);
|
|
81
82
|
|
|
82
83
|
return <LocaleContext.Provider value={{ lang, locales, localesByLang }}>{children}</LocaleContext.Provider>;
|
|
83
84
|
}
|