@@ -3,23 +3,37 @@ import fs from 'fs';
33import i18next from 'i18next' ;
44import path from 'path' ;
55
6- const __dirname = path . resolve ( process . cwd ( ) , 'src' , 'utils' ) ;
6+ const distPath = path . resolve ( process . cwd ( ) , 'dist' , 'translations' ) ;
7+ const srcPath = path . resolve ( process . cwd ( ) , 'src' , 'utils' , 'translations' ) ;
8+
9+ let translationsPath ;
10+
11+ if ( fs . existsSync ( distPath ) ) {
12+ translationsPath = distPath ;
13+ } else if ( fs . existsSync ( srcPath ) ) {
14+ translationsPath = srcPath ;
15+ } else {
16+ console . error ( 'Translations directory not found in dist or src.' ) ;
17+ // Fallback to a non-existent path or handle error appropriately
18+ translationsPath = '' ;
19+ }
720
821const languages = [ 'en' , 'pt-BR' , 'es' ] ;
9- const translationsPath = path . join ( __dirname , 'translations' ) ;
1022const configService : ConfigService = new ConfigService ( ) ;
1123
1224const resources : any = { } ;
1325
14- languages . forEach ( ( language ) => {
15- const languagePath = path . join ( translationsPath , `${ language } .json` ) ;
16- if ( fs . existsSync ( languagePath ) ) {
17- const translationContent = fs . readFileSync ( languagePath , 'utf8' ) ;
18- resources [ language ] = {
19- translation : JSON . parse ( translationContent ) ,
20- } ;
21- }
22- } ) ;
26+ if ( translationsPath ) {
27+ languages . forEach ( ( language ) => {
28+ const languagePath = path . join ( translationsPath , `${ language } .json` ) ;
29+ if ( fs . existsSync ( languagePath ) ) {
30+ const translationContent = fs . readFileSync ( languagePath , 'utf8' ) ;
31+ resources [ language ] = {
32+ translation : JSON . parse ( translationContent ) ,
33+ } ;
34+ }
35+ } ) ;
36+ }
2337
2438i18next . init ( {
2539 resources,
0 commit comments