@umituz/react-native-settings 5.4.23 → 5.4.25

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-settings",
3
- "version": "5.4.23",
3
+ "version": "5.4.25",
4
4
  "description": "Complete settings hub for React Native apps - consolidated package with settings, localization, about, legal, appearance, feedback, FAQs, rating, and gamification - expo-store-review and expo-device now lazy loaded",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./dist/index.d.ts",
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Pre-Publish Script
5
- * Basic checks before publishing
6
- */
7
-
8
- import fs from 'fs';
9
- import path from 'path';
10
- import { fileURLToPath } from 'url';
11
-
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = path.dirname(__filename);
14
-
15
- const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
16
- const SRC_DIR = path.join(PACKAGE_ROOT, 'src');
17
-
18
- if (!fs.existsSync(SRC_DIR)) {
19
- console.error('❌ src directory not found');
20
- process.exit(1);
21
- }
22
-
23
- const mainFiles = [
24
- 'src/index.ts',
25
- 'src/infrastructure/config/i18n.ts',
26
- ];
27
-
28
- for (const file of mainFiles) {
29
- const filePath = path.join(PACKAGE_ROOT, file);
30
- if (!fs.existsSync(filePath)) {
31
- console.error(`❌ Missing mandatory file: ${file}`);
32
- process.exit(1);
33
- }
34
- }
35
-
36
- console.log('✅ Pre-publish checks passed!');
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Setup Languages Script
5
- * Creates stub files for all supported languages (if not exist),
6
- * then generates index.ts from all available translation files.
7
- * Usage: node setup-languages.js [locales-dir]
8
- */
9
-
10
- import fs from 'fs';
11
- import path from 'path';
12
- import { LANGUAGE_MAP, getLangDisplayName } from './utils/translation-config.js';
13
-
14
- export function setupLanguages(targetDir) {
15
- const localesDir = path.resolve(process.cwd(), targetDir);
16
-
17
- if (!fs.existsSync(localesDir)) {
18
- console.error(`❌ Locales directory not found: ${localesDir}`);
19
- return false;
20
- }
21
-
22
- // Create stub files for all supported languages that don't exist yet
23
- let created = 0;
24
- for (const langCode of Object.keys(LANGUAGE_MAP)) {
25
- // Skip English variants — en-US is the base, others (en-AU, en-GB) are redundant
26
- if (langCode.startsWith('en-') && langCode !== 'en-US') continue;
27
-
28
- const filePath = path.join(localesDir, `${langCode}.ts`);
29
- if (!fs.existsSync(filePath)) {
30
- const langName = getLangDisplayName(langCode);
31
- fs.writeFileSync(
32
- filePath,
33
- `/**\n * ${langName} Translations\n * Auto-synced from en-US.ts\n */\n\nexport default {};\n`,
34
- );
35
- console.log(` ✅ Created ${langCode}.ts (${langName})`);
36
- created++;
37
- }
38
- }
39
-
40
- if (created > 0) {
41
- console.log(`\n📦 Created ${created} new language stubs.\n`);
42
- }
43
-
44
- // Generate index.ts from all language files
45
- const files = fs.readdirSync(localesDir)
46
- .filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/))
47
- .sort();
48
-
49
- const imports = [];
50
- const exports = [];
51
-
52
- files.forEach(file => {
53
- const code = file.replace('.ts', '');
54
- const varName = code.replace(/-([a-z0-9])/g, (g) => g[1].toUpperCase()).replace('-', '');
55
- imports.push(`import ${varName} from "./${code}";`);
56
- exports.push(` "${code}": ${varName},`);
57
- });
58
-
59
- const content = `/**
60
- * Localization Index
61
- * Exports all available translation files
62
- * Auto-generated by scripts/setup-languages.js
63
- */
64
-
65
- ${imports.join('\n')}
66
-
67
- export const translations = {
68
- ${exports.join('\n')}
69
- };
70
-
71
- export type TranslationKey = keyof typeof translations;
72
-
73
- export default translations;
74
- `;
75
-
76
- fs.writeFileSync(path.join(localesDir, 'index.ts'), content);
77
- console.log(`✅ Generated index.ts with ${files.length} languages`);
78
- return true;
79
- }
80
-
81
- if (import.meta.url === `file://${process.argv[1]}`) {
82
- const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
83
- console.log('🚀 Setting up language files...\n');
84
- setupLanguages(targetDir);
85
- }
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Sync Translations Script
5
- * Synchronizes translation keys from en-US.ts to all other language files
6
- * Usage: node sync-translations.js [locales-dir] [src-dir-optional]
7
- */
8
-
9
- import fs from 'fs';
10
- import path from 'path';
11
- import { parseTypeScriptFile, generateTypeScriptContent } from './utils/file-parser.js';
12
- import { addMissingKeys, removeExtraKeys } from './utils/sync-helper.js';
13
- import { detectNewKeys } from './utils/key-detector.js';
14
- import { extractUsedKeys } from './utils/key-extractor.js';
15
- import { setDeep } from './utils/object-helper.js';
16
-
17
- function syncLanguageFile(enUSPath, targetPath, langCode) {
18
- const enUS = parseTypeScriptFile(enUSPath);
19
- let target;
20
-
21
- try {
22
- target = parseTypeScriptFile(targetPath);
23
- } catch {
24
- target = {};
25
- }
26
-
27
- const newKeys = detectNewKeys(enUS, target);
28
- const addStats = { added: 0, newKeys: [] };
29
- const removeStats = { removed: 0, removedKeys: [] };
30
-
31
- addMissingKeys(enUS, target, addStats);
32
- removeExtraKeys(enUS, target, removeStats);
33
-
34
- const changed = addStats.added > 0 || removeStats.removed > 0;
35
-
36
- if (changed) {
37
- const content = generateTypeScriptContent(target, langCode);
38
- fs.writeFileSync(targetPath, content);
39
- }
40
-
41
- return { ...addStats, ...removeStats, newKeys, changed };
42
- }
43
-
44
- function processExtraction(srcDir, enUSPath) {
45
- if (!srcDir) return;
46
-
47
- console.log(`🔍 Scanning source code and dependencies: ${srcDir}...`);
48
- const usedKeyMap = extractUsedKeys(srcDir);
49
- console.log(` Found ${usedKeyMap.size} unique keys.`);
50
-
51
- const oldEnUS = parseTypeScriptFile(enUSPath);
52
- const newEnUS = {};
53
-
54
- let addedCount = 0;
55
- for (const [key, defaultValue] of usedKeyMap) {
56
- // Try to keep existing translation if it exists
57
- const existingValue = key.split('.').reduce((obj, k) => (obj && obj[k]), oldEnUS);
58
-
59
- // We treat it as "not translated" if the value is exactly the key string
60
- const isActuallyTranslated = typeof existingValue === 'string' && existingValue !== key;
61
- const valueToSet = isActuallyTranslated ? existingValue : defaultValue;
62
-
63
- if (setDeep(newEnUS, key, valueToSet)) {
64
- if (!isActuallyTranslated) addedCount++;
65
- }
66
- }
67
-
68
- // Count keys in objects
69
- const getKeysCount = (obj) => {
70
- let count = 0;
71
- const walk = (o) => {
72
- for (const k in o) {
73
- if (typeof o[k] === 'object' && o[k] !== null) walk(o[k]);
74
- else count++;
75
- }
76
- };
77
- walk(obj);
78
- return count;
79
- };
80
-
81
- const oldTotal = getKeysCount(oldEnUS);
82
- const newTotal = getKeysCount(newEnUS);
83
- const removedCount = oldTotal - (newTotal - addedCount);
84
-
85
- console.log(` ✨ Optimized en-US.ts: ${addedCount} keys populated/updated, pruned ${Math.max(0, removedCount)} unused.`);
86
- const content = generateTypeScriptContent(newEnUS, 'en-US');
87
- fs.writeFileSync(enUSPath, content);
88
- }
89
-
90
- export function syncTranslations(targetDir, srcDir) {
91
- const localesDir = path.resolve(process.cwd(), targetDir);
92
- const enUSPath = path.join(localesDir, 'en-US.ts');
93
-
94
- if (!fs.existsSync(localesDir) || !fs.existsSync(enUSPath)) {
95
- console.error(`❌ Localization files not found in: ${localesDir}`);
96
- return false;
97
- }
98
-
99
- processExtraction(srcDir, enUSPath);
100
-
101
- const files = fs.readdirSync(localesDir)
102
- .filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/) && f !== 'en-US.ts')
103
- .sort();
104
-
105
- console.log(`📊 Languages to sync: ${files.length}\n`);
106
- files.forEach(file => {
107
- const langCode = file.replace('.ts', '');
108
- const targetPath = path.join(localesDir, file);
109
- const result = syncLanguageFile(enUSPath, targetPath, langCode);
110
- if (result.changed) {
111
- console.log(` 🌍 ${langCode}: ✏️ +${result.added} keys, -${result.removed} keys`);
112
- }
113
- });
114
-
115
- console.log(`\n✅ Synchronization completed!`);
116
- return true;
117
- }
118
-
119
- if (import.meta.url === `file://${process.argv[1]}`) {
120
- const targetDir = process.argv[2] || 'src/domains/localization/infrastructure/locales';
121
- const srcDir = process.argv[3];
122
- console.log('🚀 Starting translation synchronization...\n');
123
- syncTranslations(targetDir, srcDir);
124
- }
@@ -1,121 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Translate Missing Script
5
- * Automatically translates missing strings using Google Translate
6
- * Refactored to use @umituz/react-native-google-translate package
7
- */
8
-
9
- import fs from 'fs';
10
- import path from 'path';
11
- import { parseTypeScriptFile, generateTypeScriptContent } from './utils/file-parser.js';
12
- import {
13
- googleTranslateService,
14
- getTargetLanguage,
15
- getLanguageDisplayName,
16
- } from '@umituz/react-native-google-translate/services';
17
- import { setupLanguages } from './setup-languages.js';
18
- import { syncTranslations } from './sync-translations.js';
19
-
20
- async function translateMissing(targetDir, srcDir) {
21
- // Initialize the translation service
22
- googleTranslateService.initialize({
23
- minDelay: 100,
24
- maxRetries: 3,
25
- timeout: 10000,
26
- });
27
-
28
- const localesDir = path.resolve(process.cwd(), targetDir);
29
- const enUSPath = path.join(localesDir, 'en-US.ts');
30
-
31
- const skipSync = process.argv.includes('--no-sync');
32
-
33
- if (!fs.existsSync(path.join(localesDir, 'index.ts'))) {
34
- console.log('🔄 Initializing localization setup...');
35
- setupLanguages(targetDir);
36
- }
37
-
38
- if (!skipSync) {
39
- console.log('\n🔄 Checking synchronization...');
40
- syncTranslations(targetDir, srcDir);
41
- } else {
42
- console.log('\n⏭️ Skipping synchronization check...');
43
- }
44
-
45
- const files = fs.readdirSync(localesDir)
46
- .filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/) && f !== 'en-US.ts')
47
- .sort();
48
-
49
- console.log(`\n📊 Languages to translate: ${files.length}\n`);
50
-
51
- const enUS = parseTypeScriptFile(enUSPath);
52
-
53
- for (const file of files) {
54
- const langCode = file.replace('.ts', '');
55
-
56
- // Skip English variants
57
- const targetLang = getTargetLanguage(langCode);
58
- if (!targetLang || targetLang === 'en') {
59
- console.log(`⏭️ Skipping ${langCode} (English variant)`);
60
- continue;
61
- }
62
-
63
- const langName = getLanguageDisplayName(langCode);
64
- console.log(`🌍 Translating ${langCode} (${langName})...`);
65
-
66
- const targetPath = path.join(localesDir, file);
67
- const target = parseTypeScriptFile(targetPath);
68
-
69
- const stats = {
70
- totalCount: 0,
71
- successCount: 0,
72
- failureCount: 0,
73
- skippedCount: 0,
74
- translatedKeys: [],
75
- };
76
-
77
- await googleTranslateService.translateObject(
78
- enUS,
79
- target,
80
- targetLang,
81
- '',
82
- stats
83
- );
84
-
85
- // Clear progress line
86
- process.stdout.write('\r' + ' '.repeat(80) + '\r');
87
-
88
- if (stats.successCount > 0) {
89
- const content = generateTypeScriptContent(target, langCode);
90
- fs.writeFileSync(targetPath, content);
91
-
92
- console.log(` ✅ Successfully translated ${stats.successCount} keys:`);
93
-
94
- // Detailed logging of translated keys
95
- const displayCount = Math.min(stats.translatedKeys.length, 15);
96
- stats.translatedKeys.slice(0, displayCount).forEach(item => {
97
- console.log(` • ${item.key}: "${item.from}" → "${item.to}"`);
98
- });
99
-
100
- if (stats.translatedKeys.length > displayCount) {
101
- console.log(` ... and ${stats.translatedKeys.length - displayCount} more.`);
102
- }
103
- } else {
104
- console.log(` ✨ Already up to date.`);
105
- }
106
- }
107
-
108
- console.log('\n✅ All translations completed!');
109
- }
110
-
111
- const isMainModule = import.meta.url.endsWith('translate-missing.js');
112
- if (isMainModule) {
113
- const args = process.argv.slice(2).filter(arg => !arg.startsWith('--'));
114
- const targetDir = args[0] || 'src/domains/localization/infrastructure/locales';
115
- const srcDir = args[1];
116
- console.log('🚀 Starting integrated translation workflow...');
117
- translateMissing(targetDir, srcDir).catch(err => {
118
- console.error('\n❌ Translation workflow failed:', err.message);
119
- process.exit(1);
120
- });
121
- }
@@ -1,104 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getLangDisplayName } from './translation-config.js';
4
-
5
- /**
6
- * File Parser
7
- * Parse and generate TypeScript translation files
8
- */
9
-
10
- export function parseTypeScriptFile(filePath) {
11
- const content = fs.readFileSync(filePath, 'utf8');
12
-
13
- // Match: export default { ... } OR export const NAME = { ... }
14
- const match = content.match(/export\s+(?:default|const\s+\w+\s*=)\s*(\{[\s\S]*\});?\s*$/);
15
-
16
- if (!match) {
17
- throw new Error(`Could not parse TypeScript file: ${filePath}`);
18
- }
19
-
20
- const objectStr = match[1].replace(/;$/, '');
21
-
22
- try {
23
- // Basic evaluation for simple objects (works for generated language files like tr-TR.ts
24
- // and sub-module files like common.ts, home.ts, etc.)
25
- // eslint-disable-next-line no-eval
26
- return eval(`(${objectStr})`);
27
- } catch (error) {
28
- // File might be a barrel file with named imports (e.g., en-US.ts that imports sub-modules)
29
- // Try to resolve each import and merge into a single object
30
- const dir = path.dirname(filePath);
31
- const importMatches = [...content.matchAll(/import\s*\{\s*(\w+)\s*\}\s*from\s*["']\.\/(\w+)["']/g)];
32
-
33
- if (importMatches.length > 0) {
34
- const result = {};
35
- for (const [, varName, moduleName] of importMatches) {
36
- const subFilePath = path.join(dir, `${moduleName}.ts`);
37
- if (fs.existsSync(subFilePath)) {
38
- try {
39
- result[varName] = parseTypeScriptFile(subFilePath);
40
- } catch {
41
- // ignore individual sub-file parse errors
42
- }
43
- }
44
- }
45
- if (Object.keys(result).length > 0) {
46
- return result;
47
- }
48
- }
49
-
50
- console.warn(`\n⚠️ Warning: Could not fully parse ${filePath}. Files with complex imports/spreads are currently limited.`);
51
- return {};
52
- }
53
- }
54
-
55
- export function stringifyValue(value, indent = 2) {
56
- if (typeof value === 'string') {
57
- const escaped = value
58
- .replace(/\\/g, '\\\\')
59
- .replace(/"/g, '\\"')
60
- .replace(/\n/g, '\\n');
61
- return `"${escaped}"`;
62
- }
63
-
64
- if (Array.isArray(value)) {
65
- if (value.length === 0) return '[]';
66
- const items = value.map(v => stringifyValue(v, indent + 2));
67
- return `[${items.join(', ')}]`;
68
- }
69
-
70
- if (typeof value === 'object' && value !== null) {
71
- const entries = Object.entries(value);
72
-
73
- if (entries.length === 0) {
74
- return '{}';
75
- }
76
-
77
- const spaces = ' '.repeat(indent);
78
- const innerSpaces = ' '.repeat(indent + 2);
79
- const entriesStr = entries
80
- .sort((a, b) => a[0].localeCompare(b[0]))
81
- .map(([k, v]) => {
82
- const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(k) ? k : `"${k}"`;
83
- return `${innerSpaces}${key}: ${stringifyValue(v, indent + 2)}`;
84
- })
85
- .join(',\n');
86
- return `{\n${entriesStr},\n${spaces}}`;
87
- }
88
-
89
- return String(value);
90
- }
91
-
92
- export function generateTypeScriptContent(obj, langCode) {
93
- const langName = getLangDisplayName(langCode);
94
- const isBase = langCode === 'en-US';
95
- const objString = stringifyValue(obj, 0);
96
-
97
- return `/**
98
- * ${langName} Translations
99
- * ${isBase ? 'Base translations file' : 'Auto-synced from en-US.ts'}
100
- */
101
-
102
- export default ${objString};
103
- `;
104
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * Key Detector
3
- * Detects new, missing, and removed keys between source and target objects
4
- */
5
-
6
- export function detectNewKeys(sourceObj, targetObj, path = '', newKeys = []) {
7
- for (const key in sourceObj) {
8
- const currentPath = path ? `${path}.${key}` : key;
9
- const sourceValue = sourceObj[key];
10
- const targetValue = targetObj[key];
11
-
12
- if (!Object.prototype.hasOwnProperty.call(targetObj, key)) {
13
- newKeys.push({ path: currentPath, value: sourceValue });
14
- } else if (
15
- typeof sourceValue === 'object' &&
16
- sourceValue !== null &&
17
- !Array.isArray(sourceValue)
18
- ) {
19
- if (typeof targetValue === 'object' && targetValue !== null && !Array.isArray(targetValue)) {
20
- detectNewKeys(sourceValue, targetValue, currentPath, newKeys);
21
- }
22
- }
23
- }
24
- return newKeys;
25
- }
26
-
27
- export function detectMissingKeys(sourceObj, targetObj, path = '', missingKeys = []) {
28
- for (const key in targetObj) {
29
- const currentPath = path ? `${path}.${key}` : key;
30
-
31
- if (!Object.prototype.hasOwnProperty.call(sourceObj, key)) {
32
- missingKeys.push(currentPath);
33
- } else if (
34
- typeof sourceObj[key] === 'object' &&
35
- sourceObj[key] !== null &&
36
- !Array.isArray(sourceObj[key]) &&
37
- typeof targetObj[key] === 'object' &&
38
- targetObj[key] !== null &&
39
- !Array.isArray(targetObj[key])
40
- ) {
41
- detectMissingKeys(sourceObj[key], targetObj[key], currentPath, missingKeys);
42
- }
43
- }
44
- return missingKeys;
45
- }
@@ -1,105 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- /**
5
- * Generic Key Extractor
6
- * Scans source code for i18n translation keys
7
- * NO project-specific logic - works for any React Native app
8
- */
9
-
10
- const IGNORED_DOMAINS = ['.com', '.org', '.net', '.io', '.co', '.app', '.ai', '.gov', '.edu'];
11
- const IGNORED_EXTENSIONS = [
12
- '.ts', '.tsx', '.js', '.jsx', '.json', '.yaml', '.yml',
13
- '.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.pdf',
14
- '.mp4', '.mov', '.avi', '.mp3', '.wav', '.css', '.scss', '.md'
15
- ];
16
- const IGNORED_LAYOUT_VALS = new Set([
17
- 'center', 'row', 'column', 'flex', 'absolute', 'relative', 'hidden', 'visible',
18
- 'transparent', 'bold', 'normal', 'italic', 'contain', 'cover', 'stretch',
19
- 'top', 'bottom', 'left', 'right', 'middle', 'auto', 'none', 'underline',
20
- 'capitalize', 'uppercase', 'lowercase', 'solid', 'dotted', 'dashed', 'wrap',
21
- 'nowrap', 'space-between', 'space-around', 'flex-start', 'flex-end', 'baseline',
22
- 'react', 'index', 'default', 'string', 'number', 'boolean', 'key', 'id'
23
- ]);
24
-
25
- function extractFromFile(content, keyMap) {
26
- // Pattern 1: t('key') or t("key")
27
- const tRegex = /(?:^|\W)t\(['"`]([^'"`]+)['"`]\)/g;
28
- let match;
29
- while ((match = tRegex.exec(content)) !== null) {
30
- const key = match[1];
31
- if (!key.includes('${') && !keyMap.has(key)) {
32
- keyMap.set(key, key); // Use key itself as default
33
- }
34
- }
35
-
36
- // Pattern 2: Dot-notation strings (potential i18n keys)
37
- const dotRegex = /['"`]([a-z][a-z0-9_]*\.(?:[a-z0-9_]+\.)+[a-z0-9_]+)['"`]/gi;
38
- while ((match = dotRegex.exec(content)) !== null) {
39
- const key = match[1];
40
- const isIgnoredDomain = IGNORED_DOMAINS.some(ext => key.toLowerCase().endsWith(ext));
41
- const isIgnoredExt = IGNORED_EXTENSIONS.some(ext => key.toLowerCase().endsWith(ext));
42
- if (!isIgnoredDomain && !isIgnoredExt && !key.includes(' ') && !keyMap.has(key)) {
43
- keyMap.set(key, key);
44
- }
45
- }
46
-
47
- // Pattern 3: Template literals t(`prefix.${var}`)
48
- const templateRegex = /t\(\`([a-z0-9_.]+)\.\$\{/g;
49
- while ((match = templateRegex.exec(content)) !== null) {
50
- const prefix = match[1];
51
- const arrayMatches = content.matchAll(/\[([\s\S]*?)\]/g);
52
- for (const arrayMatch of arrayMatches) {
53
- const inner = arrayMatch[1];
54
- const idMatches = inner.matchAll(/['"`]([a-z0-9_]{2,40})['"`]/g);
55
- for (const idMatch of idMatches) {
56
- const id = idMatch[1];
57
- if (IGNORED_LAYOUT_VALS.has(id.toLowerCase())) continue;
58
- if (/^[0-9]+$/.test(id)) continue;
59
-
60
- const dynamicKey = `${prefix}.${id}`;
61
- if (!keyMap.has(dynamicKey)) {
62
- keyMap.set(dynamicKey, dynamicKey);
63
- }
64
- }
65
- }
66
- }
67
- }
68
-
69
- function walkDirectory(dir, keyMap, skipDirs = ['node_modules', '.expo', '.git', 'build', 'ios', 'android', 'assets', 'locales', '__tests__']) {
70
- if (!fs.existsSync(dir)) return;
71
-
72
- const files = fs.readdirSync(dir);
73
- for (const file of files) {
74
- const fullPath = path.join(dir, file);
75
- const stat = fs.statSync(fullPath);
76
-
77
- if (stat.isDirectory()) {
78
- if (!skipDirs.includes(file)) {
79
- walkDirectory(fullPath, keyMap, skipDirs);
80
- }
81
- } else if (/\.(ts|tsx|js|jsx)$/.test(file)) {
82
- const content = fs.readFileSync(fullPath, 'utf8');
83
- extractFromFile(content, keyMap);
84
- }
85
- }
86
- }
87
-
88
- export function extractUsedKeys(srcDir) {
89
- const keyMap = new Map();
90
- if (!srcDir) return keyMap;
91
-
92
- const projectRoot = process.cwd();
93
- const absoluteSrcDir = path.resolve(projectRoot, srcDir);
94
-
95
- // Scan project source
96
- walkDirectory(absoluteSrcDir, keyMap);
97
-
98
- // Scan @umituz packages for shared keys
99
- const packagesDir = path.resolve(projectRoot, 'node_modules/@umituz');
100
- if (fs.existsSync(packagesDir)) {
101
- walkDirectory(packagesDir, keyMap);
102
- }
103
-
104
- return keyMap;
105
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Object Helper
3
- * Utilities for deep object manipulation
4
- */
5
-
6
- /**
7
- * Set a value in a nested object, creating intermediate objects if necessary
8
- * Returns true if the key was newly added, false if it already existed
9
- */
10
- export function setDeep(obj, path, value) {
11
- const keys = path.split('.');
12
- let current = obj;
13
-
14
- for (let i = 0; i < keys.length - 1; i++) {
15
- const key = keys[i];
16
- if (!current[key] || typeof current[key] !== 'object' || Array.isArray(current[key])) {
17
- current[key] = {};
18
- }
19
- current = current[key];
20
- }
21
-
22
- const lastKey = keys[keys.length - 1];
23
- if (current[lastKey] === undefined) {
24
- current[lastKey] = value;
25
- return true;
26
- }
27
-
28
- return false;
29
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * Sync Helper
3
- * Helper functions for synchronizing translation keys
4
- */
5
-
6
- export function addMissingKeys(sourceObj, targetObj, stats = { added: 0, newKeys: [] }) {
7
- for (const key in sourceObj) {
8
- const sourceValue = sourceObj[key];
9
- const isNewKey = !Object.prototype.hasOwnProperty.call(targetObj, key);
10
-
11
- if (isNewKey) {
12
- targetObj[key] = sourceValue;
13
- stats.added++;
14
- stats.newKeys.push(key);
15
- } else if (
16
- typeof sourceValue === 'object' &&
17
- sourceValue !== null &&
18
- !Array.isArray(sourceValue)
19
- ) {
20
- if (!targetObj[key] || typeof targetObj[key] !== 'object') {
21
- targetObj[key] = {};
22
- }
23
- addMissingKeys(sourceValue, targetObj[key], stats);
24
- }
25
- }
26
- return stats;
27
- }
28
-
29
- export function removeExtraKeys(sourceObj, targetObj, stats = { removed: 0, removedKeys: [] }) {
30
- for (const key in targetObj) {
31
- const isExtraKey = !Object.prototype.hasOwnProperty.call(sourceObj, key);
32
-
33
- if (isExtraKey) {
34
- delete targetObj[key];
35
- stats.removed++;
36
- stats.removedKeys.push(key);
37
- } else if (
38
- typeof sourceObj[key] === 'object' &&
39
- sourceObj[key] !== null &&
40
- !Array.isArray(sourceObj[key]) &&
41
- typeof targetObj[key] === 'object' &&
42
- targetObj[key] !== null &&
43
- !Array.isArray(targetObj[key])
44
- ) {
45
- removeExtraKeys(sourceObj[key], targetObj[key], stats);
46
- }
47
- }
48
- return stats;
49
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Translation Configuration
3
- * Re-exports from @umituz/react-native-google-translate package
4
- * This file provides backward compatibility for existing imports
5
- */
6
-
7
- export {
8
- LANGUAGE_MAP,
9
- SKIP_WORDS,
10
- LANGUAGE_NAMES,
11
- getTargetLanguage,
12
- isEnglishVariant,
13
- getLanguageDisplayName,
14
- shouldSkipWord,
15
- } from '@umituz/react-native-google-translate/services';
16
-
17
- // Backward compatibility alias
18
- export function getLangDisplayName(code) {
19
- return getLanguageDisplayName(code);
20
- }