@umituz/react-native-localization 1.6.2 → 1.6.4
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
|
@@ -266,16 +266,9 @@ const initializeI18n = () => {
|
|
|
266
266
|
}
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
-
//
|
|
270
|
-
// React Native
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
setTimeout(() => {
|
|
274
|
-
initializeI18n();
|
|
275
|
-
}, 0);
|
|
276
|
-
} else {
|
|
277
|
-
// Fallback: initialize immediately
|
|
278
|
-
initializeI18n();
|
|
279
|
-
}
|
|
269
|
+
// Initialize immediately - no need to defer
|
|
270
|
+
// React Native and React are ready when this module loads
|
|
271
|
+
// Deferring causes race conditions with useTranslation hook
|
|
272
|
+
initializeI18n();
|
|
280
273
|
|
|
281
274
|
export default i18n;
|
|
@@ -132,24 +132,19 @@ export const useLocalization = () => {
|
|
|
132
132
|
const currentLanguageObject = getLanguageByCode(currentLanguage);
|
|
133
133
|
|
|
134
134
|
// Always call useTranslation hook (React hooks rules - must be unconditional)
|
|
135
|
-
//
|
|
136
|
-
|
|
135
|
+
// Pass i18n instance explicitly to ensure react-i18next finds it
|
|
136
|
+
// This fixes the "NO_I18NEXT_INSTANCE" error
|
|
137
|
+
const translationResult = useTranslation(undefined, { i18n });
|
|
137
138
|
|
|
138
|
-
//
|
|
139
|
-
// If
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (isI18nReady) {
|
|
148
|
-
return i18n.t(key, options);
|
|
149
|
-
}
|
|
150
|
-
// Final fallback: return key if i18n is not ready
|
|
151
|
-
return key;
|
|
152
|
-
});
|
|
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
|
+
});
|
|
153
148
|
|
|
154
149
|
return {
|
|
155
150
|
t, // Translation function from react-i18next or i18n fallback
|