mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-17 15:57:18 -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();
|
public static final Path CONFIG_PATH = Paths.get(CONFIG_FILENAME).toAbsolutePath();
|
||||||
|
|
||||||
private static Config configInstance;
|
private static Config configInstance;
|
||||||
private static boolean initialized;
|
|
||||||
private static boolean newlyCreated;
|
private static boolean newlyCreated;
|
||||||
|
|
||||||
public static Config config() {
|
public static Config config() {
|
||||||
@ -48,10 +47,6 @@ public final class ConfigHolder {
|
|||||||
return configInstance;
|
return configInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInitialized() {
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNewlyCreated() {
|
public static boolean isNewlyCreated() {
|
||||||
if (configInstance == null) {
|
if (configInstance == null) {
|
||||||
throw new IllegalStateException("Configuration hasn't been loaded");
|
throw new IllegalStateException("Configuration hasn't been loaded");
|
||||||
@ -72,8 +67,6 @@ public final class ConfigHolder {
|
|||||||
if (newlyCreated) {
|
if (newlyCreated) {
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Config loadConfig() {
|
private static Config loadConfig() {
|
||||||
|
@ -24,19 +24,26 @@ import java.util.ResourceBundle;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.jackhuang.hmcl.setting.ConfigHolder;
|
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||||
|
import org.jackhuang.hmcl.util.i18n.Locales.SupportedLocale;
|
||||||
|
|
||||||
public final class I18n {
|
public final class I18n {
|
||||||
|
|
||||||
private I18n() {}
|
private I18n() {}
|
||||||
|
|
||||||
public static ResourceBundle getResourceBundle() {
|
private static SupportedLocale getCurrentLocale() {
|
||||||
if (ConfigHolder.isInitialized()) {
|
try {
|
||||||
return ConfigHolder.config().getLocalization().getResourceBundle();
|
return ConfigHolder.config().getLocalization();
|
||||||
} else {
|
} catch (IllegalStateException e) {
|
||||||
return Locales.DEFAULT.getResourceBundle();
|
// 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) {
|
public static String i18n(String key, Object... formatArgs) {
|
||||||
return String.format(i18n(key), formatArgs);
|
return String.format(i18n(key), formatArgs);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user