@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
|
@@ -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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
if (hasNamespace) {
|
|
63
|
+
const namespacedKey = `${potentialNamespace}:${restOfKey}`;
|
|
64
|
+
const namespacedResult = i18nextT(namespacedKey, options);
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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 {
|