Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e3db3de

Browse filesBrowse files
committed
fix: handle windows import paths; fixes #727
1 parent f9eae0c commit e3db3de
Copy full SHA for e3db3de

File tree

1 file changed

+9
-3
lines changed
Filter options

1 file changed

+9
-3
lines changed

‎utils/getLanguage.ts

Copy file name to clipboardExpand all lines: utils/getLanguage.ts
+9-3Lines changed: 9 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.