@better-i18n/expo 0.7.2 → 0.7.3
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/use-locale-switcher.d.ts +40 -0
- package/dist/use-locale-switcher.d.ts.map +1 -0
- package/dist/use-locale-switcher.js +43 -0
- package/dist/use-locale-switcher.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { initBetterI18n, getLanguages, subscribeLanguages, getLanguagesSnapshot, refreshLanguages } from "./helpers.js";
|
|
2
2
|
export type { InitBetterI18nOptions, BetterI18nResult } from "./helpers.js";
|
|
3
3
|
export { useLanguages } from "./hooks.js";
|
|
4
|
+
export { useLocaleSwitcher } from "./use-locale-switcher.js";
|
|
5
|
+
export type { UseLocaleSwitcherReturn } from "./use-locale-switcher.js";
|
|
4
6
|
export { getDeviceLocale, getDeviceLocales } from "./locale.js";
|
|
5
7
|
export { createMemoryStorage, storageAdapter } from "./storage.js";
|
|
6
8
|
export type { MMKVLike, AsyncStorageLike } from "./types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACxH,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACxH,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG7D,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEpF,+CAA+C;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,YAAY,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export { initBetterI18n, getLanguages, subscribeLanguages, getLanguagesSnapshot, refreshLanguages } from "./helpers.js";
|
|
3
3
|
// React hooks
|
|
4
4
|
export { useLanguages } from "./hooks.js";
|
|
5
|
+
export { useLocaleSwitcher } from "./use-locale-switcher.js";
|
|
5
6
|
// Locale detection
|
|
6
7
|
export { getDeviceLocale, getDeviceLocales } from "./locale.js";
|
|
7
8
|
// Storage
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGxH,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGxH,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,mBAAmB;AACnB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEhE,UAAU;AACV,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAMnE,+CAA+C;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LanguageOption } from "@better-i18n/core";
|
|
2
|
+
export interface UseLocaleSwitcherReturn {
|
|
3
|
+
/** Available languages from the CDN manifest. Empty array before `initBetterI18n` completes. */
|
|
4
|
+
languages: LanguageOption[];
|
|
5
|
+
/** Current active locale (normalized to lowercase BCP 47). */
|
|
6
|
+
currentLocale: string;
|
|
7
|
+
/** Switch to a new locale. Pre-loads translations before switching to prevent flash. */
|
|
8
|
+
changeLocale: (locale: string) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Hook for building a custom locale switcher UI in React Native.
|
|
12
|
+
*
|
|
13
|
+
* Combines `useLanguages()` for the language list with `i18next.changeLanguage()`
|
|
14
|
+
* (pre-patched by `initBetterI18n` to pre-load translations before switching).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useLocaleSwitcher } from '@better-i18n/expo';
|
|
19
|
+
*
|
|
20
|
+
* function LanguagePicker() {
|
|
21
|
+
* const { languages, currentLocale, changeLocale } = useLocaleSwitcher();
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <FlatList
|
|
25
|
+
* data={languages}
|
|
26
|
+
* keyExtractor={(item) => item.code}
|
|
27
|
+
* renderItem={({ item }) => (
|
|
28
|
+
* <Pressable onPress={() => changeLocale(item.code)}>
|
|
29
|
+
* <Text style={item.code === currentLocale ? styles.active : undefined}>
|
|
30
|
+
* {item.nativeName || item.code}
|
|
31
|
+
* </Text>
|
|
32
|
+
* </Pressable>
|
|
33
|
+
* )}
|
|
34
|
+
* />
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function useLocaleSwitcher(): UseLocaleSwitcherReturn;
|
|
40
|
+
//# sourceMappingURL=use-locale-switcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-locale-switcher.d.ts","sourceRoot":"","sources":["../src/use-locale-switcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,MAAM,WAAW,uBAAuB;IACtC,gGAAgG;IAChG,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,8DAA8D;IAC9D,aAAa,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,iBAAiB,IAAI,uBAAuB,CAiB3D"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { normalizeLocale } from "@better-i18n/core";
|
|
4
|
+
import { useLanguages } from "./hooks.js";
|
|
5
|
+
/**
|
|
6
|
+
* Hook for building a custom locale switcher UI in React Native.
|
|
7
|
+
*
|
|
8
|
+
* Combines `useLanguages()` for the language list with `i18next.changeLanguage()`
|
|
9
|
+
* (pre-patched by `initBetterI18n` to pre-load translations before switching).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useLocaleSwitcher } from '@better-i18n/expo';
|
|
14
|
+
*
|
|
15
|
+
* function LanguagePicker() {
|
|
16
|
+
* const { languages, currentLocale, changeLocale } = useLocaleSwitcher();
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <FlatList
|
|
20
|
+
* data={languages}
|
|
21
|
+
* keyExtractor={(item) => item.code}
|
|
22
|
+
* renderItem={({ item }) => (
|
|
23
|
+
* <Pressable onPress={() => changeLocale(item.code)}>
|
|
24
|
+
* <Text style={item.code === currentLocale ? styles.active : undefined}>
|
|
25
|
+
* {item.nativeName || item.code}
|
|
26
|
+
* </Text>
|
|
27
|
+
* </Pressable>
|
|
28
|
+
* )}
|
|
29
|
+
* />
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function useLocaleSwitcher() {
|
|
35
|
+
const languages = useLanguages();
|
|
36
|
+
const { i18n } = useTranslation();
|
|
37
|
+
const currentLocale = useMemo(() => normalizeLocale(i18n.language), [i18n.language]);
|
|
38
|
+
const changeLocale = useCallback(async (locale) => {
|
|
39
|
+
await i18n.changeLanguage(normalizeLocale(locale));
|
|
40
|
+
}, [i18n]);
|
|
41
|
+
return { languages, currentLocale, changeLocale };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=use-locale-switcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-locale-switcher.js","sourceRoot":"","sources":["../src/use-locale-switcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAW1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC;IAElC,MAAM,aAAa,GAAG,OAAO,CAC3B,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EACpC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAChB,CAAC;IAEF,MAAM,YAAY,GAAG,WAAW,CAC9B,KAAK,EAAE,MAAc,EAAE,EAAE;QACvB,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;IAEF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AACpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-i18n/expo",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Better i18n backend plugin for i18next in Expo/React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"prepublishOnly": "bun run build"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@better-i18n/core": "0.
|
|
53
|
+
"@better-i18n/core": "0.3.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": ">=18.0.0",
|