@umituz/react-native-localization 3.7.9 → 3.7.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "3.7.9",
3
+ "version": "3.7.10",
4
4
  "type": "module",
5
5
  "description": "Generic localization system for React Native apps with i18n support",
6
6
  "main": "./src/index.ts",
@@ -9,14 +9,12 @@
9
9
  import fs from 'fs';
10
10
  import path from 'path';
11
11
 
12
- function main() {
13
- const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
12
+ export function setupLanguages(targetDir) {
14
13
  const localesDir = path.resolve(process.cwd(), targetDir);
15
14
 
16
- console.log('šŸš€ Setting up language files...\n');
17
15
  if (!fs.existsSync(localesDir)) {
18
16
  console.error(`āŒ Locales directory not found: ${localesDir}`);
19
- process.exit(1);
17
+ return false;
20
18
  }
21
19
 
22
20
  const files = fs.readdirSync(localesDir)
@@ -52,6 +50,11 @@ export default translations;
52
50
 
53
51
  fs.writeFileSync(path.join(localesDir, 'index.ts'), content);
54
52
  console.log(`āœ… Generated index.ts with ${files.length} languages`);
53
+ return true;
55
54
  }
56
55
 
57
- main();
56
+ if (import.meta.url === `file://${process.argv[1]}`) {
57
+ const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
58
+ console.log('šŸš€ Setting up language files...\n');
59
+ setupLanguages(targetDir);
60
+ }
@@ -62,16 +62,13 @@ function processExtraction(srcDir, enUSPath) {
62
62
  }
63
63
  }
64
64
 
65
- function main() {
66
- const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
67
- const srcDir = process.argv[3];
65
+ export function syncTranslations(targetDir, srcDir) {
68
66
  const localesDir = path.resolve(process.cwd(), targetDir);
69
67
  const enUSPath = path.join(localesDir, 'en-US.ts');
70
68
 
71
- console.log('šŸš€ Starting translation synchronization...\n');
72
69
  if (!fs.existsSync(localesDir) || !fs.existsSync(enUSPath)) {
73
70
  console.error(`āŒ Localization files not found in: ${localesDir}`);
74
- process.exit(1);
71
+ return false;
75
72
  }
76
73
 
77
74
  processExtraction(srcDir, enUSPath);
@@ -84,16 +81,19 @@ function main() {
84
81
  files.forEach(file => {
85
82
  const langCode = file.replace('.ts', '');
86
83
  const targetPath = path.join(localesDir, file);
87
- console.log(`šŸŒ Syncing ${langCode} (${getLangDisplayName(langCode)})...`);
88
84
  const result = syncLanguageFile(enUSPath, targetPath, langCode);
89
85
  if (result.changed) {
90
- console.log(` āœļø +${result.added} keys, -${result.removed} keys`);
91
- } else {
92
- console.log(` āœ… Already synchronized`);
86
+ console.log(` šŸŒ ${langCode}: āœļø +${result.added} keys, -${result.removed} keys`);
93
87
  }
94
88
  });
95
89
 
96
90
  console.log(`\nāœ… Synchronization completed!`);
91
+ return true;
97
92
  }
98
93
 
99
- main();
94
+ if (import.meta.url === `file://${process.argv[1]}`) {
95
+ const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
96
+ const srcDir = process.argv[3];
97
+ console.log('šŸš€ Starting translation synchronization...\n');
98
+ syncTranslations(targetDir, srcDir);
99
+ }
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Translate Missing Script
5
5
  * Translates missing strings from en-US.ts to all other language files
6
- * Usage: node translate-missing.js [locales-dir] [lang-code-optional]
6
+ * Usage: node translate-missing.js [locales-dir] [src-dir-optional] [lang-code-optional]
7
7
  */
8
8
 
9
9
  import fs from 'fs';
@@ -11,6 +11,8 @@ import path from 'path';
11
11
  import { getTargetLanguage, isEnglishVariant, getLangDisplayName } from './utils/translation-config.js';
12
12
  import { parseTypeScriptFile, generateTypeScriptContent } from './utils/file-parser.js';
13
13
  import { translateObject } from './utils/translator.js';
14
+ import { setupLanguages } from './setup-languages.js';
15
+ import { syncTranslations } from './sync-translations.js';
14
16
 
15
17
  async function translateLanguageFile(enUSPath, targetPath, langCode) {
16
18
  const targetLang = getTargetLanguage(langCode);
@@ -47,11 +49,27 @@ async function translateLanguageFile(enUSPath, targetPath, langCode) {
47
49
 
48
50
  async function main() {
49
51
  const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
50
- const targetLangCode = process.argv[3];
52
+ const srcDir = process.argv[3];
53
+ const targetLangCode = process.argv[4];
54
+
51
55
  const localesDir = path.resolve(process.cwd(), targetDir);
52
56
  const enUSPath = path.join(localesDir, 'en-US.ts');
57
+ const indexPath = path.join(localesDir, 'index.ts');
58
+
59
+ console.log('šŸš€ Starting integrated translation workflow...\n');
60
+
61
+ // 1. Ensure setup exists (index.ts)
62
+ if (!fs.existsSync(indexPath)) {
63
+ console.log('šŸ“¦ Setup (index.ts) missing. Generating...');
64
+ setupLanguages(targetDir);
65
+ console.log('');
66
+ }
67
+
68
+ // 2. Synchronize keys (includes code scanning if srcDir is provided)
69
+ console.log('šŸ”„ Checking synchronization...');
70
+ syncTranslations(targetDir, srcDir);
71
+ console.log('');
53
72
 
54
- console.log('šŸš€ Starting automatic translation...\n');
55
73
  if (!fs.existsSync(localesDir) || !fs.existsSync(enUSPath)) {
56
74
  console.error(`āŒ Localization files not found in: ${localesDir}`);
57
75
  process.exit(1);
@@ -80,7 +98,7 @@ async function main() {
80
98
  }
81
99
  }
82
100
 
83
- console.log(`\nāœ… Translation completed! (Total: ${totalTranslated})`);
101
+ console.log(`\nāœ… Workflow completed! (Total translated: ${totalTranslated})`);
84
102
  }
85
103
 
86
104
  main().catch(error => {