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
2020const __filename = fileURLToPath ( import . meta. url )
2121const __dirname = path . dirname ( __filename )
2222const 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 */
3333function 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
6666const 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 */
9595function 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 */
471471function 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 ) )
0 commit comments