11/* eslint-disable @typescript-eslint/no-var-requires */
2- const fs = require ( "fs" ) ;
3- const path = require ( "path" ) ;
4-
2+ const fs = require ( 'fs' ) ;
3+ /* eslint-disable @typescript-eslint/no-var-requires */
4+ const path = require ( 'path' ) ;
55
66const uniqueLanguages = new Set ( ) ; // Define uniqueLanguages globally or pass it as a parameter
77
8- const extractLocales = ( dir ) => {
9- const items = fs . readdirSync ( dir , { withFileTypes : true } ) ;
8+ const findAndExtractLanguages = ( dir ) => {
9+ const items = fs . readdirSync ( dir , { withFileTypes : true } ) ;
1010
11- for ( const item of items ) {
12- const fullPath = path . join ( dir , item . name ) ;
13-
14- if ( item . isDirectory ( ) ) {
15- extractLocales ( fullPath ) ; // Proper recursion
16- } else if ( item . isFile ( ) && item . name === "data.json.json" ) {
17- try {
18- const rawData = fs . readFileSync ( fullPath , "utf8" ) ;
19- const jsonData = JSON . parse ( rawData ) ;
20- const language = jsonData ?. item ?. $ ?. language ;
11+ for ( const item of items ) {
12+ const fullPath = path . join ( dir , item . name ) ;
2113
22- if ( language ) {
23- uniqueLanguages . add ( language ) ;
24- }
25- } catch ( error ) {
26- console . error ( `Error reading ${ fullPath } :` , error . message ) ;
27- }
14+ if ( item . isDirectory ( ) ) {
15+ findAndExtractLanguages ( fullPath ) ; // Proper recursion
16+ } else if ( item . isFile ( ) && item . name === 'data.json.json' ) {
17+ try {
18+ const rawData = fs . readFileSync ( fullPath , 'utf8' ) ;
19+ const jsonData = JSON . parse ( rawData ) ;
20+ const language = jsonData ?. item ?. $ ?. language ;
21+
22+ if ( language ) {
23+ uniqueLanguages . add ( language ) ;
2824 }
25+ } catch ( error ) {
26+ console . error ( `Error reading ${ fullPath } :` , error . message ) ;
27+ }
2928 }
30- return uniqueLanguages ;
29+ }
30+ return uniqueLanguages ;
3131} ;
32-
33- module . exports = extractLocales ;
32+ module . exports = findAndExtractLanguages ;
0 commit comments