@umituz/react-native-localization 1.3.8 → 1.3.9
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 +1 -1
- package/scripts/setup-languages.js +66 -11
package/package.json
CHANGED
|
@@ -47,29 +47,84 @@ const LANGUAGES = [
|
|
|
47
47
|
"zh-TW", // Chinese Traditional
|
|
48
48
|
];
|
|
49
49
|
|
|
50
|
+
// Default translation files from package
|
|
51
|
+
const DEFAULT_FILES = [
|
|
52
|
+
'auth.json',
|
|
53
|
+
'branding.json',
|
|
54
|
+
'datetime.json',
|
|
55
|
+
'errors.json',
|
|
56
|
+
'flashcards.json',
|
|
57
|
+
'general.json',
|
|
58
|
+
'navigation.json',
|
|
59
|
+
'onboarding.json',
|
|
60
|
+
'settings.json',
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
// Get path to package's default en-US files
|
|
64
|
+
function getPackageEnUSPath() {
|
|
65
|
+
// Script is in: node_modules/@umituz/react-native-localization/scripts/setup-languages.js
|
|
66
|
+
// Package en-US is in: node_modules/@umituz/react-native-localization/src/infrastructure/locales/en-US
|
|
67
|
+
const scriptDir = __dirname;
|
|
68
|
+
const packageRoot = path.resolve(scriptDir, '..');
|
|
69
|
+
return path.join(packageRoot, 'src/infrastructure/locales/en-US');
|
|
70
|
+
}
|
|
71
|
+
|
|
50
72
|
async function setupLanguages() {
|
|
51
73
|
// Find or create project's locales directory
|
|
52
74
|
const localesDir = getLocalesDir(true); // Create if not exists
|
|
53
75
|
const enUSDir = path.join(localesDir, "en-US");
|
|
76
|
+
const packageEnUSPath = getPackageEnUSPath();
|
|
54
77
|
|
|
55
78
|
console.log("🚀 Setting up language directories and files...\n");
|
|
56
79
|
|
|
57
|
-
//
|
|
80
|
+
// Create en-US directory if it doesn't exist
|
|
58
81
|
if (!fs.existsSync(enUSDir)) {
|
|
59
|
-
|
|
60
|
-
console.
|
|
61
|
-
process.exit(1);
|
|
82
|
+
fs.mkdirSync(enUSDir, { recursive: true });
|
|
83
|
+
console.log(`📁 Created directory: en-US/`);
|
|
62
84
|
}
|
|
63
85
|
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
// Check if en-US directory has any JSON files
|
|
87
|
+
let files = [];
|
|
88
|
+
if (fs.existsSync(enUSDir)) {
|
|
89
|
+
files = fs
|
|
90
|
+
.readdirSync(enUSDir)
|
|
91
|
+
.filter((file) => file.endsWith(".json"))
|
|
92
|
+
.sort();
|
|
93
|
+
}
|
|
69
94
|
|
|
95
|
+
// If no files found, copy default files from package
|
|
70
96
|
if (files.length === 0) {
|
|
71
|
-
console.
|
|
72
|
-
|
|
97
|
+
console.log("📦 No JSON files found in en-US directory.");
|
|
98
|
+
console.log(" Copying default files from package...\n");
|
|
99
|
+
|
|
100
|
+
if (!fs.existsSync(packageEnUSPath)) {
|
|
101
|
+
console.error("❌ Package default files not found!");
|
|
102
|
+
console.error(" Expected path:", packageEnUSPath);
|
|
103
|
+
console.error(" Please ensure @umituz/react-native-localization is installed.");
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Copy default files from package
|
|
108
|
+
for (const file of DEFAULT_FILES) {
|
|
109
|
+
const packageFile = path.join(packageEnUSPath, file);
|
|
110
|
+
const targetFile = path.join(enUSDir, file);
|
|
111
|
+
|
|
112
|
+
if (fs.existsSync(packageFile)) {
|
|
113
|
+
const content = fs.readFileSync(packageFile, "utf8");
|
|
114
|
+
fs.writeFileSync(targetFile, content);
|
|
115
|
+
console.log(` 📄 Created: en-US/${file}`);
|
|
116
|
+
files.push(file);
|
|
117
|
+
} else {
|
|
118
|
+
console.warn(` ⚠️ Warning: Default file not found in package: ${file}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (files.length === 0) {
|
|
123
|
+
console.error("❌ Failed to copy default files from package!");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.log("");
|
|
73
128
|
}
|
|
74
129
|
|
|
75
130
|
console.log(`📄 Found ${files.length} translation files in en-US:`);
|