File tree Expand file tree Collapse file tree 7 files changed +33
-12
lines changed Expand file tree Collapse file tree 7 files changed +33
-12
lines changed Original file line number Diff line number Diff line change 11import i18next from "i18next" ;
2- import i18nextFsBackend , { FsBackendOptions } from "i18next-fs-backend" ;
2+ import i18nextFsBackend from "i18next-fs-backend" ;
3+ import { isDev } from "../environment-util.js" ;
4+ import { app } from "electron" ;
5+ import path from "path" ;
36
47//from https://stackoverflow.com/questions/46072248/node-js-how-to-detect-user-language
58export function getUserLocale ( ) {
@@ -20,8 +23,18 @@ const config = {
2023
2124const i18nextOptions = {
2225 backend : {
23- loadPath : "./src/locales/{{lng}}/{{ns}}.json" ,
24- addPath : "./src/locales/{{lng}}/{{ns}}.missing.json" ,
26+ loadPath : isDev ( )
27+ ? "./src/electron/resources/locales/{{lng}}/{{ns}}.json"
28+ : path . join (
29+ app . getAppPath ( ) ,
30+ "/dist-electron/resources/locales/{{lng}}/{{ns}}.json"
31+ ) ,
32+ addPath : isDev ( )
33+ ? "./src/electron/resources/locales/{{lng}}/{{ns}}.missing.json"
34+ : path . join (
35+ app . getAppPath ( ) ,
36+ "/dist-electron/resources/locales/{{lng}}/{{ns}}.missing.json"
37+ ) ,
2538 jsonIndent : 2 ,
2639 } ,
2740
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -5,11 +5,17 @@ import { StrictMode } from "react";
55import { createRoot } from "react-dom/client" ;
66import { LanguageManager } from "./utils/lang" ;
77
8- //初始化语言
9- LanguageManager . getInstance ( ) . initialize ( ) ;
10-
11- createRoot ( document . getElementById ( "root" ) ! ) . render (
12- < StrictMode >
13- < App />
14- </ StrictMode >
15- ) ;
8+ async function initialize ( ) {
9+ //初始化语言
10+ await LanguageManager . getInstance ( ) . initialize ( ) ;
11+
12+ createRoot ( document . getElementById ( "root" ) ! ) . render (
13+ < StrictMode >
14+ < App />
15+ </ StrictMode >
16+ ) ;
17+ }
18+
19+ initialize ( ) . catch ( ( error ) => {
20+ console . log ( `Failed to initialize application: ${ error } ` ) ;
21+ } ) ;
Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ export class LanguageManager {
2222 }
2323
2424 public async initialize ( ) {
25- this . fallbackLang = ( await this . initLang ( ) ) . fallbackLang ;
25+ const langInfo = await this . initLang ( ) ;
26+ this . fallbackLang = langInfo . fallbackLang ;
27+ console . log ( langInfo ) ;
2628 }
2729
2830 public static getInstance ( ) {
You can’t perform that action at this time.
0 commit comments