@umituz/react-native-localization 1.6.4 → 1.6.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": "1.6.4",
3
+ "version": "1.6.5",
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",
@@ -134,17 +134,22 @@ export const useLocalization = () => {
134
134
  // Always call useTranslation hook (React hooks rules - must be unconditional)
135
135
  // Pass i18n instance explicitly to ensure react-i18next finds it
136
136
  // This fixes the "NO_I18NEXT_INSTANCE" error
137
+ // Even if i18n is not fully initialized, useTranslation will handle it gracefully
138
+ // with the explicit i18n instance passed
137
139
  const translationResult = useTranslation(undefined, { i18n });
138
140
 
139
- // Use translation function from react-i18next
140
- // If it fails, fallback to direct i18n.t
141
- const t: (key: string, options?: any) => string = translationResult?.t || ((key: string, options?: any) => {
142
- if (i18n.isInitialized && typeof i18n.t === 'function') {
143
- return i18n.t(key, options);
144
- }
145
- // Final fallback: return key if i18n is not ready
146
- return key;
147
- });
141
+ // Use translation function from react-i18next if available and valid
142
+ // Otherwise fallback to direct i18n.t
143
+ const t: (key: string, options?: any) => string = (translationResult?.t && typeof translationResult.t === 'function' && i18n.isInitialized)
144
+ ? translationResult.t
145
+ : ((key: string, options?: any) => {
146
+ // Fallback to direct i18n.t if react-i18next is not ready
147
+ if (i18n.isInitialized && typeof i18n.t === 'function') {
148
+ return i18n.t(key, options);
149
+ }
150
+ // Final fallback: return key if i18n is not ready
151
+ return key;
152
+ });
148
153
 
149
154
  return {
150
155
  t, // Translation function from react-i18next or i18n fallback