Finished and polished the Language Panel

This commit is contained in:
Florian CUNY 2018-04-24 18:02:29 +02:00
parent 175f832f41
commit 0e45aa664d
3 changed files with 30 additions and 7 deletions

View File

@ -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%"

View File

@ -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;
}

View File

@ -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;
}
}