@umituz/react-native-localization 3.2.2 → 3.2.5
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.2.
|
|
3
|
+
"version": "3.2.5",
|
|
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",
|
|
@@ -60,12 +60,13 @@
|
|
|
60
60
|
"@testing-library/jest-native": "^5.4.3",
|
|
61
61
|
"@testing-library/react": "^16.3.0",
|
|
62
62
|
"@testing-library/react-hooks": "^8.0.1",
|
|
63
|
+
"@react-navigation/native": "^6.1.17",
|
|
63
64
|
"@testing-library/react-native": "^13.3.3",
|
|
64
65
|
"@types/react": "^18.2.45",
|
|
65
66
|
"@types/react-native": "^0.73.0",
|
|
66
67
|
"@umituz/react-native-design-system-theme": "^1.8.0",
|
|
67
68
|
"@umituz/react-native-filesystem": "^1.4.0",
|
|
68
|
-
"@umituz/react-native-storage": "^
|
|
69
|
+
"@umituz/react-native-storage": "^2.4.0",
|
|
69
70
|
"expo-localization": "~15.0.0",
|
|
70
71
|
"i18next": "^23.0.0",
|
|
71
72
|
"jest": "^30.2.0",
|
|
@@ -90,4 +91,4 @@
|
|
|
90
91
|
"README.md",
|
|
91
92
|
"LICENSE"
|
|
92
93
|
]
|
|
93
|
-
}
|
|
94
|
+
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { useCallback, useMemo } from 'react';
|
|
13
13
|
import i18n from '../config/i18n';
|
|
14
|
-
import {
|
|
14
|
+
import { translationCache } from '../config/TranslationCache';
|
|
15
15
|
|
|
16
16
|
export interface TranslationOptions {
|
|
17
17
|
count?: number;
|
|
@@ -20,7 +20,6 @@ export interface TranslationOptions {
|
|
|
20
20
|
[key: string]: any;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const translationCache = new TranslationCache();
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Hook for translation functionality
|
|
@@ -41,7 +40,7 @@ export const useTranslationFunction = () => {
|
|
|
41
40
|
|
|
42
41
|
// Create cache key
|
|
43
42
|
const cacheKey = `${key}:${JSON.stringify(options)}`;
|
|
44
|
-
|
|
43
|
+
|
|
45
44
|
// Check cache first
|
|
46
45
|
const cached = translationCache.get(cacheKey);
|
|
47
46
|
if (cached) {
|
|
@@ -67,7 +66,7 @@ export const useTranslationFunction = () => {
|
|
|
67
66
|
if (hasNamespace) {
|
|
68
67
|
const namespacedKey = `${potentialNamespace}:${restOfKey}`;
|
|
69
68
|
const namespacedResult = i18n.t(namespacedKey, options);
|
|
70
|
-
|
|
69
|
+
|
|
71
70
|
// If translation found (not same as key), use it
|
|
72
71
|
if (namespacedResult !== namespacedKey && namespacedResult !== restOfKey) {
|
|
73
72
|
result = typeof namespacedResult === 'string' ? namespacedResult : key;
|
|
@@ -8,6 +8,7 @@ import type { LocalizationState, LocalizationActions, LocalizationGetters, Langu
|
|
|
8
8
|
import { LanguageInitializer } from './LanguageInitializer';
|
|
9
9
|
import { LanguageSwitcher } from './LanguageSwitcher';
|
|
10
10
|
import { languageRegistry } from '../config/languagesData';
|
|
11
|
+
import { translationCache } from '../config/TranslationCache';
|
|
11
12
|
|
|
12
13
|
interface LocalizationStore extends LocalizationState, LocalizationActions, LocalizationGetters {
|
|
13
14
|
// Additional properties can be added here if needed
|
|
@@ -61,10 +62,15 @@ export const createLocalizationStore = () => {
|
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
|
|
65
|
+
|
|
66
|
+
|
|
64
67
|
setLanguage: async (languageCode: string) => {
|
|
65
68
|
try {
|
|
66
69
|
const result = await LanguageSwitcher.switchLanguage(languageCode);
|
|
67
70
|
|
|
71
|
+
// Clear translation cache to ensure new keys are fetched
|
|
72
|
+
translationCache.clear();
|
|
73
|
+
|
|
68
74
|
set({
|
|
69
75
|
currentLanguage: result.languageCode,
|
|
70
76
|
isRTL: result.isRTL,
|