@umituz/react-native-localization 1.5.0 → 1.5.2
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 +1 -6
- package/src/infrastructure/config/i18n.ts +2 -34
- package/src/infrastructure/config/languages.ts +0 -1
- package/src/infrastructure/storage/AsyncStorageWrapper.ts +1 -2
- package/src/infrastructure/storage/LocalizationStore.ts +0 -62
- package/lib/domain/repositories/ILocalizationRepository.d.ts +0 -17
- package/lib/domain/repositories/ILocalizationRepository.d.ts.map +0 -1
- package/lib/domain/repositories/ILocalizationRepository.js +0 -6
- package/lib/domain/repositories/ILocalizationRepository.js.map +0 -1
- package/lib/index.d.ts +0 -13
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -15
- package/lib/index.js.map +0 -1
- package/lib/infrastructure/components/LanguageSwitcher.d.ts +0 -12
- package/lib/infrastructure/components/LanguageSwitcher.d.ts.map +0 -1
- package/lib/infrastructure/components/LanguageSwitcher.js +0 -49
- package/lib/infrastructure/components/LanguageSwitcher.js.map +0 -1
- package/lib/infrastructure/components/LocalizationProvider.d.ts +0 -11
- package/lib/infrastructure/components/LocalizationProvider.d.ts.map +0 -1
- package/lib/infrastructure/components/LocalizationProvider.js +0 -14
- package/lib/infrastructure/components/LocalizationProvider.js.map +0 -1
- package/lib/infrastructure/components/useLanguageNavigation.d.ts +0 -6
- package/lib/infrastructure/components/useLanguageNavigation.d.ts.map +0 -1
- package/lib/infrastructure/components/useLanguageNavigation.js +0 -16
- package/lib/infrastructure/components/useLanguageNavigation.js.map +0 -1
- package/lib/infrastructure/config/i18n.d.ts +0 -12
- package/lib/infrastructure/config/i18n.d.ts.map +0 -1
- package/lib/infrastructure/config/i18n.js +0 -269
- package/lib/infrastructure/config/i18n.js.map +0 -1
- package/lib/infrastructure/config/languages.d.ts +0 -39
- package/lib/infrastructure/config/languages.d.ts.map +0 -1
- package/lib/infrastructure/config/languages.js +0 -210
- package/lib/infrastructure/config/languages.js.map +0 -1
- package/lib/infrastructure/config/languagesData.d.ts +0 -26
- package/lib/infrastructure/config/languagesData.d.ts.map +0 -1
- package/lib/infrastructure/config/languagesData.js +0 -58
- package/lib/infrastructure/config/languagesData.js.map +0 -1
- package/lib/infrastructure/locales/en-US/index.d.ts +0 -29
- package/lib/infrastructure/locales/en-US/index.d.ts.map +0 -1
- package/lib/infrastructure/locales/en-US/index.js +0 -40
- package/lib/infrastructure/locales/en-US/index.js.map +0 -1
- package/lib/infrastructure/storage/AsyncStorageWrapper.d.ts +0 -12
- package/lib/infrastructure/storage/AsyncStorageWrapper.d.ts.map +0 -1
- package/lib/infrastructure/storage/AsyncStorageWrapper.js +0 -29
- package/lib/infrastructure/storage/AsyncStorageWrapper.js.map +0 -1
- package/lib/infrastructure/storage/LocalizationStore.d.ts +0 -31
- package/lib/infrastructure/storage/LocalizationStore.d.ts.map +0 -1
- package/lib/infrastructure/storage/LocalizationStore.js +0 -192
- package/lib/infrastructure/storage/LocalizationStore.js.map +0 -1
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-loader for en-US translation modules
|
|
3
|
-
*
|
|
4
|
-
* AUTOMATIC TRANSLATION FILE DETECTION:
|
|
5
|
-
* - Uses Metro bundler's require.context to auto-discover .json files
|
|
6
|
-
* - Adding new translation file = just create .json file (zero manual updates)
|
|
7
|
-
* - Build-time resolution (fast, no runtime overhead)
|
|
8
|
-
* - Works for all languages automatically
|
|
9
|
-
*
|
|
10
|
-
* OFFLINE-ONLY TRANSLATIONS (All domains work without backend):
|
|
11
|
-
* - Automatically imports ALL .json files in this directory
|
|
12
|
-
* - Alphabetically sorted for consistency
|
|
13
|
-
* - Type-safe with TypeScript
|
|
14
|
-
*
|
|
15
|
-
* USAGE:
|
|
16
|
-
* 1. Create new translation file: my_domain.json
|
|
17
|
-
* 2. File is auto-discovered and loaded
|
|
18
|
-
* 3. Access via t('my_domain.key')
|
|
19
|
-
*
|
|
20
|
-
* This file is automatically generated by setup-languages.js script
|
|
21
|
-
* but can be manually edited if needed.
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Load all JSON modules automatically
|
|
25
|
-
* Extracts module name from path (e.g., './auth.json' -> 'auth')
|
|
26
|
-
*/
|
|
27
|
-
declare const translations: Record<string, any>;
|
|
28
|
-
export default translations;
|
|
29
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/locales/en-US/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH;;;GAGG;AACH,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;AAW7C,eAAe,YAAY,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-loader for en-US translation modules
|
|
3
|
-
*
|
|
4
|
-
* AUTOMATIC TRANSLATION FILE DETECTION:
|
|
5
|
-
* - Uses Metro bundler's require.context to auto-discover .json files
|
|
6
|
-
* - Adding new translation file = just create .json file (zero manual updates)
|
|
7
|
-
* - Build-time resolution (fast, no runtime overhead)
|
|
8
|
-
* - Works for all languages automatically
|
|
9
|
-
*
|
|
10
|
-
* OFFLINE-ONLY TRANSLATIONS (All domains work without backend):
|
|
11
|
-
* - Automatically imports ALL .json files in this directory
|
|
12
|
-
* - Alphabetically sorted for consistency
|
|
13
|
-
* - Type-safe with TypeScript
|
|
14
|
-
*
|
|
15
|
-
* USAGE:
|
|
16
|
-
* 1. Create new translation file: my_domain.json
|
|
17
|
-
* 2. File is auto-discovered and loaded
|
|
18
|
-
* 3. Access via t('my_domain.key')
|
|
19
|
-
*
|
|
20
|
-
* This file is automatically generated by setup-languages.js script
|
|
21
|
-
* but can be manually edited if needed.
|
|
22
|
-
*/
|
|
23
|
-
// Metro bundler require.context - auto-discover all .json files
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
25
|
-
const translationContext = require.context('./', false, /\.json$/);
|
|
26
|
-
/**
|
|
27
|
-
* Load all JSON modules automatically
|
|
28
|
-
* Extracts module name from path (e.g., './auth.json' -> 'auth')
|
|
29
|
-
*/
|
|
30
|
-
const translations = {};
|
|
31
|
-
translationContext.keys().forEach((key) => {
|
|
32
|
-
// Extract module name from path: './auth.json' -> 'auth'
|
|
33
|
-
const match = key.match(/\.\/([^/]+)\.json$/);
|
|
34
|
-
if (match) {
|
|
35
|
-
const moduleName = match[1];
|
|
36
|
-
translations[moduleName] = translationContext(key);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
export default translations;
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/infrastructure/locales/en-US/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,gEAAgE;AAChE,iEAAiE;AACjE,MAAM,kBAAkB,GAAI,OAAe,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAE5E;;;GAGG;AACH,MAAM,YAAY,GAAwB,EAAE,CAAC;AAE7C,kBAAkB,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;IAChD,yDAAyD;IACzD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9C,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5B,YAAY,CAAC,UAAU,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,eAAe,YAAY,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AsyncStorage Wrapper
|
|
3
|
-
* Simple wrapper for AsyncStorage operations
|
|
4
|
-
*/
|
|
5
|
-
export declare const STORAGE_KEYS: {
|
|
6
|
-
readonly LANGUAGE: "@localization:language";
|
|
7
|
-
};
|
|
8
|
-
export declare const StorageWrapper: {
|
|
9
|
-
getString(key: string, defaultValue: string): Promise<string>;
|
|
10
|
-
setString(key: string, value: string): Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=AsyncStorageWrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncStorageWrapper.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/storage/AsyncStorageWrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,eAAO,MAAM,YAAY;;CAEf,CAAC;AAEX,eAAO,MAAM,cAAc;mBACJ,MAAM,gBAAgB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;mBAU9C,MAAM,SAAS,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAO3D,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AsyncStorage Wrapper
|
|
3
|
-
* Simple wrapper for AsyncStorage operations
|
|
4
|
-
*/
|
|
5
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
6
|
-
export const STORAGE_KEYS = {
|
|
7
|
-
LANGUAGE: '@localization:language',
|
|
8
|
-
};
|
|
9
|
-
export const StorageWrapper = {
|
|
10
|
-
async getString(key, defaultValue) {
|
|
11
|
-
try {
|
|
12
|
-
const value = await AsyncStorage.getItem(key);
|
|
13
|
-
return value ?? defaultValue;
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
console.warn('[Localization] Failed to get storage value:', error);
|
|
17
|
-
return defaultValue;
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
async setString(key, value) {
|
|
21
|
-
try {
|
|
22
|
-
await AsyncStorage.setItem(key, value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
console.warn('[Localization] Failed to set storage value:', error);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=AsyncStorageWrapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncStorageWrapper.js","sourceRoot":"","sources":["../../../src/infrastructure/storage/AsyncStorageWrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,YAAY,MAAM,2CAA2C,CAAC;AAErE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,wBAAwB;CAC1B,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,YAAoB;QAC/C,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO,KAAK,IAAI,YAAY,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;YACnE,OAAO,YAAY,CAAC;QACtB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,KAAa;QACxC,IAAI,CAAC;YACH,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Localization Store
|
|
3
|
-
* Zustand state management for language preferences with AsyncStorage persistence
|
|
4
|
-
*/
|
|
5
|
-
import type { Language } from '../../domain/repositories/ILocalizationRepository';
|
|
6
|
-
interface LocalizationState {
|
|
7
|
-
currentLanguage: string;
|
|
8
|
-
isRTL: boolean;
|
|
9
|
-
isInitialized: boolean;
|
|
10
|
-
supportedLanguages: Language[];
|
|
11
|
-
setLanguage: (languageCode: string) => Promise<void>;
|
|
12
|
-
initialize: () => Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare const useLocalizationStore: import("zustand").UseBoundStore<import("zustand").StoreApi<LocalizationState>>;
|
|
15
|
-
/**
|
|
16
|
-
* Hook to use localization
|
|
17
|
-
* Provides current language, RTL state, language switching, and translation function
|
|
18
|
-
* Uses react-i18next's useTranslation hook to ensure proper i18n instance
|
|
19
|
-
*/
|
|
20
|
-
export declare const useLocalization: () => {
|
|
21
|
-
t: import("i18next").TFunction<"translation", undefined>;
|
|
22
|
-
currentLanguage: string;
|
|
23
|
-
currentLanguageObject: Language;
|
|
24
|
-
isRTL: boolean;
|
|
25
|
-
isInitialized: boolean;
|
|
26
|
-
supportedLanguages: Language[];
|
|
27
|
-
setLanguage: (languageCode: string) => Promise<void>;
|
|
28
|
-
initialize: () => Promise<void>;
|
|
29
|
-
};
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=LocalizationStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationStore.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/storage/LocalizationStore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAElF,UAAU,iBAAiB;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,QAAQ,EAAE,CAAC;IAC/B,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED,eAAO,MAAM,oBAAoB,gFA0J9B,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;;;;gCArKE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;sBAClC,OAAO,CAAC,IAAI,CAAC;CA8LhC,CAAC"}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Localization Store
|
|
3
|
-
* Zustand state management for language preferences with AsyncStorage persistence
|
|
4
|
-
*/
|
|
5
|
-
import { create } from 'zustand';
|
|
6
|
-
import { useTranslation } from 'react-i18next';
|
|
7
|
-
import { StorageWrapper, STORAGE_KEYS } from './AsyncStorageWrapper';
|
|
8
|
-
import i18n from '../config/i18n';
|
|
9
|
-
import { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE, getLanguageByCode, getDeviceLocale } from '../config/languages';
|
|
10
|
-
export const useLocalizationStore = create((set, get) => ({
|
|
11
|
-
currentLanguage: DEFAULT_LANGUAGE,
|
|
12
|
-
isRTL: false,
|
|
13
|
-
isInitialized: false,
|
|
14
|
-
supportedLanguages: SUPPORTED_LANGUAGES,
|
|
15
|
-
/**
|
|
16
|
-
* Initialize localization
|
|
17
|
-
* DEVICE LOCALE DETECTION:
|
|
18
|
-
* - First launch (no saved language): Automatically detect device locale
|
|
19
|
-
* - After manual selection: Use saved language preference
|
|
20
|
-
* - Fallback: English (en-US) if device locale not supported
|
|
21
|
-
*/
|
|
22
|
-
initialize: async () => {
|
|
23
|
-
/* eslint-disable-next-line no-console */
|
|
24
|
-
if (__DEV__)
|
|
25
|
-
console.log('[LocalizationStore] Starting initialization...');
|
|
26
|
-
try {
|
|
27
|
-
// ✅ CRITICAL FIX: Don't reset isInitialized if already initialized
|
|
28
|
-
// This prevents UI flash on re-initialization
|
|
29
|
-
const { isInitialized: alreadyInitialized } = get();
|
|
30
|
-
if (alreadyInitialized) {
|
|
31
|
-
/* eslint-disable-next-line no-console */
|
|
32
|
-
if (__DEV__)
|
|
33
|
-
console.log('[LocalizationStore] Already initialized, skipping...');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
/* eslint-disable-next-line no-console */
|
|
37
|
-
if (__DEV__)
|
|
38
|
-
console.log('[LocalizationStore] Getting saved language preference...');
|
|
39
|
-
// Get saved language preference
|
|
40
|
-
const savedLanguage = await StorageWrapper.getString(STORAGE_KEYS.LANGUAGE, DEFAULT_LANGUAGE);
|
|
41
|
-
/* eslint-disable-next-line no-console */
|
|
42
|
-
if (__DEV__)
|
|
43
|
-
console.log('[LocalizationStore] Saved language:', savedLanguage);
|
|
44
|
-
// ✅ DEVICE LOCALE DETECTION: Use device locale on first launch
|
|
45
|
-
let languageCode;
|
|
46
|
-
if (savedLanguage && savedLanguage !== DEFAULT_LANGUAGE) {
|
|
47
|
-
// User has previously selected a language → Use their choice
|
|
48
|
-
/* eslint-disable-next-line no-console */
|
|
49
|
-
if (__DEV__)
|
|
50
|
-
console.log('[LocalizationStore] Using saved language preference:', savedLanguage);
|
|
51
|
-
languageCode = savedLanguage;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
// First launch → Detect device locale automatically
|
|
55
|
-
/* eslint-disable-next-line no-console */
|
|
56
|
-
if (__DEV__)
|
|
57
|
-
console.log('[LocalizationStore] First launch, detecting device locale...');
|
|
58
|
-
languageCode = getDeviceLocale();
|
|
59
|
-
/* eslint-disable-next-line no-console */
|
|
60
|
-
if (__DEV__)
|
|
61
|
-
console.log('[LocalizationStore] Detected device locale:', languageCode);
|
|
62
|
-
// Save detected locale for future launches
|
|
63
|
-
await StorageWrapper.setString(STORAGE_KEYS.LANGUAGE, languageCode);
|
|
64
|
-
/* eslint-disable-next-line no-console */
|
|
65
|
-
if (__DEV__)
|
|
66
|
-
console.log('[LocalizationStore] Saved detected locale to storage');
|
|
67
|
-
}
|
|
68
|
-
// ✅ DEFENSIVE: Validate language exists, fallback to default
|
|
69
|
-
/* eslint-disable-next-line no-console */
|
|
70
|
-
if (__DEV__)
|
|
71
|
-
console.log('[LocalizationStore] Validating language code:', languageCode);
|
|
72
|
-
const language = getLanguageByCode(languageCode);
|
|
73
|
-
const finalLanguage = language ? languageCode : DEFAULT_LANGUAGE;
|
|
74
|
-
const finalLanguageObj = getLanguageByCode(finalLanguage);
|
|
75
|
-
if (!language) {
|
|
76
|
-
/* eslint-disable-next-line no-console */
|
|
77
|
-
console.warn('[LocalizationStore] ⚠️ Language not found:', languageCode, 'falling back to:', DEFAULT_LANGUAGE);
|
|
78
|
-
}
|
|
79
|
-
/* eslint-disable-next-line no-console */
|
|
80
|
-
if (__DEV__)
|
|
81
|
-
console.log('[LocalizationStore] Changing i18n language to:', finalLanguage);
|
|
82
|
-
await i18n.changeLanguage(finalLanguage);
|
|
83
|
-
/* eslint-disable-next-line no-console */
|
|
84
|
-
if (__DEV__)
|
|
85
|
-
console.log('[LocalizationStore] Setting store state...');
|
|
86
|
-
set({
|
|
87
|
-
currentLanguage: finalLanguage,
|
|
88
|
-
isRTL: finalLanguageObj?.rtl || false,
|
|
89
|
-
isInitialized: true, // ✅ Always set true to unblock UI
|
|
90
|
-
});
|
|
91
|
-
/* eslint-disable-next-line no-console */
|
|
92
|
-
if (__DEV__)
|
|
93
|
-
console.log('[LocalizationStore] ✅ Initialization complete. Language:', finalLanguage, 'RTL:', finalLanguageObj?.rtl || false);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
/* eslint-disable-next-line no-console */
|
|
97
|
-
console.error('[LocalizationStore] ❌ FATAL: Initialization failed:', error);
|
|
98
|
-
/* eslint-disable-next-line no-console */
|
|
99
|
-
if (error instanceof Error) {
|
|
100
|
-
/* eslint-disable-next-line no-console */
|
|
101
|
-
console.error('[LocalizationStore] Error name:', error.name);
|
|
102
|
-
/* eslint-disable-next-line no-console */
|
|
103
|
-
console.error('[LocalizationStore] Error message:', error.message);
|
|
104
|
-
/* eslint-disable-next-line no-console */
|
|
105
|
-
console.error('[LocalizationStore] Error stack:', error.stack);
|
|
106
|
-
}
|
|
107
|
-
// Set to default language even on error to prevent app from breaking
|
|
108
|
-
try {
|
|
109
|
-
await i18n.changeLanguage(DEFAULT_LANGUAGE);
|
|
110
|
-
set({
|
|
111
|
-
currentLanguage: DEFAULT_LANGUAGE,
|
|
112
|
-
isRTL: false,
|
|
113
|
-
isInitialized: true, // Set true even on error to unblock UI
|
|
114
|
-
});
|
|
115
|
-
/* eslint-disable-next-line no-console */
|
|
116
|
-
console.warn('[LocalizationStore] ⚠️ Fallback to default language due to error');
|
|
117
|
-
}
|
|
118
|
-
catch (fallbackError) {
|
|
119
|
-
/* eslint-disable-next-line no-console */
|
|
120
|
-
console.error('[LocalizationStore] ❌ CRITICAL: Even fallback failed:', fallbackError);
|
|
121
|
-
throw fallbackError;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
/**
|
|
126
|
-
* Change language
|
|
127
|
-
* Updates i18n, state, and persists to AsyncStorage
|
|
128
|
-
*/
|
|
129
|
-
setLanguage: async (languageCode) => {
|
|
130
|
-
/* eslint-disable-next-line no-console */
|
|
131
|
-
if (__DEV__)
|
|
132
|
-
console.log('[LocalizationStore] Changing language to:', languageCode);
|
|
133
|
-
try {
|
|
134
|
-
const language = getLanguageByCode(languageCode);
|
|
135
|
-
// ✅ DEFENSIVE: Early return if unsupported language
|
|
136
|
-
if (!language) {
|
|
137
|
-
/* eslint-disable-next-line no-console */
|
|
138
|
-
console.warn('[LocalizationStore] ⚠️ Unsupported language code:', languageCode);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
/* eslint-disable-next-line no-console */
|
|
142
|
-
if (__DEV__)
|
|
143
|
-
console.log('[LocalizationStore] Updating i18n language...');
|
|
144
|
-
// Update i18n
|
|
145
|
-
await i18n.changeLanguage(languageCode);
|
|
146
|
-
/* eslint-disable-next-line no-console */
|
|
147
|
-
if (__DEV__)
|
|
148
|
-
console.log('[LocalizationStore] Updating store state...');
|
|
149
|
-
// Update state
|
|
150
|
-
set({
|
|
151
|
-
currentLanguage: languageCode,
|
|
152
|
-
isRTL: language.rtl || false,
|
|
153
|
-
});
|
|
154
|
-
/* eslint-disable-next-line no-console */
|
|
155
|
-
if (__DEV__)
|
|
156
|
-
console.log('[LocalizationStore] Persisting language preference...');
|
|
157
|
-
// Persist language preference
|
|
158
|
-
await StorageWrapper.setString(STORAGE_KEYS.LANGUAGE, languageCode);
|
|
159
|
-
/* eslint-disable-next-line no-console */
|
|
160
|
-
if (__DEV__)
|
|
161
|
-
console.log('[LocalizationStore] ✅ Language changed successfully to:', languageCode);
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
/* eslint-disable-next-line no-console */
|
|
165
|
-
console.error('[LocalizationStore] ❌ Error changing language:', error);
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
}));
|
|
170
|
-
/**
|
|
171
|
-
* Hook to use localization
|
|
172
|
-
* Provides current language, RTL state, language switching, and translation function
|
|
173
|
-
* Uses react-i18next's useTranslation hook to ensure proper i18n instance
|
|
174
|
-
*/
|
|
175
|
-
export const useLocalization = () => {
|
|
176
|
-
const { currentLanguage, isRTL, isInitialized, supportedLanguages, setLanguage, initialize, } = useLocalizationStore();
|
|
177
|
-
const currentLanguageObject = getLanguageByCode(currentLanguage);
|
|
178
|
-
// Use react-i18next's useTranslation hook to ensure proper i18n instance
|
|
179
|
-
// This ensures that react-i18next knows about the i18n instance
|
|
180
|
-
const { t } = useTranslation();
|
|
181
|
-
return {
|
|
182
|
-
t, // Translation function from react-i18next
|
|
183
|
-
currentLanguage,
|
|
184
|
-
currentLanguageObject,
|
|
185
|
-
isRTL,
|
|
186
|
-
isInitialized,
|
|
187
|
-
supportedLanguages,
|
|
188
|
-
setLanguage,
|
|
189
|
-
initialize,
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
//# sourceMappingURL=LocalizationStore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationStore.js","sourceRoot":"","sources":["../../../src/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