@umituz/react-native-localization 1.10.0 → 1.11.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
|
@@ -31,42 +31,30 @@ const packageTranslations = loadPackageTranslations();
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Load project translations for all supported languages
|
|
34
|
-
*
|
|
34
|
+
* Simple approach: try to load nutrition translations directly
|
|
35
35
|
*/
|
|
36
36
|
const loadProjectTranslations = (): Record<string, any> => {
|
|
37
37
|
const translations: Record<string, any> = {};
|
|
38
38
|
|
|
39
|
-
// Try to load translations
|
|
40
|
-
// This allows dynamic loading without hardcoded paths
|
|
39
|
+
// Try to load nutrition translations from nutrition tracker app
|
|
41
40
|
try {
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'en-US', 'ar-SA', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR',
|
|
48
|
-
'en-AU', 'en-CA', 'en-GB', 'es-ES', 'es-MX', 'fi-FI', 'fr-CA',
|
|
49
|
-
'fr-FR', 'hi-IN', 'hr-HR', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP',
|
|
50
|
-
'ko-KR', 'ms-MY', 'nl-NL', 'no-NO', 'pl-PL', 'pt-BR', 'pt-PT',
|
|
51
|
-
'ro-RO', 'ru-RU', 'sk-SK', 'sv-SE', 'th-TH', 'tl-PH', 'tr-TR',
|
|
52
|
-
'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW'
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
for (const langCode of supportedLanguages) {
|
|
56
|
-
try {
|
|
57
|
-
// Attempt to load language module dynamically
|
|
58
|
-
// This will work if the project has set up locales properly
|
|
59
|
-
const langModule = require(`../../../../../../src/locales/${langCode}`);
|
|
60
|
-
if (langModule?.default || langModule) {
|
|
61
|
-
translations[langCode] = langModule.default || langModule;
|
|
62
|
-
}
|
|
63
|
-
} catch {
|
|
64
|
-
// Language not available - skip silently
|
|
65
|
-
}
|
|
41
|
+
// Direct require for nutrition translations
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
43
|
+
const nutritionTranslations = require('../../../../../../src/locales/en-US');
|
|
44
|
+
if (nutritionTranslations?.default || nutritionTranslations) {
|
|
45
|
+
translations['en-US'] = nutritionTranslations.default || nutritionTranslations;
|
|
66
46
|
}
|
|
67
47
|
} catch (error) {
|
|
68
|
-
//
|
|
69
|
-
|
|
48
|
+
// If nutrition translations not found, try to load them directly
|
|
49
|
+
try {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
51
|
+
const nutritionJson = require('../../../../../../src/locales/en-US/nutrition.json');
|
|
52
|
+
if (nutritionJson) {
|
|
53
|
+
translations['en-US'] = { nutrition: nutritionJson };
|
|
54
|
+
}
|
|
55
|
+
} catch (fallbackError) {
|
|
56
|
+
// Silent fallback - no nutrition translations available
|
|
57
|
+
}
|
|
70
58
|
}
|
|
71
59
|
|
|
72
60
|
return translations;
|
|
@@ -114,18 +102,34 @@ const mergeTranslations = (packageTranslations: any, projectTranslations: any):
|
|
|
114
102
|
*/
|
|
115
103
|
const buildResources = (): Record<string, { translation: any }> => {
|
|
116
104
|
const resources: Record<string, { translation: any }> = {};
|
|
117
|
-
|
|
105
|
+
|
|
106
|
+
// Try to load nutrition translations directly for en-US
|
|
107
|
+
let nutritionTranslations: any = {};
|
|
108
|
+
try {
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
110
|
+
const nutritionJson = require('../../../../../../src/locales/en-US/nutrition.json');
|
|
111
|
+
if (nutritionJson) {
|
|
112
|
+
nutritionTranslations = { nutrition: nutritionJson };
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Silent fallback - no nutrition translations
|
|
116
|
+
}
|
|
117
|
+
|
|
118
118
|
// Build resources for each supported language
|
|
119
119
|
for (const lang of SUPPORTED_LANGUAGES) {
|
|
120
120
|
const langCode = lang.code;
|
|
121
121
|
const packageTranslation = langCode === 'en-US' ? (packageTranslations['en-US'] || {}) : {};
|
|
122
122
|
const projectTranslation = projectTranslations[langCode] || {};
|
|
123
|
-
|
|
124
|
-
// For en-US, merge package and
|
|
123
|
+
|
|
124
|
+
// For en-US, merge package, project, and nutrition translations
|
|
125
125
|
// For other languages, use project translations only (fallback to en-US handled by i18n)
|
|
126
126
|
if (langCode === 'en-US') {
|
|
127
|
+
const mergedTranslation = mergeTranslations(
|
|
128
|
+
mergeTranslations(packageTranslation, projectTranslation),
|
|
129
|
+
nutritionTranslations
|
|
130
|
+
);
|
|
127
131
|
resources[langCode] = {
|
|
128
|
-
translation:
|
|
132
|
+
translation: mergedTranslation,
|
|
129
133
|
};
|
|
130
134
|
} else if (projectTranslation && Object.keys(projectTranslation).length > 0) {
|
|
131
135
|
resources[langCode] = {
|
|
@@ -133,14 +137,15 @@ const buildResources = (): Record<string, { translation: any }> => {
|
|
|
133
137
|
};
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
|
-
|
|
140
|
+
|
|
137
141
|
// Ensure en-US is always present
|
|
138
142
|
if (!resources['en-US']) {
|
|
143
|
+
const baseTranslation = packageTranslations['en-US'] || {};
|
|
139
144
|
resources['en-US'] = {
|
|
140
|
-
translation:
|
|
145
|
+
translation: mergeTranslations(baseTranslation, nutritionTranslations),
|
|
141
146
|
};
|
|
142
147
|
}
|
|
143
|
-
|
|
148
|
+
|
|
144
149
|
return resources;
|
|
145
150
|
};
|
|
146
151
|
|