1- const fs = require ( 'fs' ) ;
2- const path = require ( ' path' ) ;
1+ const fs = require ( "fs" ) ;
2+ const path = require ( " path" ) ;
33
4- const MESSAGES_DIR = path . join ( __dirname , ' ../messages' ) ;
5- const EN_FILE = path . join ( MESSAGES_DIR , ' en.json' ) ;
6- const OTHER_LOCALES = [ ' es.json' , ' tl.json' ] ;
4+ const MESSAGES_DIR = path . join ( __dirname , " ../messages" ) ;
5+ const EN_FILE = path . join ( MESSAGES_DIR , " en.json" ) ;
6+ const OTHER_LOCALES = [ " es.json" , " tl.json" ] ;
77
88function flattenObject ( ob ) {
99 let toReturn = { } ;
1010 for ( let i in ob ) {
1111 if ( ! ob . hasOwnProperty ( i ) ) continue ;
1212
13- if ( typeof ob [ i ] == ' object' && ob [ i ] !== null ) {
13+ if ( typeof ob [ i ] == " object" && ob [ i ] !== null ) {
1414 let flatObject = flattenObject ( ob [ i ] ) ;
1515 for ( let x in flatObject ) {
1616 if ( ! flatObject . hasOwnProperty ( x ) ) continue ;
17- toReturn [ i + '.' + x ] = flatObject [ x ] ;
17+ toReturn [ i + "." + x ] = flatObject [ x ] ;
1818 }
1919 } else {
2020 toReturn [ i ] = ob [ i ] ;
@@ -24,54 +24,56 @@ function flattenObject(ob) {
2424}
2525
2626function checkLocales ( ) {
27- console . log ( ' Checking locale drift...' ) ;
28-
27+ console . log ( " Checking locale drift..." ) ;
28+
2929 if ( ! fs . existsSync ( EN_FILE ) ) {
30- console . error ( ' Error: en.json not found' ) ;
30+ console . error ( " Error: en.json not found" ) ;
3131 process . exit ( 1 ) ;
3232 }
3333
34- const enContent = JSON . parse ( fs . readFileSync ( EN_FILE , ' utf8' ) ) ;
34+ const enContent = JSON . parse ( fs . readFileSync ( EN_FILE , " utf8" ) ) ;
3535 const enKeys = Object . keys ( flattenObject ( enContent ) ) . sort ( ) ;
36-
36+
3737 let hasErrors = false ;
3838
39- OTHER_LOCALES . forEach ( localeFile => {
39+ OTHER_LOCALES . forEach ( ( localeFile ) => {
4040 const localePath = path . join ( MESSAGES_DIR , localeFile ) ;
4141 if ( ! fs . existsSync ( localePath ) ) {
4242 console . error ( `Error: ${ localeFile } not found` ) ;
4343 hasErrors = true ;
4444 return ;
4545 }
4646
47- const localeContent = JSON . parse ( fs . readFileSync ( localePath , ' utf8' ) ) ;
47+ const localeContent = JSON . parse ( fs . readFileSync ( localePath , " utf8" ) ) ;
4848 const localeKeys = Object . keys ( flattenObject ( localeContent ) ) . sort ( ) ;
4949
50- const missingKeys = enKeys . filter ( k => ! localeKeys . includes ( k ) ) ;
51- const extraKeys = localeKeys . filter ( k => ! enKeys . includes ( k ) ) ;
50+ const missingKeys = enKeys . filter ( ( k ) => ! localeKeys . includes ( k ) ) ;
51+ const extraKeys = localeKeys . filter ( ( k ) => ! enKeys . includes ( k ) ) ;
5252
5353 if ( missingKeys . length > 0 ) {
5454 console . error ( `\n❌ [${ localeFile } ] Missing keys compared to en.json:` ) ;
55- missingKeys . forEach ( k => console . error ( ` - ${ k } ` ) ) ;
55+ missingKeys . forEach ( ( k ) => console . error ( ` - ${ k } ` ) ) ;
5656 hasErrors = true ;
5757 }
5858
5959 if ( extraKeys . length > 0 ) {
6060 console . error ( `\n❌ [${ localeFile } ] Extra keys not found in en.json:` ) ;
61- extraKeys . forEach ( k => console . error ( ` - ${ k } ` ) ) ;
61+ extraKeys . forEach ( ( k ) => console . error ( ` - ${ k } ` ) ) ;
6262 hasErrors = true ;
6363 }
64-
64+
6565 if ( missingKeys . length === 0 && extraKeys . length === 0 ) {
6666 console . log ( `✅ ${ localeFile } is in sync with en.json` ) ;
6767 }
6868 } ) ;
6969
7070 if ( hasErrors ) {
71- console . error ( '\n❌ Locale drift detected! Please ensure all locale files have the exact same keys as en.json.' ) ;
71+ console . error (
72+ "\n❌ Locale drift detected! Please ensure all locale files have the exact same keys as en.json." ,
73+ ) ;
7274 process . exit ( 1 ) ;
7375 } else {
74- console . log ( ' \n✨ All locales are perfectly in sync!' ) ;
76+ console . log ( " \n✨ All locales are perfectly in sync!" ) ;
7577 process . exit ( 0 ) ;
7678 }
7779}
0 commit comments