fix: windows load locale resource, fixed #447

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-09-17 14:42:39 +08:00
parent cb9860d4b3
commit 862757a99f
2 changed files with 13 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import path from "node:path"
import { getRendererHandlers } from "@egoist/tipc/main"
import { callGlobalContextMethod } from "@shared/bridge"
import type { BrowserWindow } from "electron"
@ -202,6 +204,9 @@ export const appRoute = {
}),
getAppPath: t.procedure.action(async () => app.getAppPath()),
resolveAppAsarPath: t.procedure.input<string>().action(async ({ input }) => {
return path.resolve(app.getAppPath(), input)
}),
}
interface Sender extends Electron.WebContents {
getOwnerBrowserWindow: () => Electron.BrowserWindow | null

View File

@ -2,7 +2,7 @@ import { currentSupportedLanguages, dayjsLocaleImportMap } from "@renderer/@type
import { defaultResources } from "@renderer/@types/default-resource"
import { fallbackLanguage, i18nAtom, LocaleCache } from "@renderer/i18n"
import { jotaiStore } from "@renderer/lib/jotai"
import { isEmptyObject } from "@renderer/lib/utils"
import { getOS, isEmptyObject } from "@renderer/lib/utils"
import dayjs from "dayjs"
import i18next from "i18next"
import { toast } from "sonner"
@ -64,8 +64,13 @@ export const loadLanguageAndApply = async (lang: string) => {
let importFilePath = ""
if (window.electron) {
const electronAsarPath = await tipcClient?.getAppPath()
importFilePath = `${electronAsarPath}/dist/renderer/locales/${lang}.js`
importFilePath =
(await tipcClient?.resolveAppAsarPath(`dist/renderer/locales/${lang}.js`)) || ""
// FUCK windows
if (getOS() === "Windows") {
importFilePath = importFilePath.replaceAll("\\", "/")
}
} else {
importFilePath = `/locales/${lang}.js`
}