@umituz/react-native-localization 3.1.2 → 3.2.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": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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",
|
|
@@ -86,4 +86,4 @@
|
|
|
86
86
|
"README.md",
|
|
87
87
|
"LICENSE"
|
|
88
88
|
]
|
|
89
|
-
}
|
|
89
|
+
}
|
|
@@ -18,9 +18,27 @@ export class NamespaceResolver {
|
|
|
18
18
|
const packageTranslations = TranslationLoader.loadPackageTranslations();
|
|
19
19
|
const packageLang = packageTranslations[languageCode] || {};
|
|
20
20
|
|
|
21
|
+
let appNamespaces: string[] = [];
|
|
22
|
+
|
|
23
|
+
// Check if appTranslations has language keys (format: xx-XX)
|
|
24
|
+
const hasLanguageKeys = Object.keys(appTranslations).some(key =>
|
|
25
|
+
/^[a-z]{2}-[A-Z]{2}$/.test(key)
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (hasLanguageKeys) {
|
|
29
|
+
// If structured by language, get namespaces from the requested language
|
|
30
|
+
const langTranslations = appTranslations[languageCode];
|
|
31
|
+
if (langTranslations && typeof langTranslations === 'object') {
|
|
32
|
+
appNamespaces = Object.keys(langTranslations);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
// If structured by namespace (legacy/simple), keys are namespaces
|
|
36
|
+
appNamespaces = Object.keys(appTranslations);
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
const namespaces = new Set([
|
|
22
40
|
...Object.keys(packageLang),
|
|
23
|
-
...
|
|
41
|
+
...appNamespaces,
|
|
24
42
|
]);
|
|
25
43
|
|
|
26
44
|
if (!namespaces.has(DEFAULT_NAMESPACE)) {
|
|
@@ -15,26 +15,43 @@ export class ResourceBuilder {
|
|
|
15
15
|
): Record<string, Record<string, any>> {
|
|
16
16
|
const packageTranslations = TranslationLoader.loadPackageTranslations();
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
18
|
+
// Initialize with package translations
|
|
19
|
+
const resources: Record<string, Record<string, any>> = { ...packageTranslations };
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (const [namespace, translations] of Object.entries(packageLang)) {
|
|
26
|
-
resources[languageCode][namespace] = translations;
|
|
21
|
+
// Ensure initial language exists
|
|
22
|
+
if (!resources[languageCode]) {
|
|
23
|
+
resources[languageCode] = {};
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
//
|
|
30
|
-
for (const [
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
26
|
+
// Process app translations
|
|
27
|
+
for (const [key, value] of Object.entries(appTranslations)) {
|
|
28
|
+
// Check if the key is a language code (format: xx-XX)
|
|
29
|
+
const isLanguageKey = /^[a-z]{2}-[A-Z]{2}$/.test(key);
|
|
30
|
+
|
|
31
|
+
if (isLanguageKey) {
|
|
32
|
+
// It's a language key (e.g., "en-US")
|
|
33
|
+
const lang = key;
|
|
34
|
+
if (!resources[lang]) {
|
|
35
|
+
resources[lang] = {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Merge namespaces for this language
|
|
39
|
+
if (value && typeof value === 'object') {
|
|
40
|
+
for (const [namespace, translations] of Object.entries(value)) {
|
|
41
|
+
resources[lang][namespace] = TranslationLoader.mergeTranslations(
|
|
42
|
+
resources[lang][namespace] || {},
|
|
43
|
+
translations
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
} else {
|
|
37
|
-
|
|
48
|
+
// It's a namespace for the default/current language (backward compatibility)
|
|
49
|
+
if (value && typeof value === 'object') {
|
|
50
|
+
resources[languageCode][key] = TranslationLoader.mergeTranslations(
|
|
51
|
+
resources[languageCode][key] || {},
|
|
52
|
+
value
|
|
53
|
+
);
|
|
54
|
+
}
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
|