Skip to content

Commit bf0cb6c

Browse files
committed
refactor(scripts): rename validation scripts from locales to translations
- Rename validate-locales-refs.mjs to validate-translations-refs.mjs - Rename validate-locales-structure.mjs to validate-translations-structure.mjs - Align script names with new translations directory structure
1 parent d9bd698 commit bf0cb6c

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

scripts/validate/validate-locales-refs.mjs renamed to scripts/validate/validate-translations-refs.mjs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
/**
4-
* Validates i18n reference syntax in locale files
4+
* Validates i18n reference syntax in translation files
55
*
66
* This script checks:
77
* 1. All @:path references point to valid paths
@@ -20,22 +20,22 @@ import { extractReferences, getValueByPath, resolveReference } from '../../src/i
2020
const __filename = fileURLToPath(import.meta.url)
2121
const __dirname = path.dirname(__filename)
2222
const rootDir = path.join(__dirname, '../..')
23-
const localesDir = path.join(rootDir, 'locales')
23+
const translationsDir = path.join(rootDir, 'translations')
2424

2525
/**
26-
* Discover all available locales by scanning the locales directory
27-
* A locale is valid if:
26+
* Discover all available translations by scanning the translations directory
27+
* A translation is valid if:
2828
* 1. It's a directory (not a file)
2929
* 2. It's not in the exclude list (e.g., _archive)
3030
* 3. It contains an index.ts file
3131
* @returns {string[]} - Array of locale codes
3232
*/
3333
function discoverLocales() {
34-
if (!fs.existsSync(localesDir)) {
35-
throw new Error(`Locales directory not found: ${localesDir}`)
34+
if (!fs.existsSync(translationsDir)) {
35+
throw new Error(`Translations directory not found: ${translationsDir}`)
3636
}
3737

38-
const entries = fs.readdirSync(localesDir, { withFileTypes: true })
38+
const entries = fs.readdirSync(translationsDir, { withFileTypes: true })
3939
const locales = []
4040

4141
for (const entry of entries) {
@@ -51,8 +51,8 @@ function discoverLocales() {
5151
continue
5252
}
5353

54-
// Check if it's a valid locale directory (has index.ts)
55-
const indexPath = path.join(localesDir, localeName, 'index.ts')
54+
// Check if it's a valid translation directory (has index.ts)
55+
const indexPath = path.join(translationsDir, localeName, 'index.ts')
5656
if (fs.existsSync(indexPath)) {
5757
locales.push(localeName)
5858
}
@@ -62,7 +62,7 @@ function discoverLocales() {
6262
return locales.sort()
6363
}
6464

65-
// Discover locales dynamically
65+
// Discover translations dynamically
6666
const LOCALES = discoverLocales()
6767

6868
/**
@@ -87,16 +87,16 @@ function toCamelCase(filename) {
8787
}
8888

8989
/**
90-
* Load messages from a locale by dynamically reading JSON files
91-
* This mimics the structure in locales/{locale}/index.ts
90+
* Load messages from a translation by dynamically reading JSON files
91+
* This mimics the structure in translations/{locale}/index.ts
9292
* @param {string} locale - The locale code
9393
* @returns {{messages: Record<string, unknown>, fileMap: Map<string, string>}} - The messages object and file mapping
9494
*/
9595
function loadMessages(locale) {
96-
const localeDir = path.join(localesDir, locale)
96+
const localeDir = path.join(translationsDir, locale)
9797

9898
if (!fs.existsSync(localeDir)) {
99-
throw new Error(`Locale directory not found: ${localeDir}`)
99+
throw new Error(`Translation directory not found: ${localeDir}`)
100100
}
101101

102102
const messages = {}
@@ -309,7 +309,7 @@ function findSimilarPaths(targetPath, messages, maxSuggestions = 3) {
309309
}
310310

311311
/**
312-
* Validate references in a locale
312+
* Validate references in a translation
313313
* @param {string} locale - The locale code
314314
* @returns {{errors: Array<{path: string, filePath: string, message: string, suggestion?: string}>, warnings: Array<{path: string, filePath: string, message: string}>}}
315315
*/
@@ -368,12 +368,12 @@ function validateLocale(locale) {
368368
} catch (_error) {
369369
// Path doesn't exist or is invalid
370370
const similarPaths = findSimilarPaths(ref.path, messages, 3)
371-
let suggestion = `The path "${ref.path}" does not exist in the locale messages.`
371+
let suggestion = `The path "${ref.path}" does not exist in the translation messages.`
372372

373373
if (similarPaths.length > 0) {
374374
suggestion += `\n Did you mean one of these?\n${similarPaths.map(p => ` • ${p}`).join('\n')}`
375375
} else {
376-
suggestion += `\n Check that the path is correct and the referenced key exists in your locale files.`
376+
suggestion += `\n Check that the path is correct and the referenced key exists in your translation files.`
377377
}
378378

379379
errors.push({
@@ -434,16 +434,16 @@ function validateLocale(locale) {
434434
filePath: 'unknown',
435435
message: `Resolution error`,
436436
details: `Failed to resolve references: ${error.message}`,
437-
suggestion: `Check for syntax errors or circular references in your locale files.`,
437+
suggestion: `Check for syntax errors or circular references in your translation files.`,
438438
})
439439
}
440440
} catch (error) {
441441
errors.push({
442442
path: 'root',
443443
filePath: 'unknown',
444444
message: `Load error`,
445-
details: `Failed to load locale ${locale}: ${error.message}`,
446-
suggestion: `Check that the locale directory exists and all JSON files are valid.`,
445+
details: `Failed to load translation ${locale}: ${error.message}`,
446+
suggestion: `Check that the translation directory exists and all JSON files are valid.`,
447447
})
448448
}
449449

@@ -469,14 +469,14 @@ function formatFilePath(filePath) {
469469
* Main validation function
470470
*/
471471
function main() {
472-
console.log('🔍 Validating i18n reference syntax in locale files...\n')
472+
console.log('🔍 Validating i18n reference syntax in translation files...\n')
473473

474474
let totalErrors = 0
475475
let totalWarnings = 0
476476
const localeResults = []
477477

478478
for (const locale of LOCALES) {
479-
console.log(`\n📂 Checking locale: ${locale}`)
479+
console.log(`\n📂 Checking translation: ${locale}`)
480480
const result = validateLocale(locale)
481481
localeResults.push({ locale, ...result })
482482

@@ -522,7 +522,7 @@ function main() {
522522
// Summary
523523
console.log(`\n${'='.repeat(70)}`)
524524
console.log('📊 Summary:')
525-
console.log(` Locales checked: ${LOCALES.length}`)
525+
console.log(` Translations checked: ${LOCALES.length}`)
526526
console.log(` Total errors: ${totalErrors}`)
527527
console.log(` Total warnings: ${totalWarnings}`)
528528
console.log('='.repeat(70))

scripts/validate/validate-locales-structure.mjs renamed to scripts/validate/validate-translations-structure.mjs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
22

33
/**
4-
* Validates that all locale structures are identical
4+
* Validates that all translation structures are identical
55
*
66
* This script checks:
7-
* 1. All locales have the same file structure (same JSON files)
7+
* 1. All translations have the same file structure (same JSON files)
88
* 2. All JSON files have the same key structure (same nested keys)
9-
* 3. Reports any structural differences between locales
9+
* 3. Reports any structural differences between translations
1010
*/
1111

1212
import fs from 'node:fs'
@@ -16,18 +16,18 @@ import { fileURLToPath } from 'node:url'
1616
const __filename = fileURLToPath(import.meta.url)
1717
const __dirname = path.dirname(__filename)
1818
const rootDir = path.join(__dirname, '../..')
19-
const localesDir = path.join(rootDir, 'locales')
19+
const translationsDir = path.join(rootDir, 'translations')
2020

2121
/**
22-
* Discover all available locales by scanning the locales directory
22+
* Discover all available translations by scanning the translations directory
2323
* @returns {string[]} - Array of locale codes
2424
*/
2525
function discoverLocales() {
26-
if (!fs.existsSync(localesDir)) {
27-
throw new Error(`Locales directory not found: ${localesDir}`)
26+
if (!fs.existsSync(translationsDir)) {
27+
throw new Error(`Translations directory not found: ${translationsDir}`)
2828
}
2929

30-
const entries = fs.readdirSync(localesDir, { withFileTypes: true })
30+
const entries = fs.readdirSync(translationsDir, { withFileTypes: true })
3131
const locales = []
3232

3333
for (const entry of entries) {
@@ -43,8 +43,8 @@ function discoverLocales() {
4343
continue
4444
}
4545

46-
// Check if it's a valid locale directory (has index.ts)
47-
const indexPath = path.join(localesDir, localeName, 'index.ts')
46+
// Check if it's a valid translation directory (has index.ts)
47+
const indexPath = path.join(translationsDir, localeName, 'index.ts')
4848
if (fs.existsSync(indexPath)) {
4949
locales.push(localeName)
5050
}
@@ -89,17 +89,17 @@ function collectKeys(obj, prefix, keys) {
8989
}
9090

9191
/**
92-
* Get the structure of a locale (files and keys)
92+
* Get the structure of a translation (files and keys)
9393
* @param {string} locale - The locale code
9494
* @returns {{files: Map<string, Set<string>>, fileList: string[]}} - Structure information
9595
*/
9696
function getLocaleStructure(locale) {
97-
const localeDir = path.join(localesDir, locale)
97+
const localeDir = path.join(translationsDir, locale)
9898
const files = new Map()
9999
const fileList = []
100100

101101
if (!fs.existsSync(localeDir)) {
102-
throw new Error(`Locale directory not found: ${localeDir}`)
102+
throw new Error(`Translation directory not found: ${localeDir}`)
103103
}
104104

105105
/**
@@ -178,23 +178,23 @@ function compareSets(set1, set2) {
178178
* Main validation function
179179
*/
180180
function main() {
181-
console.log('🔍 Validating locale structures...\n')
181+
console.log('🔍 Validating translation structures...\n')
182182

183183
const locales = discoverLocales()
184184

185185
if (locales.length === 0) {
186-
console.error('❌ No locales found!')
186+
console.error('❌ No translations found!')
187187
process.exit(1)
188188
}
189189

190190
if (locales.length === 1) {
191-
console.log(`⚠️ Only one locale found (${locales[0]}), nothing to compare.`)
191+
console.log(`⚠️ Only one translation found (${locales[0]}), nothing to compare.`)
192192
process.exit(0)
193193
}
194194

195-
console.log(`Found ${locales.length} locales: ${locales.join(', ')}\n`)
195+
console.log(`Found ${locales.length} translations: ${locales.join(', ')}\n`)
196196

197-
// Get structure for each locale
197+
// Get structure for each translation
198198
const structures = new Map()
199199
let hasErrors = false
200200

@@ -212,15 +212,15 @@ function main() {
212212
process.exit(1)
213213
}
214214

215-
// Use the first locale as reference
215+
// Use the first translation as reference
216216
const referenceLocale = locales[0]
217217
const referenceStructure = structures.get(referenceLocale)
218218

219219
console.log(`Using ${referenceLocale} as reference structure\n`)
220220

221221
const errors = []
222222

223-
// Compare each locale with the reference
223+
// Compare each translation with the reference
224224
for (let i = 1; i < locales.length; i++) {
225225
const locale = locales[i]
226226
const structure = structures.get(locale)
@@ -290,7 +290,7 @@ function main() {
290290
console.error('❌ Structure differences found:\n')
291291

292292
for (const error of errors) {
293-
console.error(`📂 Locale: ${error.locale}`)
293+
console.error(`📂 Translation: ${error.locale}`)
294294

295295
if (error.type === 'file_list') {
296296
console.error(' Type: File list mismatch')
@@ -331,16 +331,16 @@ function main() {
331331
}
332332

333333
console.error('='.repeat(70))
334-
console.error('❌ Validation failed! Locale structures are not identical.')
334+
console.error('❌ Validation failed! Translation structures are not identical.')
335335
console.error('='.repeat(70))
336336
process.exit(1)
337337
}
338338

339339
// Success
340340
console.log('='.repeat(70))
341-
console.log('✅ All locale structures are identical!')
341+
console.log('✅ All translation structures are identical!')
342342
console.log('='.repeat(70))
343-
console.log(`\nChecked ${locales.length} locales:`)
343+
console.log(`\nChecked ${locales.length} translations:`)
344344
locales.forEach(locale => {
345345
const structure = structures.get(locale)
346346
console.log(` • ${locale}: ${structure.fileList.length} files`)

0 commit comments

Comments
 (0)