@umituz/react-native-localization 3.5.38 → 3.5.40
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-localization",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.40",
|
|
4
4
|
"description": "Generic localization system for React Native apps with i18n support",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@react-native-async-storage/async-storage": ">=2.0.0",
|
|
29
|
+
"@umituz/react-native-storage": "*",
|
|
29
30
|
"expo-localization": ">=16.0.0",
|
|
30
31
|
"i18next": ">=23.0.0",
|
|
31
32
|
"react": ">=18.2.0",
|
|
@@ -34,9 +35,10 @@
|
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@react-native-async-storage/async-storage": "~2.1.2",
|
|
38
|
+
"@types/react": "~19.1.10",
|
|
39
|
+
"@umituz/react-native-storage": "*",
|
|
37
40
|
"expo-localization": "~16.0.1",
|
|
38
41
|
"i18next": "^24.2.0",
|
|
39
|
-
"@types/react": "~19.1.10",
|
|
40
42
|
"react": "19.1.0",
|
|
41
43
|
"react-i18next": "^15.2.0",
|
|
42
44
|
"react-native": "0.81.5",
|
|
@@ -3,83 +3,85 @@
|
|
|
3
3
|
* Creates and manages localization state with proper separation of concerns
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { createStore } from '@umituz/react-native-storage';
|
|
7
7
|
import type { LocalizationState, LocalizationActions, LocalizationGetters } from './types/LocalizationState';
|
|
8
8
|
import { LanguageInitializer } from './LanguageInitializer';
|
|
9
9
|
import { LanguageSwitcher } from './LanguageSwitcher';
|
|
10
10
|
import { languageRegistry } from '../config/languagesData';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type LocalizationStoreActions = LocalizationActions & LocalizationGetters;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// State
|
|
21
|
-
currentLanguage: 'en-US',
|
|
22
|
-
isRTL: false,
|
|
23
|
-
isInitialized: false,
|
|
24
|
-
supportedLanguages: languageRegistry.getLanguages(),
|
|
25
|
-
|
|
26
|
-
// Actions
|
|
27
|
-
initialize: async () => {
|
|
28
|
-
const { isInitialized: alreadyInitialized } = get();
|
|
29
|
-
if (alreadyInitialized) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const result = await LanguageInitializer.initialize();
|
|
14
|
+
const initialLocalizationState: LocalizationState = {
|
|
15
|
+
currentLanguage: 'en-US',
|
|
16
|
+
isRTL: false,
|
|
17
|
+
isInitialized: false,
|
|
18
|
+
supportedLanguages: languageRegistry.getLanguages(),
|
|
19
|
+
};
|
|
35
20
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
21
|
+
// Create singleton instance
|
|
22
|
+
export const useLocalizationStore = createStore<LocalizationState, LocalizationStoreActions>({
|
|
23
|
+
name: 'localization-store',
|
|
24
|
+
initialState: initialLocalizationState,
|
|
25
|
+
persist: false,
|
|
26
|
+
actions: (set, get) => ({
|
|
27
|
+
// Actions
|
|
28
|
+
initialize: async () => {
|
|
29
|
+
const { isInitialized: alreadyInitialized } = get();
|
|
30
|
+
if (alreadyInitialized) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
49
33
|
|
|
50
|
-
|
|
51
|
-
const result = await
|
|
34
|
+
try {
|
|
35
|
+
const result = await LanguageInitializer.initialize();
|
|
52
36
|
|
|
53
37
|
set({
|
|
54
38
|
currentLanguage: result.languageCode,
|
|
55
39
|
isRTL: result.isRTL,
|
|
40
|
+
isInitialized: true,
|
|
56
41
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
reset: () => {
|
|
42
|
+
} catch {
|
|
60
43
|
set({
|
|
61
44
|
currentLanguage: 'en-US',
|
|
62
45
|
isRTL: false,
|
|
63
|
-
isInitialized:
|
|
46
|
+
isInitialized: true,
|
|
64
47
|
});
|
|
65
|
-
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
66
50
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const { currentLanguage } = get();
|
|
70
|
-
return languageRegistry.getLanguageByCode(currentLanguage);
|
|
71
|
-
},
|
|
51
|
+
setLanguage: async (languageCode: string) => {
|
|
52
|
+
const result = await LanguageSwitcher.switchLanguage(languageCode);
|
|
72
53
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
54
|
+
set({
|
|
55
|
+
currentLanguage: result.languageCode,
|
|
56
|
+
isRTL: result.isRTL,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
60
|
+
reset: () => {
|
|
61
|
+
set({
|
|
62
|
+
currentLanguage: 'en-US',
|
|
63
|
+
isRTL: false,
|
|
64
|
+
isInitialized: false,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
83
67
|
|
|
84
|
-
//
|
|
85
|
-
|
|
68
|
+
// Getters
|
|
69
|
+
getCurrentLanguage: () => {
|
|
70
|
+
const { currentLanguage } = get();
|
|
71
|
+
return languageRegistry.getLanguageByCode(currentLanguage);
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
isLanguageSupported: (code: string) => {
|
|
75
|
+
return languageRegistry.isLanguageSupported(code);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
getSupportedLanguages: () => {
|
|
79
|
+
return languageRegistry.getLanguages();
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Use useLocalizationStore directly
|
|
86
|
+
*/
|
|
87
|
+
export const createLocalizationStore = () => useLocalizationStore;
|