@umituz/react-native-localization 2.7.0 → 3.0.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 +21 -10
- package/scripts/prepublish.js +29 -16
- package/src/domain/repositories/ILocalizationRepository.ts +2 -2
- package/src/index.ts +5 -1
- package/src/infrastructure/components/LanguageSwitcher.tsx +90 -37
- package/src/infrastructure/components/LocalizationProvider.tsx +115 -7
- package/src/infrastructure/components/__tests__/LanguageSwitcher.test.tsx +91 -0
- package/src/infrastructure/components/useLanguageNavigation.ts +4 -4
- package/src/infrastructure/config/TranslationCache.ts +27 -0
- package/src/infrastructure/config/TranslationLoader.ts +4 -8
- package/src/infrastructure/config/__tests__/TranslationCache.test.ts +44 -0
- package/src/infrastructure/config/__tests__/languagesData.test.ts +49 -0
- package/src/infrastructure/config/languages.ts +1 -1
- package/src/infrastructure/config/languagesData.ts +91 -61
- package/src/infrastructure/hooks/__tests__/useTranslation.test.ts +52 -0
- package/src/infrastructure/hooks/useLocalization.ts +58 -0
- package/src/infrastructure/hooks/useTranslation.ts +84 -29
- package/src/infrastructure/storage/LanguageInitializer.ts +7 -5
- package/src/infrastructure/storage/LanguageSwitcher.ts +3 -3
- package/src/infrastructure/storage/LocalizationStore.ts +103 -94
- package/src/infrastructure/storage/types/LocalizationState.ts +31 -0
- package/src/presentation/components/LanguageItem.tsx +109 -0
- package/src/presentation/components/SearchInput.tsx +90 -0
- package/src/presentation/components/__tests__/LanguageItem.test.tsx +106 -0
- package/src/presentation/components/__tests__/SearchInput.test.tsx +95 -0
- package/src/presentation/screens/LanguageSelectionScreen.tsx +148 -0
- package/src/presentation/screens/__tests__/LanguageSelectionScreen.test.tsx +166 -0
- package/src/scripts/prepublish.ts +48 -0
- package/src/infrastructure/locales/en-US/alerts.json +0 -107
- package/src/infrastructure/locales/en-US/auth.json +0 -34
- package/src/infrastructure/locales/en-US/branding.json +0 -8
- package/src/infrastructure/locales/en-US/clipboard.json +0 -9
- package/src/infrastructure/locales/en-US/common.json +0 -57
- package/src/infrastructure/locales/en-US/datetime.json +0 -138
- package/src/infrastructure/locales/en-US/device.json +0 -14
- package/src/infrastructure/locales/en-US/editor.json +0 -64
- package/src/infrastructure/locales/en-US/errors.json +0 -41
- package/src/infrastructure/locales/en-US/general.json +0 -57
- package/src/infrastructure/locales/en-US/goals.json +0 -5
- package/src/infrastructure/locales/en-US/haptics.json +0 -6
- package/src/infrastructure/locales/en-US/home.json +0 -62
- package/src/infrastructure/locales/en-US/index.ts +0 -54
- package/src/infrastructure/locales/en-US/navigation.json +0 -6
- package/src/infrastructure/locales/en-US/onboarding.json +0 -26
- package/src/infrastructure/locales/en-US/projects.json +0 -34
- package/src/infrastructure/locales/en-US/settings.json +0 -45
- package/src/infrastructure/locales/en-US/sharing.json +0 -8
- package/src/infrastructure/locales/en-US/templates.json +0 -28
- package/src/infrastructure/scripts/createLocaleLoaders.js +0 -177
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
* Auto-Loader Generator for Localization
|
|
5
|
-
*
|
|
6
|
-
* NOTE: This is a Node.js build script, not React Native code.
|
|
7
|
-
* ESLint is disabled for this file as it uses Node.js APIs (require, __dirname, process, console).
|
|
8
|
-
*
|
|
9
|
-
* Automatically scans locale directories and generates index.ts files
|
|
10
|
-
* that import all .json translation files.
|
|
11
|
-
*
|
|
12
|
-
* Features:
|
|
13
|
-
* - Dynamic JSON file detection (no hardcoded mappings)
|
|
14
|
-
* - Nested namespace structure for better organization
|
|
15
|
-
* - Supports all languages automatically
|
|
16
|
-
* - Clean, maintainable output
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* npm run localization:create-loaders # Generate all
|
|
20
|
-
* node scripts/createLocaleLoaders.js en-US # Generate single language
|
|
21
|
-
*
|
|
22
|
-
* Factory-First: This script is auto-copied to all generated apps
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const fs = require('fs');
|
|
26
|
-
const path = require('path');
|
|
27
|
-
|
|
28
|
-
// Get the locales directory (works from scripts/ or root)
|
|
29
|
-
const getLocalesDir = () => {
|
|
30
|
-
const possiblePaths = [
|
|
31
|
-
path.join(__dirname, '../locales'), // From scripts/
|
|
32
|
-
path.join(__dirname, 'domains/localization/infrastructure/locales'), // From root
|
|
33
|
-
path.join(process.cwd(), 'domains/localization/infrastructure/locales'),
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
for (const p of possiblePaths) {
|
|
37
|
-
if (fs.existsSync(p)) {
|
|
38
|
-
return p;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
throw new Error('Could not find locales directory');
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const localesDir = getLocalesDir();
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get all language directories dynamically
|
|
49
|
-
*/
|
|
50
|
-
function getLanguageDirectories() {
|
|
51
|
-
return fs
|
|
52
|
-
.readdirSync(localesDir)
|
|
53
|
-
.filter(item => {
|
|
54
|
-
const itemPath = path.join(localesDir, item);
|
|
55
|
-
return fs.statSync(itemPath).isDirectory() && item.match(/^[a-z]{2}-[A-Z]{2}$/);
|
|
56
|
-
})
|
|
57
|
-
.sort();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Create auto-loader for a single language
|
|
62
|
-
*/
|
|
63
|
-
function createAutoLoader(languageCode) {
|
|
64
|
-
const languageDir = path.join(localesDir, languageCode);
|
|
65
|
-
|
|
66
|
-
// Check if directory exists
|
|
67
|
-
if (!fs.existsSync(languageDir)) {
|
|
68
|
-
console.warn(`⚠️ Language directory not found: ${languageCode}`);
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Read all JSON files in the directory
|
|
73
|
-
const files = fs
|
|
74
|
-
.readdirSync(languageDir)
|
|
75
|
-
.filter(file => file.endsWith('.json'))
|
|
76
|
-
.sort();
|
|
77
|
-
|
|
78
|
-
if (files.length === 0) {
|
|
79
|
-
console.warn(`⚠️ No JSON files found in: ${languageCode}`);
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Create import statements and namespace mapping
|
|
84
|
-
const imports = [];
|
|
85
|
-
const namespaces = [];
|
|
86
|
-
const descriptions = [];
|
|
87
|
-
|
|
88
|
-
files.forEach(file => {
|
|
89
|
-
const moduleName = file.replace('.json', '');
|
|
90
|
-
imports.push(`import ${moduleName} from './${file}';`);
|
|
91
|
-
namespaces.push(moduleName);
|
|
92
|
-
descriptions.push(` * - ${moduleName}: ${file}`);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Create the auto-loader content with nested structure
|
|
96
|
-
const content = `/**
|
|
97
|
-
* Auto-generated translation loader for ${languageCode}
|
|
98
|
-
*
|
|
99
|
-
* This file is automatically generated by:
|
|
100
|
-
* npm run localization:create-loaders
|
|
101
|
-
*
|
|
102
|
-
* DO NOT EDIT THIS FILE MANUALLY!
|
|
103
|
-
*
|
|
104
|
-
* Translation Modules:
|
|
105
|
-
${descriptions.join('\n')}
|
|
106
|
-
*
|
|
107
|
-
* Generated: ${new Date().toISOString()}
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
// Import all translation modules
|
|
111
|
-
${imports.join('\n')}
|
|
112
|
-
|
|
113
|
-
// Merge all modules into a single translation object
|
|
114
|
-
// Using nested structure for better namespace organization
|
|
115
|
-
const translations = {
|
|
116
|
-
${namespaces.join(',\n ')},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export default translations;
|
|
120
|
-
`;
|
|
121
|
-
|
|
122
|
-
// Write the index.ts file
|
|
123
|
-
const indexPath = path.join(languageDir, 'index.ts');
|
|
124
|
-
fs.writeFileSync(indexPath, content, 'utf8');
|
|
125
|
-
|
|
126
|
-
console.log(`✅ Created auto-loader: ${languageCode}/index.ts (${files.length} modules)`);
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Create auto-loaders for all languages
|
|
132
|
-
*/
|
|
133
|
-
function createAllAutoLoaders() {
|
|
134
|
-
const languages = getLanguageDirectories();
|
|
135
|
-
|
|
136
|
-
if (languages.length === 0) {
|
|
137
|
-
console.error('❌ No language directories found in:', localesDir);
|
|
138
|
-
process.exit(1);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
console.log(`\n🌍 Creating auto-loaders for ${languages.length} languages...\n`);
|
|
142
|
-
|
|
143
|
-
let successCount = 0;
|
|
144
|
-
languages.forEach(languageCode => {
|
|
145
|
-
if (createAutoLoader(languageCode)) {
|
|
146
|
-
successCount++;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
console.log(`\n✨ Successfully created ${successCount}/${languages.length} auto-loaders`);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ============================================================================
|
|
154
|
-
// CLI
|
|
155
|
-
// ============================================================================
|
|
156
|
-
|
|
157
|
-
const args = process.argv.slice(2);
|
|
158
|
-
|
|
159
|
-
if (args[0] === 'all' || args.length === 0) {
|
|
160
|
-
createAllAutoLoaders();
|
|
161
|
-
} else if (args[0]) {
|
|
162
|
-
// Single language
|
|
163
|
-
const languageCode = args[0];
|
|
164
|
-
if (createAutoLoader(languageCode)) {
|
|
165
|
-
console.log(`\n✨ Done!`);
|
|
166
|
-
} else {
|
|
167
|
-
console.error(`\n❌ Failed to create auto-loader for: ${languageCode}`);
|
|
168
|
-
process.exit(1);
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
console.log('Usage: node createLocaleLoaders.js [language-code|all]');
|
|
172
|
-
console.log('\nExamples:');
|
|
173
|
-
console.log(' node createLocaleLoaders.js # Generate all');
|
|
174
|
-
console.log(' node createLocaleLoaders.js all # Generate all');
|
|
175
|
-
console.log(' node createLocaleLoaders.js en-US # Generate single language');
|
|
176
|
-
console.log(' node createLocaleLoaders.js tr-TR # Generate single language');
|
|
177
|
-
}
|