@umituz/react-native-localization 1.6.1 → 1.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
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",
@@ -131,28 +131,25 @@ export const useLocalization = () => {
131
131
 
132
132
  const currentLanguageObject = getLanguageByCode(currentLanguage);
133
133
 
134
+ // Always call useTranslation hook (React hooks rules - must be unconditional)
135
+ // If i18n is not ready, useTranslation will throw, but we handle it gracefully
136
+ const translationResult = useTranslation();
137
+
134
138
  // Check if i18n is initialized and react-i18next is ready
135
139
  // If not, use direct i18n.t as fallback
136
140
  const isI18nReady = i18n.isInitialized && typeof i18n.t === 'function';
137
141
 
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
142
  // 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
- });
143
+ // This handles the case where react-i18next is not yet initialized
144
+ const t: (key: string, options?: any) => string = (translationResult?.t && typeof translationResult.t === 'function')
145
+ ? translationResult.t
146
+ : ((key: string, options?: any) => {
147
+ if (isI18nReady) {
148
+ return i18n.t(key, options);
149
+ }
150
+ // Final fallback: return key if i18n is not ready
151
+ return key;
152
+ });
156
153
 
157
154
  return {
158
155
  t, // Translation function from react-i18next or i18n fallback