@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "Universal localization system for React Native apps with i18n support",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -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
- // Check if en-US directory exists
80
+ // Create en-US directory if it doesn't exist
58
81
  if (!fs.existsSync(enUSDir)) {
59
- console.error("❌ en-US directory not found!");
60
- console.error(" Expected path:", enUSDir);
61
- process.exit(1);
82
+ fs.mkdirSync(enUSDir, { recursive: true });
83
+ console.log(`📁 Created directory: en-US/`);
62
84
  }
63
85
 
64
- // Automatically discover all JSON files in en-US directory
65
- const files = fs
66
- .readdirSync(enUSDir)
67
- .filter((file) => file.endsWith(".json"))
68
- .sort();
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.error(" No JSON files found in en-US directory!");
72
- process.exit(1);
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:`);