File tree 7 files changed +17
-22
lines changed
7 files changed +17
-22
lines changed Original file line number Diff line number Diff line change 21
21
import org .jackhuang .hmcl .Metadata ;
22
22
import org .jackhuang .hmcl .util .InvocationDispatcher ;
23
23
import org .jackhuang .hmcl .util .Lang ;
24
+ import org .jackhuang .hmcl .util .i18n .I18n ;
24
25
import org .jackhuang .hmcl .util .io .FileUtils ;
25
26
import org .jackhuang .hmcl .util .io .JarUtils ;
26
27
import org .jackhuang .hmcl .util .platform .OperatingSystem ;
27
28
28
29
import java .io .IOException ;
29
30
import java .nio .file .*;
31
+ import java .util .Locale ;
30
32
import java .util .logging .Level ;
31
33
32
34
import static org .jackhuang .hmcl .util .Logging .LOG ;
@@ -87,6 +89,8 @@ public static void init() throws IOException {
87
89
globalConfigInstance = loadGlobalConfig ();
88
90
globalConfigInstance .addListener (source -> markGlobalConfigDirty ());
89
91
92
+ Locale .setDefault (config ().getLocalization ().getLocale ());
93
+ I18n .setLocale (configInstance .getLocalization ());
90
94
Settings .init ();
91
95
92
96
if (newlyCreated ) {
Original file line number Diff line number Diff line change 24
24
import org .jackhuang .hmcl .util .CacheRepository ;
25
25
import org .jackhuang .hmcl .util .io .FileUtils ;
26
26
27
- import java .util .Locale ;
28
-
29
27
import static org .jackhuang .hmcl .setting .ConfigHolder .config ;
30
28
31
29
public final class Settings {
@@ -47,9 +45,6 @@ static void init() {
47
45
}
48
46
49
47
private Settings () {
50
- config ().localizationProperty ().addListener (unused -> updateSystemLocale ());
51
- updateSystemLocale ();
52
-
53
48
DownloadProviders .init ();
54
49
ProxyManager .init ();
55
50
Accounts .init ();
@@ -81,8 +76,4 @@ public String getCommonDirectory() {
81
76
return null ;
82
77
}
83
78
}
84
-
85
- private static void updateSystemLocale () {
86
- Locale .setDefault (config ().getLocalization ().getLocale ());
87
- }
88
79
}
Original file line number Diff line number Diff line change 37
37
import org .jackhuang .hmcl .ui .construct .ComponentList ;
38
38
import org .jackhuang .hmcl .ui .construct .ComponentSublist ;
39
39
import org .jackhuang .hmcl .ui .construct .MultiFileItem ;
40
+ import org .jackhuang .hmcl .util .i18n .I18n ;
40
41
import org .jackhuang .hmcl .util .i18n .Locales .SupportedLocale ;
41
42
42
43
import java .util .Arrays ;
@@ -176,8 +177,8 @@ public SettingsView() {
176
177
languagePane .setLeft (left );
177
178
178
179
cboLanguage = new JFXComboBox <>();
179
- cboLanguage .setConverter (stringConverter (locale -> locale .getName (config (). getLocalization ().getResourceBundle ())));
180
- FXUtils .setLimitWidth (cboLanguage , 400 );
180
+ cboLanguage .setConverter (stringConverter (locale -> locale .getName (I18n . getCurrentLocale ().getResourceBundle ())));
181
+ FXUtils .setLimitWidth (cboLanguage , 300 );
181
182
languagePane .setRight (cboLanguage );
182
183
183
184
settingsPane .getContent ().add (languagePane );
Original file line number Diff line number Diff line change 17
17
*/
18
18
package org .jackhuang .hmcl .util .i18n ;
19
19
20
- import org .jackhuang .hmcl .setting .ConfigHolder ;
21
20
import org .jackhuang .hmcl .util .i18n .Locales .SupportedLocale ;
22
21
23
22
import java .time .Instant ;
@@ -34,14 +33,14 @@ public final class I18n {
34
33
private I18n () {
35
34
}
36
35
36
+ private static volatile SupportedLocale locale = Locales .DEFAULT ;
37
+
38
+ public static void setLocale (SupportedLocale locale ) {
39
+ I18n .locale = locale ;
40
+ }
41
+
37
42
public static SupportedLocale getCurrentLocale () {
38
- try {
39
- return ConfigHolder .config ().getLocalization ();
40
- } catch (IllegalStateException e ) {
41
- // e is thrown by ConfigHolder.config(), indicating the config hasn't been loaded
42
- // fallback to use default locale
43
- return Locales .DEFAULT ;
44
- }
43
+ return locale ;
45
44
}
46
45
47
46
public static ResourceBundle getResourceBundle () {
Original file line number Diff line number Diff line change @@ -1118,7 +1118,7 @@ settings.launcher.download_source.auto=Auto Choose Download Mirror
1118
1118
settings.launcher.enable_game_list =Show version list in home page
1119
1119
settings.launcher.font =Font
1120
1120
settings.launcher.general =General
1121
- settings.launcher.language =Language
1121
+ settings.launcher.language =Language (applies after restart)
1122
1122
settings.launcher.launcher_log.export =Export launcher logs
1123
1123
settings.launcher.launcher_log.export.failed =Unable to export logs
1124
1124
settings.launcher.launcher_log.export.success =Logs have been exported to %s
Original file line number Diff line number Diff line change @@ -984,7 +984,7 @@ settings.launcher.download_source.auto=自動選擇下載來源
984
984
settings.launcher.enable_game_list =在首頁內顯示遊戲列表
985
985
settings.launcher.font =字體
986
986
settings.launcher.general =通用
987
- settings.launcher.language =語言
987
+ settings.launcher.language =語言 (重啟後生效)
988
988
settings.launcher.launcher_log.export =匯出啟動器日誌
989
989
settings.launcher.launcher_log.export.failed =無法匯出日誌
990
990
settings.launcher.launcher_log.export.success =日誌已儲存到 %s
Original file line number Diff line number Diff line change @@ -992,7 +992,7 @@ settings.launcher.download_source.auto=自动选择下载源
992
992
settings.launcher.enable_game_list =在主页内显示版本列表
993
993
settings.launcher.font =字体
994
994
settings.launcher.general =通用
995
- settings.launcher.language =语言
995
+ settings.launcher.language =语言 (重启后生效)
996
996
settings.launcher.launcher_log.export =导出启动器日志
997
997
settings.launcher.launcher_log.export.failed =无法导出日志
998
998
settings.launcher.launcher_log.export.success =日志已保存到 %s
You can’t perform that action at this time.
0 commit comments