@umituz/react-native-localization 3.5.7 → 3.5.8
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
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import * as Localization from 'expo-localization';
|
|
17
|
-
import {
|
|
17
|
+
import { languageRegistry } from './languagesData';
|
|
18
18
|
import type { Language } from '../storage/types/LocalizationState';
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
export const
|
|
20
|
+
// SUPPORTED_LANGUAGES and LANGUAGES are now dynamic getters to ensure they always reflect the registry
|
|
21
|
+
export const getSUPPORTED_LANGUAGES = () => languageRegistry.getLanguages();
|
|
22
|
+
export const getLANGUAGES = () => languageRegistry.getLanguages();
|
|
22
23
|
|
|
23
|
-
//
|
|
24
|
+
// For backward compatibility while keeping it dynamic
|
|
25
|
+
export const SUPPORTED_LANGUAGES: Language[] = languageRegistry.getLanguages();
|
|
24
26
|
export const LANGUAGES = SUPPORTED_LANGUAGES;
|
|
25
27
|
|
|
26
28
|
export const DEFAULT_LANGUAGE = 'en-US';
|
|
@@ -28,9 +30,6 @@ export const DEFAULT_LANGUAGE = 'en-US';
|
|
|
28
30
|
/**
|
|
29
31
|
* Locale mapping for device locales to supported app locales
|
|
30
32
|
* Maps short codes and regional variants to en-US
|
|
31
|
-
*
|
|
32
|
-
* SIMPLE MAPPING:
|
|
33
|
-
* - All variants map to en-US (only supported language)
|
|
34
33
|
*/
|
|
35
34
|
const LOCALE_MAPPING: Record<string, string> = {
|
|
36
35
|
// English variants map to en-US
|
|
@@ -46,37 +45,37 @@ const LOCALE_MAPPING: Record<string, string> = {
|
|
|
46
45
|
'en-IN': 'en-US',
|
|
47
46
|
|
|
48
47
|
// Portuguese mappings
|
|
49
|
-
'pt': 'pt-PT',
|
|
50
|
-
'pt-BR': 'pt-BR',
|
|
48
|
+
'pt': 'pt-PT',
|
|
49
|
+
'pt-BR': 'pt-BR',
|
|
51
50
|
'pt-PT': 'pt-PT',
|
|
52
51
|
|
|
53
52
|
// Spanish variants
|
|
54
53
|
'es': 'es-ES',
|
|
55
54
|
'es-ES': 'es-ES',
|
|
56
|
-
'es-MX': 'es-ES',
|
|
55
|
+
'es-MX': 'es-ES',
|
|
57
56
|
'es-AR': 'es-ES',
|
|
58
|
-
'es-US': 'es-ES',
|
|
57
|
+
'es-US': 'es-ES',
|
|
59
58
|
|
|
60
59
|
// French variants
|
|
61
60
|
'fr': 'fr-FR',
|
|
62
61
|
'fr-FR': 'fr-FR',
|
|
63
|
-
'fr-CA': 'fr-FR',
|
|
62
|
+
'fr-CA': 'fr-FR',
|
|
64
63
|
'fr-BE': 'fr-FR',
|
|
65
64
|
'fr-CH': 'fr-FR',
|
|
66
65
|
|
|
67
|
-
// Norwegian
|
|
66
|
+
// Norwegian
|
|
68
67
|
'no': 'no-NO',
|
|
69
68
|
'nb': 'no-NO',
|
|
70
|
-
'nn': 'no-NO',
|
|
69
|
+
'nn': 'no-NO',
|
|
71
70
|
|
|
72
71
|
// Chinese variants
|
|
73
72
|
'zh': 'zh-CN',
|
|
74
73
|
'zh-CN': 'zh-CN',
|
|
75
74
|
'zh-Hans': 'zh-CN',
|
|
76
75
|
'zh-Hans-CN': 'zh-CN',
|
|
77
|
-
'zh-Hant': 'zh-TW',
|
|
76
|
+
'zh-Hant': 'zh-TW',
|
|
78
77
|
'zh-TW': 'zh-TW',
|
|
79
|
-
'zh-HK': 'zh-TW',
|
|
78
|
+
'zh-HK': 'zh-TW',
|
|
80
79
|
|
|
81
80
|
// Others
|
|
82
81
|
'ar': 'ar-SA',
|
|
@@ -84,10 +83,10 @@ const LOCALE_MAPPING: Record<string, string> = {
|
|
|
84
83
|
'cs': 'cs-CZ',
|
|
85
84
|
'da': 'da-DK',
|
|
86
85
|
'de': 'de-DE',
|
|
87
|
-
'el': 'el-GR',
|
|
86
|
+
'el': 'el-GR',
|
|
88
87
|
'fi': 'fi-FI',
|
|
89
88
|
'hi': 'hi-IN',
|
|
90
|
-
'hr': 'hr-HR',
|
|
89
|
+
'hr': 'hr-HR',
|
|
91
90
|
'hu': 'hu-HU',
|
|
92
91
|
'id': 'id-ID',
|
|
93
92
|
'it': 'it-IT',
|
|
@@ -98,7 +97,7 @@ const LOCALE_MAPPING: Record<string, string> = {
|
|
|
98
97
|
'pl': 'pl-PL',
|
|
99
98
|
'ro': 'ro-RO',
|
|
100
99
|
'ru': 'ru-RU',
|
|
101
|
-
'sk': 'sk-SK',
|
|
100
|
+
'sk': 'sk-SK',
|
|
102
101
|
'sv': 'sv-SE',
|
|
103
102
|
'th': 'th-TH',
|
|
104
103
|
'tr': 'tr-TR',
|
|
@@ -107,11 +106,11 @@ const LOCALE_MAPPING: Record<string, string> = {
|
|
|
107
106
|
};
|
|
108
107
|
|
|
109
108
|
export const getLanguageByCode = (code: string): Language | undefined => {
|
|
110
|
-
return
|
|
109
|
+
return languageRegistry.getLanguageByCode(code);
|
|
111
110
|
};
|
|
112
111
|
|
|
113
112
|
export const isLanguageSupported = (code: string): boolean => {
|
|
114
|
-
return
|
|
113
|
+
return languageRegistry.isLanguageSupported(code);
|
|
115
114
|
};
|
|
116
115
|
|
|
117
116
|
export const getDefaultLanguage = (): Language => {
|
|
@@ -44,10 +44,15 @@ function syncLanguageFile(enUSPath, targetPath, langCode) {
|
|
|
44
44
|
|
|
45
45
|
function main() {
|
|
46
46
|
const targetDir = process.argv[2] || 'src/domains/localization/translations';
|
|
47
|
+
const targetLangCode = process.argv[3]; // Optional specific language to sync
|
|
47
48
|
const localesDir = path.resolve(process.cwd(), targetDir);
|
|
48
49
|
|
|
49
50
|
console.log('🚀 Starting translation synchronization...\n');
|
|
50
|
-
console.log(`📂 Locales directory: ${localesDir}
|
|
51
|
+
console.log(`📂 Locales directory: ${localesDir}`);
|
|
52
|
+
if (targetLangCode) {
|
|
53
|
+
console.log(`🎯 Target language: ${targetLangCode}`);
|
|
54
|
+
}
|
|
55
|
+
console.log('');
|
|
51
56
|
|
|
52
57
|
if (!fs.existsSync(localesDir)) {
|
|
53
58
|
console.error(`❌ Locales directory not found: ${localesDir}`);
|
|
@@ -61,9 +66,20 @@ function main() {
|
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
const files = fs.readdirSync(localesDir)
|
|
64
|
-
.filter(f =>
|
|
69
|
+
.filter(f => {
|
|
70
|
+
const isLangFile = f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/) && f !== 'en-US.ts';
|
|
71
|
+
if (!isLangFile) return false;
|
|
72
|
+
if (targetLangCode) {
|
|
73
|
+
return f === `${targetLangCode}.ts`;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
})
|
|
65
77
|
.sort();
|
|
66
78
|
|
|
79
|
+
if (targetLangCode && files.length === 0) {
|
|
80
|
+
console.warn(`⚠️ Target language file ${targetLangCode}.ts not found in ${targetDir}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
67
83
|
console.log(`📊 Languages to sync: ${files.length}\n`);
|
|
68
84
|
|
|
69
85
|
let totalAdded = 0;
|
|
@@ -47,10 +47,15 @@ async function translateLanguageFile(enUSPath, targetPath, langCode) {
|
|
|
47
47
|
|
|
48
48
|
async function main() {
|
|
49
49
|
const targetDir = process.argv[2] || 'src/domains/localization/translations';
|
|
50
|
+
const targetLangCode = process.argv[3]; // Optional specific language to translate
|
|
50
51
|
const localesDir = path.resolve(process.cwd(), targetDir);
|
|
51
52
|
|
|
52
53
|
console.log('🚀 Starting automatic translation...\n');
|
|
53
|
-
console.log(`📂 Locales directory: ${localesDir}
|
|
54
|
+
console.log(`📂 Locales directory: ${localesDir}`);
|
|
55
|
+
if (targetLangCode) {
|
|
56
|
+
console.log(`🎯 Target language: ${targetLangCode}`);
|
|
57
|
+
}
|
|
58
|
+
console.log('');
|
|
54
59
|
|
|
55
60
|
if (!fs.existsSync(localesDir)) {
|
|
56
61
|
console.error(`❌ Locales directory not found: ${localesDir}`);
|
|
@@ -64,9 +69,20 @@ async function main() {
|
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
const files = fs.readdirSync(localesDir)
|
|
67
|
-
.filter(f =>
|
|
72
|
+
.filter(f => {
|
|
73
|
+
const isLangFile = f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/) && f !== 'en-US.ts';
|
|
74
|
+
if (!isLangFile) return false;
|
|
75
|
+
if (targetLangCode) {
|
|
76
|
+
return f === `${targetLangCode}.ts`;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
})
|
|
68
80
|
.sort();
|
|
69
81
|
|
|
82
|
+
if (targetLangCode && files.length === 0) {
|
|
83
|
+
console.warn(`⚠️ Target language file ${targetLangCode}.ts not found in ${targetDir}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
70
86
|
console.log(`📊 Languages to translate: ${files.length}`);
|
|
71
87
|
console.log('⚡ Running with 200ms delay between API calls\n');
|
|
72
88
|
|