|
1 | 1 | import*asfsfrom'node:fs' |
2 | 2 | import*aspathfrom'node:path' |
| 3 | +import{pathToFileURL}from'node:url' |
3 | 4 |
|
4 | 5 | interfaceLanguageItem{ |
5 | 6 | hint?:string |
@@ -105,15 +106,20 @@ function getLocale() { |
105 | 106 | returnlinkLocale(shellLocale.split('.')[0].replace('_','-')) |
106 | 107 | } |
107 | 108 |
|
| 109 | +asyncfunctionloadLanguageFile(filePath:string):Promise<Language>{ |
| 110 | +return(awaitimport(pathToFileURL(filePath).toString(),{with:{type:'json'}})).default |
| 111 | +} |
| 112 | + |
108 | 113 | exportdefaultasyncfunctiongetLanguage(localesRoot:string){ |
109 | 114 | constlocale=getLocale() |
110 | 115 |
|
111 | 116 | constlanguageFilePath=path.resolve(localesRoot,`${locale}.json`) |
112 | | -constdoesLanguageExist=fs.existsSync(languageFilePath) |
| 117 | +constfallbackPath=path.resolve(localesRoot,'en-US.json') |
113 | 118 |
|
| 119 | +constdoesLanguageExist=fs.existsSync(languageFilePath) |
114 | 120 | constlang:Language=doesLanguageExist |
115 | | - ?(awaitimport(languageFilePath,{with:{type:'json'}})).default |
116 | | - :(awaitimport(path.resolve(localesRoot,'en-US.json'),{with:{type:'json'}})).default |
| 121 | + ?awaitloadLanguageFile(languageFilePath) |
| 122 | + :awaitloadLanguageFile(fallbackPath) |
117 | 123 |
|
118 | 124 | returnlang |
119 | 125 | } |