@umituz/react-native-localization 1.6.0 → 1.6.1

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": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Universal localization system for React Native apps with i18n support",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -20,7 +20,7 @@
20
20
  * This file is automatically generated by setup-languages.js or createLocaleLoaders.js
21
21
  * but can be manually edited if needed.
22
22
  *
23
- * Generated: 2025-11-13T00:36:17.340Z
23
+ * Generated: 2025-11-13T00:52:59.500Z
24
24
  */
25
25
 
26
26
  // Metro bundler require.context - auto-discover all .json files
@@ -117,6 +117,7 @@ export const useLocalizationStore = create<LocalizationState>((set, get) => ({
117
117
  * Hook to use localization
118
118
  * Provides current language, RTL state, language switching, and translation function
119
119
  * Uses react-i18next's useTranslation hook to ensure proper i18n instance
120
+ * Falls back to direct i18n.t if react-i18next is not ready
120
121
  */
121
122
  export const useLocalization = () => {
122
123
  const {
@@ -130,12 +131,31 @@ export const useLocalization = () => {
130
131
 
131
132
  const currentLanguageObject = getLanguageByCode(currentLanguage);
132
133
 
133
- // Use react-i18next's useTranslation hook to ensure proper i18n instance
134
- // This ensures that react-i18next knows about the i18n instance
135
- const { t } = useTranslation();
134
+ // Check if i18n is initialized and react-i18next is ready
135
+ // If not, use direct i18n.t as fallback
136
+ const isI18nReady = i18n.isInitialized && typeof i18n.t === 'function';
137
+
138
+ // Always call useTranslation hook (React hooks rules)
139
+ // But use fallback if i18n is not ready
140
+ let translationResult;
141
+ try {
142
+ translationResult = useTranslation();
143
+ } catch (error) {
144
+ // If useTranslation fails, we'll use direct i18n.t
145
+ translationResult = null;
146
+ }
147
+
148
+ // Use translation function from react-i18next if available, otherwise use direct i18n.t
149
+ const t: (key: string, options?: any) => string = translationResult?.t || ((key: string, options?: any) => {
150
+ if (isI18nReady) {
151
+ return i18n.t(key, options);
152
+ }
153
+ // Final fallback: return key if i18n is not ready
154
+ return key;
155
+ });
136
156
 
137
157
  return {
138
- t, // Translation function from react-i18next
158
+ t, // Translation function from react-i18next or i18n fallback
139
159
  currentLanguage,
140
160
  currentLanguageObject,
141
161
  isRTL,