mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 23:37:14 -04:00
Use configured locale as soon as possible
This commit is contained in:
parent
d9aeb0cc2b
commit
add00ddba1
@ -38,7 +38,6 @@ public final class ConfigHolder {
|
||||
public static final Path CONFIG_PATH = Paths.get(CONFIG_FILENAME).toAbsolutePath();
|
||||
|
||||
private static Config configInstance;
|
||||
private static boolean initialized;
|
||||
private static boolean newlyCreated;
|
||||
|
||||
public static Config config() {
|
||||
@ -48,10 +47,6 @@ public final class ConfigHolder {
|
||||
return configInstance;
|
||||
}
|
||||
|
||||
public static boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static boolean isNewlyCreated() {
|
||||
if (configInstance == null) {
|
||||
throw new IllegalStateException("Configuration hasn't been loaded");
|
||||
@ -72,8 +67,6 @@ public final class ConfigHolder {
|
||||
if (newlyCreated) {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private static Config loadConfig() {
|
||||
|
@ -24,19 +24,26 @@ import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||
import org.jackhuang.hmcl.util.i18n.Locales.SupportedLocale;
|
||||
|
||||
public final class I18n {
|
||||
|
||||
private I18n() {}
|
||||
|
||||
public static ResourceBundle getResourceBundle() {
|
||||
if (ConfigHolder.isInitialized()) {
|
||||
return ConfigHolder.config().getLocalization().getResourceBundle();
|
||||
} else {
|
||||
return Locales.DEFAULT.getResourceBundle();
|
||||
private static SupportedLocale getCurrentLocale() {
|
||||
try {
|
||||
return ConfigHolder.config().getLocalization();
|
||||
} catch (IllegalStateException e) {
|
||||
// e is thrown by ConfigHolder.config(), indicating the config hasn't been loaded
|
||||
// fallback to use default locale
|
||||
return Locales.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
public static ResourceBundle getResourceBundle() {
|
||||
return getCurrentLocale().getResourceBundle();
|
||||
}
|
||||
|
||||
public static String i18n(String key, Object... formatArgs) {
|
||||
return String.format(i18n(key), formatArgs);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user