refactor: fallback locale + feat: custom locale
This commit is contained in:
parent
863aa46a7b
commit
9ed076e00d
3 changed files with 18 additions and 12 deletions
|
@ -102,7 +102,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
saveDefaultConfig();
|
||||
config = new NickoConfiguration(this);
|
||||
|
||||
LocaleManager.setDefaultLocale(this);
|
||||
LocaleManager.setFallbackLocale(this);
|
||||
|
||||
final PluginCommand command = getCommand("nicko");
|
||||
if (command != null) {
|
||||
|
|
|
@ -7,20 +7,20 @@ import java.util.Arrays;
|
|||
public class LocaleManager {
|
||||
private static final String[] supportedLocales = new String[]{"en", "fr", "custom"};
|
||||
|
||||
public static void setDefaultLocale(NickoBukkit instance) {
|
||||
final String locale = instance.getNickoConfig().getDefaultLocale();
|
||||
public static void setFallbackLocale(NickoBukkit instance) {
|
||||
final String locale = instance.getNickoConfig().getFallbackLocale();
|
||||
try {
|
||||
if (Arrays.stream(supportedLocales).noneMatch(s -> s.equalsIgnoreCase(locale))) {
|
||||
instance.getLogger().severe(locale + " is not a supported locale, defaulting to English.");
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
Locale.setFallback(Locale.ENGLISH);
|
||||
return;
|
||||
}
|
||||
final Locale defaultLocale = Locale.fromCode(locale);
|
||||
instance.getLogger().info("Default locale set to " + defaultLocale.getName() + ".");
|
||||
Locale.setDefault(defaultLocale);
|
||||
instance.getLogger().info("Fallback locale set to " + defaultLocale.getName() + ".");
|
||||
Locale.setFallback(defaultLocale);
|
||||
} catch (Exception e) {
|
||||
instance.getLogger().severe(locale + " is not a valid locale, defaulting to English.");
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
Locale.setFallback(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
prefix: "§8[§6Nicko§8] "
|
||||
|
||||
bungeecord:
|
||||
# Enables Bungeecord support, switching through servers will keep player's skins.
|
||||
# Enables Bungeecord support, switching through servers will transfer player's disguise.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
enabled: false
|
||||
redis:
|
||||
|
@ -13,10 +13,16 @@ bungeecord:
|
|||
ttl: -1
|
||||
|
||||
# Localisation:
|
||||
locale:
|
||||
# By default, Nicko tries to get the locale from the player's preferences.
|
||||
# If that fails, the locale fallback is the one provided by this option.
|
||||
# Accepted values: fr (French), en (English), custom (Custom language file).
|
||||
locale: "en"
|
||||
fallback: "en"
|
||||
# Nicko will copy the English locale as "custom.yml"
|
||||
# and will use the translations in that file when "Server Custom"
|
||||
# is selected as the player's locale/default locale.
|
||||
use_custom_locale: false
|
||||
|
||||
|
||||
storage:
|
||||
# Indicates wherever the data will be stored
|
||||
|
|
Loading…
Reference in a new issue