@umituz/react-native-localization 3.5.9 → 3.5.10

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": "3.5.9",
3
+ "version": "3.5.10",
4
4
  "description": "Generic localization system for React Native apps with i18n support",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -35,35 +35,71 @@ export const useTranslationFunction = () => {
35
35
  : defaultValueOrOptions || {};
36
36
 
37
37
  if (!ready || !i18n.isInitialized) {
38
+ if (__DEV__) {
39
+ console.log(`[i18n] ⏳ Not ready - Key: "${key}" → Fallback: "${options.defaultValue || key}"`);
40
+ }
38
41
  return options.defaultValue || key;
39
42
  }
40
43
 
44
+ let finalResult: string;
45
+ let translationFound = false;
46
+ let usedKey = key;
47
+
41
48
  // If key already has namespace separator (:), use as-is
42
49
  if (key.includes(':')) {
43
50
  const result = i18nextT(key, options);
44
- return typeof result === 'string' ? result : key;
45
- }
46
-
47
- // Auto-detect namespace from first dot segment
48
- const firstDotIndex = key.indexOf('.');
49
- if (firstDotIndex > 0) {
50
- const potentialNamespace = key.substring(0, firstDotIndex);
51
- const restOfKey = key.substring(firstDotIndex + 1);
52
- const hasNamespace = i18n.hasResourceBundle(i18n.language, potentialNamespace);
51
+ finalResult = typeof result === 'string' ? result : key;
52
+ translationFound = finalResult !== key && finalResult !== options.defaultValue;
53
+ usedKey = key;
54
+ } else {
55
+ // Auto-detect namespace from first dot segment
56
+ const firstDotIndex = key.indexOf('.');
57
+ if (firstDotIndex > 0) {
58
+ const potentialNamespace = key.substring(0, firstDotIndex);
59
+ const restOfKey = key.substring(firstDotIndex + 1);
60
+ const hasNamespace = i18n.hasResourceBundle(i18n.language, potentialNamespace);
53
61
 
54
- if (hasNamespace) {
55
- const namespacedKey = `${potentialNamespace}:${restOfKey}`;
56
- const namespacedResult = i18nextT(namespacedKey, options);
62
+ if (hasNamespace) {
63
+ const namespacedKey = `${potentialNamespace}:${restOfKey}`;
64
+ const namespacedResult = i18nextT(namespacedKey, options);
57
65
 
58
- if (namespacedResult !== namespacedKey && namespacedResult !== restOfKey) {
59
- return typeof namespacedResult === 'string' ? namespacedResult : key;
66
+ if (namespacedResult !== namespacedKey && namespacedResult !== restOfKey) {
67
+ finalResult = typeof namespacedResult === 'string' ? namespacedResult : key;
68
+ translationFound = true;
69
+ usedKey = namespacedKey;
70
+ } else {
71
+ // Fallback to original key
72
+ const result = i18nextT(key, options);
73
+ finalResult = typeof result === 'string' ? result : key;
74
+ translationFound = finalResult !== key && finalResult !== options.defaultValue;
75
+ usedKey = key;
76
+ }
77
+ } else {
78
+ // Fallback to original key
79
+ const result = i18nextT(key, options);
80
+ finalResult = typeof result === 'string' ? result : key;
81
+ translationFound = finalResult !== key && finalResult !== options.defaultValue;
82
+ usedKey = key;
60
83
  }
84
+ } else {
85
+ // Fallback to original key
86
+ const result = i18nextT(key, options);
87
+ finalResult = typeof result === 'string' ? result : key;
88
+ translationFound = finalResult !== key && finalResult !== options.defaultValue;
89
+ usedKey = key;
90
+ }
91
+ }
92
+
93
+ // Development mode logging
94
+ if (__DEV__) {
95
+ if (translationFound) {
96
+ console.log(`[i18n] ✅ Found - Key: "${usedKey}" → "${finalResult}"`);
97
+ } else {
98
+ console.warn(`[i18n] ⚠️ Missing - Key: "${usedKey}" → Fallback: "${finalResult}"`);
61
99
  }
62
100
  }
63
101
 
64
- // Fallback to original key
65
- const result = i18nextT(key, options);
66
- return typeof result === 'string' ? result : key;
102
+ return finalResult;
67
103
  }, [i18nextT, ready]);
68
104
 
69
105
  return {