Skip to content

Commit e3db3de

Browse files
committed
fix: handle windows import paths; fixes #727
1 parent f9eae0c commit e3db3de

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: utils/getLanguage.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from 'node:fs'
22
import * as path from 'node:path'
3+
import { pathToFileURL } from 'node:url'
34

45
interface LanguageItem {
56
hint?: string
@@ -105,15 +106,20 @@ function getLocale() {
105106
return linkLocale(shellLocale.split('.')[0].replace('_', '-'))
106107
}
107108

109+
async function loadLanguageFile(filePath: string): Promise<Language> {
110+
return (await import(pathToFileURL(filePath).toString(), { with: { type: 'json' } })).default
111+
}
112+
108113
export default async function getLanguage(localesRoot: string) {
109114
const locale = getLocale()
110115

111116
const languageFilePath = path.resolve(localesRoot, `${locale}.json`)
112-
const doesLanguageExist = fs.existsSync(languageFilePath)
117+
const fallbackPath = path.resolve(localesRoot, 'en-US.json')
113118

119+
const doesLanguageExist = fs.existsSync(languageFilePath)
114120
const lang: Language = doesLanguageExist
115-
? (await import(languageFilePath, { with: { type: 'json' } })).default
116-
: (await import(path.resolve(localesRoot, 'en-US.json'), { with: { type: 'json' } })).default
121+
? await loadLanguageFile(languageFilePath)
122+
: await loadLanguageFile(fallbackPath)
117123

118124
return lang
119125
}

0 commit comments

Comments
 (0)