@umituz/react-native-localization 3.5.4 ā 3.5.6
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,9 +35,10 @@ export class I18nInitializer {
|
|
|
35
35
|
i18n.init({
|
|
36
36
|
resources,
|
|
37
37
|
lng: languageCode,
|
|
38
|
-
fallbackLng:
|
|
38
|
+
fallbackLng: DEFAULT_LANGUAGE,
|
|
39
39
|
ns: namespaces,
|
|
40
40
|
defaultNS: defaultNamespace,
|
|
41
|
+
|
|
41
42
|
fallbackNS: defaultNamespace,
|
|
42
43
|
interpolation: { escapeValue: false },
|
|
43
44
|
react: { useSuspense: false },
|
|
@@ -13,7 +13,11 @@ function main() {
|
|
|
13
13
|
const targetDir = process.argv[2] || 'src/domains/localization/translations';
|
|
14
14
|
const localesDir = path.resolve(process.cwd(), targetDir);
|
|
15
15
|
|
|
16
|
+
console.log('š Setting up language files...\n');
|
|
17
|
+
console.log(`š Locales directory: ${localesDir}\n`);
|
|
18
|
+
|
|
16
19
|
if (!fs.existsSync(localesDir)) {
|
|
20
|
+
console.error(`ā Locales directory not found: ${localesDir}`);
|
|
17
21
|
process.exit(1);
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -21,6 +25,8 @@ function main() {
|
|
|
21
25
|
.filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/))
|
|
22
26
|
.sort();
|
|
23
27
|
|
|
28
|
+
console.log(`š Found ${files.length} language files:\n`);
|
|
29
|
+
|
|
24
30
|
const imports = [];
|
|
25
31
|
const exports = [];
|
|
26
32
|
|
|
@@ -28,6 +34,7 @@ function main() {
|
|
|
28
34
|
const code = file.replace('.ts', '');
|
|
29
35
|
const varName = code.replace(/-([a-z0-9])/g, (g) => g[1].toUpperCase()).replace('-', '');
|
|
30
36
|
|
|
37
|
+
console.log(` š ${code}`);
|
|
31
38
|
imports.push(`import ${varName} from "./${code}";`);
|
|
32
39
|
exports.push(` "${code}": ${varName},`);
|
|
33
40
|
});
|
|
@@ -49,7 +56,11 @@ export type TranslationKey = keyof typeof translations;
|
|
|
49
56
|
export default translations;
|
|
50
57
|
`;
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
const indexPath = path.join(localesDir, 'index.ts');
|
|
60
|
+
fs.writeFileSync(indexPath, content);
|
|
61
|
+
|
|
62
|
+
console.log(`\nā
Generated index.ts with ${files.length} languages`);
|
|
63
|
+
console.log(` Output: ${indexPath}`);
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
main();
|
|
@@ -10,6 +10,7 @@ const fs = require('fs');
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const { parseTypeScriptFile, generateTypeScriptContent } = require('./utils/file-parser');
|
|
12
12
|
const { addMissingKeys, removeExtraKeys } = require('./utils/sync-helper');
|
|
13
|
+
const { getLangDisplayName } = require('./utils/translation-config');
|
|
13
14
|
|
|
14
15
|
function syncLanguageFile(enUSPath, targetPath, langCode) {
|
|
15
16
|
const enUS = parseTypeScriptFile(enUSPath);
|
|
@@ -45,12 +46,17 @@ function main() {
|
|
|
45
46
|
const targetDir = process.argv[2] || 'src/domains/localization/translations';
|
|
46
47
|
const localesDir = path.resolve(process.cwd(), targetDir);
|
|
47
48
|
|
|
49
|
+
console.log('š Starting translation synchronization...\n');
|
|
50
|
+
console.log(`š Locales directory: ${localesDir}\n`);
|
|
51
|
+
|
|
48
52
|
if (!fs.existsSync(localesDir)) {
|
|
53
|
+
console.error(`ā Locales directory not found: ${localesDir}`);
|
|
49
54
|
process.exit(1);
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
const enUSPath = path.join(localesDir, 'en-US.ts');
|
|
53
58
|
if (!fs.existsSync(enUSPath)) {
|
|
59
|
+
console.error(`ā Base file not found: ${enUSPath}`);
|
|
54
60
|
process.exit(1);
|
|
55
61
|
}
|
|
56
62
|
|
|
@@ -58,10 +64,41 @@ function main() {
|
|
|
58
64
|
.filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/) && f !== 'en-US.ts')
|
|
59
65
|
.sort();
|
|
60
66
|
|
|
67
|
+
console.log(`š Languages to sync: ${files.length}\n`);
|
|
68
|
+
|
|
69
|
+
let totalAdded = 0;
|
|
70
|
+
let totalRemoved = 0;
|
|
71
|
+
let totalChanged = 0;
|
|
72
|
+
|
|
61
73
|
for (const file of files) {
|
|
62
74
|
const langCode = file.replace('.ts', '');
|
|
63
75
|
const targetPath = path.join(localesDir, file);
|
|
64
|
-
|
|
76
|
+
|
|
77
|
+
console.log(`š Syncing ${langCode} (${getLangDisplayName(langCode)})...`);
|
|
78
|
+
|
|
79
|
+
const result = syncLanguageFile(enUSPath, targetPath, langCode);
|
|
80
|
+
|
|
81
|
+
if (result.changed) {
|
|
82
|
+
console.log(` āļø +${result.added} keys, -${result.removed} keys`);
|
|
83
|
+
totalAdded += result.added;
|
|
84
|
+
totalRemoved += result.removed;
|
|
85
|
+
totalChanged++;
|
|
86
|
+
} else {
|
|
87
|
+
console.log(` ā
Already synchronized`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`\nš Summary:`);
|
|
92
|
+
console.log(` Languages processed: ${files.length}`);
|
|
93
|
+
console.log(` Files changed: ${totalChanged}`);
|
|
94
|
+
console.log(` Keys added: ${totalAdded}`);
|
|
95
|
+
console.log(` Keys removed: ${totalRemoved}`);
|
|
96
|
+
|
|
97
|
+
if (totalChanged > 0) {
|
|
98
|
+
console.log(`\nā
Synchronization completed!`);
|
|
99
|
+
console.log(` Next: Run 'npm run i18n:translate' to translate new keys`);
|
|
100
|
+
} else {
|
|
101
|
+
console.log(`\nā
All languages were already synchronized!`);
|
|
65
102
|
}
|
|
66
103
|
}
|
|
67
104
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
const fs = require('fs');
|
|
10
10
|
const path = require('path');
|
|
11
|
-
const { getTargetLanguage, isEnglishVariant } = require('./utils/translation-config');
|
|
11
|
+
const { getTargetLanguage, isEnglishVariant, getLangDisplayName } = require('./utils/translation-config');
|
|
12
12
|
const { parseTypeScriptFile, generateTypeScriptContent } = require('./utils/file-parser');
|
|
13
13
|
const { translateObject } = require('./utils/translator');
|
|
14
14
|
|
|
@@ -16,10 +16,12 @@ async function translateLanguageFile(enUSPath, targetPath, langCode) {
|
|
|
16
16
|
const targetLang = getTargetLanguage(langCode);
|
|
17
17
|
|
|
18
18
|
if (!targetLang) {
|
|
19
|
+
console.log(` ā ļø No language mapping for ${langCode}, skipping`);
|
|
19
20
|
return 0;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
if (isEnglishVariant(langCode)) {
|
|
24
|
+
console.log(` āļø Skipping English variant: ${langCode}`);
|
|
23
25
|
return 0;
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -47,12 +49,17 @@ async function main() {
|
|
|
47
49
|
const targetDir = process.argv[2] || 'src/domains/localization/translations';
|
|
48
50
|
const localesDir = path.resolve(process.cwd(), targetDir);
|
|
49
51
|
|
|
52
|
+
console.log('š Starting automatic translation...\n');
|
|
53
|
+
console.log(`š Locales directory: ${localesDir}\n`);
|
|
54
|
+
|
|
50
55
|
if (!fs.existsSync(localesDir)) {
|
|
56
|
+
console.error(`ā Locales directory not found: ${localesDir}`);
|
|
51
57
|
process.exit(1);
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
const enUSPath = path.join(localesDir, 'en-US.ts');
|
|
55
61
|
if (!fs.existsSync(enUSPath)) {
|
|
62
|
+
console.error(`ā Base file not found: ${enUSPath}`);
|
|
56
63
|
process.exit(1);
|
|
57
64
|
}
|
|
58
65
|
|
|
@@ -60,16 +67,33 @@ async function main() {
|
|
|
60
67
|
.filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/) && f !== 'en-US.ts')
|
|
61
68
|
.sort();
|
|
62
69
|
|
|
70
|
+
console.log(`š Languages to translate: ${files.length}`);
|
|
71
|
+
console.log('ā” Running with 200ms delay between API calls\n');
|
|
72
|
+
|
|
63
73
|
let totalTranslated = 0;
|
|
64
74
|
|
|
65
75
|
for (const file of files) {
|
|
66
76
|
const langCode = file.replace('.ts', '');
|
|
67
77
|
const targetPath = path.join(localesDir, file);
|
|
78
|
+
|
|
79
|
+
console.log(`\nš Translating ${langCode} (${getLangDisplayName(langCode)})...`);
|
|
80
|
+
|
|
68
81
|
const count = await translateLanguageFile(enUSPath, targetPath, langCode);
|
|
69
82
|
totalTranslated += count;
|
|
83
|
+
|
|
84
|
+
if (count > 0) {
|
|
85
|
+
console.log(` ā
Translated ${count} strings`);
|
|
86
|
+
} else {
|
|
87
|
+
console.log(` ā Already complete`);
|
|
88
|
+
}
|
|
70
89
|
}
|
|
90
|
+
|
|
91
|
+
console.log(`\nā
Translation completed!`);
|
|
92
|
+
console.log(` Total strings translated: ${totalTranslated}`);
|
|
93
|
+
console.log(`\nš Next: Run 'npm run i18n:setup' to update index.ts`);
|
|
71
94
|
}
|
|
72
95
|
|
|
73
|
-
main().catch(() => {
|
|
96
|
+
main().catch((error) => {
|
|
97
|
+
console.error('ā Translation failed:', error.message);
|
|
74
98
|
process.exit(1);
|
|
75
99
|
});
|
|
@@ -67,6 +67,8 @@ async function translateObject(enObj, targetObj, targetLang, path = '', stats =
|
|
|
67
67
|
for (let i = 0; i < enValue.length; i++) {
|
|
68
68
|
if (typeof enValue[i] === 'string') {
|
|
69
69
|
if (needsTranslation(targetObj[key][i], enValue[i])) {
|
|
70
|
+
const preview = enValue[i].length > 40 ? enValue[i].substring(0, 40) + '...' : enValue[i];
|
|
71
|
+
console.log(` š ${currentPath}[${i}]: "${preview}"`);
|
|
70
72
|
targetObj[key][i] = await translateText(enValue[i], targetLang);
|
|
71
73
|
stats.count++;
|
|
72
74
|
await delay(200);
|
|
@@ -80,6 +82,8 @@ async function translateObject(enObj, targetObj, targetLang, path = '', stats =
|
|
|
80
82
|
await translateObject(enValue, targetObj[key], targetLang, currentPath, stats);
|
|
81
83
|
} else if (typeof enValue === 'string') {
|
|
82
84
|
if (needsTranslation(targetValue, enValue)) {
|
|
85
|
+
const preview = enValue.length > 40 ? enValue.substring(0, 40) + '...' : enValue;
|
|
86
|
+
console.log(` š ${currentPath}: "${preview}"`);
|
|
83
87
|
targetObj[key] = await translateText(enValue, targetLang);
|
|
84
88
|
stats.count++;
|
|
85
89
|
await delay(200);
|