From 0e45aa664dd073ae6429808aab81f0449bbf568a Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Tue, 24 Apr 2018 18:02:29 +0200 Subject: [PATCH] Finished and polished the Language Panel --- locales/en-US.yml | 7 +++-- .../bskyblock/managers/LocalesManager.java | 4 +++ .../bskyblock/panels/LanguagePanel.java | 26 +++++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index f7b116dfc..4fe72837d 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -259,11 +259,14 @@ protection: &7Allowed for: &f[rank] help-item: name: "&aNeed some help?" - - island: locked: "&cThis island is locked!" +language: + panel-title: "Select your language" + selected: "&aCurrently selected." + edited: "&aEdited your language to &e[lang]&a." + new-island: sign: line0: "&1%bsb_plugin_name%" diff --git a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java index 69e28245b..14af34edd 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java @@ -43,6 +43,10 @@ public class LocalesManager { if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) { return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference); } + // Or try in the en-US locale + if (languages.get(Locale.forLanguageTag("en-US")).contains(reference)) { + return languages.get(Locale.forLanguageTag("en-US")).get(reference); + } return null; } diff --git a/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java b/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java index cd4181979..d26821f7e 100644 --- a/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java +++ b/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java @@ -18,20 +18,20 @@ public class LanguagePanel { */ public static void openPanel(User user) { PanelBuilder panelBuilder = new PanelBuilder() - .name(user.getTranslation("languages.panel.title")); + .name(user.getTranslation("language.panel-title")); for (Locale locale : BSkyBlock.getInstance().getLocalesManager().getAvailableLocales()) { PanelItemBuilder localeIcon = new PanelItemBuilder().icon(BSkyBlock.getInstance().getLocalesManager().getLanguages().get(locale).getBanner()) - .name("languages." + locale.toLanguageTag() + ".name") + .name(fancyLocaleDisplayName(user, locale)) .clickHandler((u, click) -> { BSkyBlock.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag()); - u.sendMessage("language.changed"); - u.closeInventory(); + u.sendMessage("language.edited", "[lang]", fancyLocaleDisplayName(u, locale)); + openPanel(u); return true; }); if (user.getLocale().toLanguageTag().equals(locale.toLanguageTag())) { - localeIcon.description("language.already-selected"); + localeIcon.description(user.getTranslation("language.selected")); } panelBuilder.item(localeIcon.build()); @@ -39,4 +39,20 @@ public class LanguagePanel { panelBuilder.build().open(user); } + + /** + * Returns a properly capitalized String based on locale's display name from user's current locale. + * @param user - the User + * @param locale - the Locale to get the display name from + * @return properly capitalized String of the locale's display name in user's current locale + */ + private static String fancyLocaleDisplayName(User user, Locale locale) { + // Get the display name of the locale based on current user's locale + String localeDisplayName = locale.getDisplayName(user.getLocale()); + + // Set the first letter to an uppercase, to make it nice and fancy :D + localeDisplayName = localeDisplayName.substring(0,1).toUpperCase() + localeDisplayName.substring(1); + + return localeDisplayName; + } }