@umituz/react-native-localization 1.7.2 → 1.7.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
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",
@@ -67,15 +67,62 @@ const LANGUAGE_MAP = {
67
67
  'zh-TW': 'zh-TW', // Chinese Traditional
68
68
  };
69
69
 
70
- // Only skip actual brand names - everything else should be translated
71
- // Note: Even common words like "Email", "OK", "Premium" should be localized
70
+ // Skip brand names and common words that are the same in most languages
71
+ // These words don't need translation and should be preserved as-is
72
72
  const SKIP_WORDS = new Set([
73
+ // Brand names
73
74
  'Google',
74
75
  'Apple',
75
76
  'Facebook',
76
77
  'Instagram',
77
78
  'Twitter',
78
79
  'WhatsApp',
80
+
81
+ // Common UI words that are often the same
82
+ 'OK',
83
+ 'Yes',
84
+ 'No',
85
+ 'Cancel',
86
+ 'Save',
87
+ 'Delete',
88
+ 'Edit',
89
+ 'Back',
90
+ 'Next',
91
+ 'Previous',
92
+ 'Close',
93
+ 'Open',
94
+ 'Menu',
95
+ 'Settings',
96
+ 'Help',
97
+ 'Info',
98
+ 'Error',
99
+ 'Warning',
100
+ 'Success',
101
+ 'Loading',
102
+ 'Search',
103
+ 'Filter',
104
+ 'Sort',
105
+ 'View',
106
+ 'Show',
107
+ 'Hide',
108
+
109
+ // Technical terms
110
+ 'API',
111
+ 'URL',
112
+ 'HTTP',
113
+ 'HTTPS',
114
+ 'JSON',
115
+ 'XML',
116
+ 'PDF',
117
+ 'CSV',
118
+ 'ID',
119
+
120
+ // Common abbreviations
121
+ 'etc.',
122
+ 'e.g.',
123
+ 'i.e.',
124
+ 'vs.',
125
+ 'etc',
79
126
  ]);
80
127
 
81
128
  /**
@@ -169,10 +216,10 @@ async function translateText(text, targetLang, retryCount = 0) {
169
216
  translateText(text, targetLang, retryCount + 1).then(resolve);
170
217
  }, RETRY_DELAY * (retryCount + 1));
171
218
  } else {
172
- console.warn(
219
+ console.warn(
173
220
  `⚠️ Translation failed for "${text}" to ${targetLang}: ${error.message}`
174
- );
175
- resolve(text); // Fallback to original
221
+ );
222
+ resolve(text); // Fallback to original
176
223
  }
177
224
  }
178
225
  });
@@ -188,10 +235,10 @@ async function translateText(text, targetLang, retryCount = 0) {
188
235
  translateText(text, targetLang, retryCount + 1).then(resolve);
189
236
  }, RETRY_DELAY * (retryCount + 1));
190
237
  } else {
191
- console.warn(
238
+ console.warn(
192
239
  `⚠️ Network error translating "${text}" to ${targetLang}: ${err.message}`
193
- );
194
- resolve(text); // Fallback to original
240
+ );
241
+ resolve(text); // Fallback to original
195
242
  }
196
243
  });
197
244
  });
@@ -284,7 +331,7 @@ function needsTranslation(key, value, enValue) {
284
331
  }
285
332
 
286
333
  // Skip if already translated (value is different from English)
287
- // This protects manual translations!
334
+ // This protects manual translations and prevents re-translation of auto-translated strings!
288
335
  if (value !== enValue) {
289
336
  if (options.verbose) {
290
337
  console.log(` ⏭️ Skipping "${key}": already translated (manual or previous auto)`);
@@ -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-13T02:01:18.323Z
23
+ * Generated: 2025-11-14T22:27:21.619Z
24
24
  */
25
25
 
26
26
  // Metro bundler require.context - auto-discover all .json files
@@ -140,16 +140,21 @@ export const useLocalization = () => {
140
140
 
141
141
  // Use translation function from react-i18next if available and valid
142
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) => {
143
+ // Type assertion needed because react-i18next's TFunction can return string | object
144
+ const t = (translationResult?.t && typeof translationResult.t === 'function' && i18n.isInitialized)
145
+ ? ((key: string, options?: any): string => {
146
+ const result = translationResult.t(key, options);
147
+ return typeof result === 'string' ? result : String(result);
148
+ })
149
+ : ((key: string, options?: any): string => {
146
150
  // Fallback to direct i18n.t if react-i18next is not ready
147
151
  if (i18n.isInitialized && typeof i18n.t === 'function') {
148
- return i18n.t(key, options);
152
+ const result = i18n.t(key, options);
153
+ return typeof result === 'string' ? result : String(result);
149
154
  }
150
155
  // Final fallback: return key if i18n is not ready
151
156
  return key;
152
- });
157
+ }) as (key: string, options?: any) => string;
153
158
 
154
159
  return {
155
160
  t, // Translation function from react-i18next or i18n fallback