11import * as fs from "fs" ;
22import * as path from "path" ;
3- import { fileURLToPath } from 'url' ;
3+
44import { getDirname } from "./utils.js" ;
55
6- // const __dirname = getDirname();
7- const __filename = fileURLToPath ( import . meta. url ) ;
8- const __dirname = path . dirname ( __filename ) ;
6+ const __dirname = getDirname ( ) ;
97
108function findLocalesDir ( ) : string {
119 const cands = [
@@ -21,7 +19,7 @@ function findLocalesDir(): string {
2119 throw new Error ( "Cannot locate locales directory. Tried:\n" + cands . map ( ( p ) => " - " + p ) . join ( "\n" ) ) ;
2220}
2321
24- // const LOCALES_DIR = findLocalesDir();
22+ const LOCALES_DIR = findLocalesDir ( ) ;
2523
2624class I18nManager {
2725 private currentLocale = "en" ;
@@ -34,10 +32,8 @@ class I18nManager {
3432
3533 private loadFallback ( ) {
3634 try {
37- // const fallbackPath = path.join(LOCALES_DIR, "en.json");
38- // const fallbackData = fs.readFileSync(fallbackPath, "utf-8");
39- const fallbackPath = path . join ( __dirname , '../resources/locales/en.json' ) ;
40- const fallbackData = fs . readFileSync ( fallbackPath , 'utf-8' ) ;
35+ const fallbackPath = path . join ( LOCALES_DIR , "en.json" ) ;
36+ const fallbackData = fs . readFileSync ( fallbackPath , "utf-8" ) ;
4137 this . fallbackTranslations = JSON . parse ( fallbackData ) ;
4238 this . translations = this . fallbackTranslations ;
4339 } catch ( error ) {
@@ -56,10 +52,8 @@ class I18nManager {
5652 }
5753
5854 try {
59- // const localePath = path.join(LOCALES_DIR, `${locale}.json`);
60- // const localeData = fs.readFileSync(localePath, "utf-8");
61- const localePath = path . join ( __dirname , `../resources/locales/${ locale } .json` ) ;
62- const localeData = fs . readFileSync ( localePath , 'utf-8' ) ;
55+ const localePath = path . join ( LOCALES_DIR , `${ locale } .json` ) ;
56+ const localeData = fs . readFileSync ( localePath , "utf-8" ) ;
6357 this . translations = JSON . parse ( localeData ) ;
6458 } catch ( error ) {
6559 console . error ( `Locale '${ locale } ' not found, using English fallback` ) ;
0 commit comments