@umituz/react-native-localization 1.6.5 → 1.7.0

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.5",
3
+ "version": "1.7.0",
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",
@@ -197,27 +197,36 @@ const buildResources = (): Record<string, { translation: any }> => {
197
197
 
198
198
  const resources = buildResources();
199
199
 
200
- // Debug: Log loaded resources in development
201
- /* eslint-disable-next-line no-console */
202
- if (typeof __DEV__ !== 'undefined' && __DEV__) {
203
- console.log('🌍 i18n Resources loaded:', {
204
- languages: Object.keys(resources),
205
- enUSKeys: resources['en-US']?.translation ? Object.keys(resources['en-US'].translation) : [],
206
- hasGoals: !!resources['en-US']?.translation?.goals,
207
- navigationKeys: resources['en-US']?.translation?.navigation ? Object.keys(resources['en-US'].translation.navigation) : [],
208
- hasMilestones: !!resources['en-US']?.translation?.navigation?.milestones,
209
- hasStatistics: !!resources['en-US']?.translation?.navigation?.statistics,
210
- });
200
+ // Debug: Log loaded resources in development (only once to prevent spam)
201
+ // Use global flag to prevent multiple logs when module is imported multiple times
202
+ if (typeof global !== 'undefined' && !(global as any).__i18n_resources_logged) {
203
+ /* eslint-disable-next-line no-console */
204
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
205
+ console.log('🌍 i18n Resources loaded:', {
206
+ languages: Object.keys(resources),
207
+ enUSKeys: resources['en-US']?.translation ? Object.keys(resources['en-US'].translation) : [],
208
+ hasGoals: !!resources['en-US']?.translation?.goals,
209
+ navigationKeys: resources['en-US']?.translation?.navigation ? Object.keys(resources['en-US'].translation.navigation) : [],
210
+ hasMilestones: !!resources['en-US']?.translation?.navigation?.milestones,
211
+ hasStatistics: !!resources['en-US']?.translation?.navigation?.statistics,
212
+ });
213
+ (global as any).__i18n_resources_logged = true;
214
+ }
211
215
  }
212
216
 
217
+ // Global flag to ensure initReactI18next is only used once
218
+ let reactI18nextInitialized = false;
219
+
213
220
  /**
214
221
  * Initialize i18next
215
- * Deferred initialization to avoid React Native renderer conflicts
222
+ * CRITICAL: Check i18n.isInitialized to prevent multiple initializations
223
+ * This prevents "i18next is already initialized" warnings when module is imported multiple times
216
224
  */
217
- let isInitialized = false;
218
-
219
225
  const initializeI18n = () => {
220
- if (isInitialized) return;
226
+ // CRITICAL: Check if i18n is already initialized (prevents multiple init calls)
227
+ if (i18n.isInitialized) {
228
+ return;
229
+ }
221
230
 
222
231
  try {
223
232
  // Check if initReactI18next is available
@@ -225,7 +234,13 @@ const initializeI18n = () => {
225
234
  throw new Error('initReactI18next is undefined');
226
235
  }
227
236
 
228
- i18n.use(initReactI18next).init({
237
+ // CRITICAL: Only use initReactI18next once (prevents context registration issues)
238
+ if (!reactI18nextInitialized) {
239
+ i18n.use(initReactI18next);
240
+ reactI18nextInitialized = true;
241
+ }
242
+
243
+ i18n.init({
229
244
  resources,
230
245
  lng: DEFAULT_LANGUAGE,
231
246
  fallbackLng: DEFAULT_LANGUAGE,
@@ -246,8 +261,6 @@ const initializeI18n = () => {
246
261
  debug: typeof __DEV__ !== 'undefined' && __DEV__,
247
262
  });
248
263
 
249
- isInitialized = true;
250
-
251
264
  // Debug: Verify initialization
252
265
  /* eslint-disable-next-line no-console */
253
266
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
@@ -269,6 +282,7 @@ const initializeI18n = () => {
269
282
  // Initialize immediately - no need to defer
270
283
  // React Native and React are ready when this module loads
271
284
  // Deferring causes race conditions with useTranslation hook
285
+ // CRITICAL: i18n.isInitialized check prevents multiple initializations
272
286
  initializeI18n();
273
287
 
274
288
  export default i18n;