feat(i18n): localize internals and more
This commit is contained in:
parent
887ffaf537
commit
2fdafa225e
11 changed files with 99 additions and 24 deletions
|
@ -1,5 +1,8 @@
|
|||
package net.artelnatif.nicko;
|
||||
|
||||
import de.studiocode.invui.gui.structure.Structure;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.SimpleItem;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.artelnatif.nicko.command.NickoTabCompleter;
|
||||
|
@ -14,6 +17,7 @@ import net.artelnatif.nicko.mojang.MojangAPI;
|
|||
import net.artelnatif.nicko.pluginchannel.UpdateMessageHandler;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import net.artelnatif.nicko.utils.ServerUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -57,6 +61,10 @@ public class NickoBukkit extends JavaPlugin {
|
|||
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerQuitListener(), this);
|
||||
|
||||
getLogger().info("Setting GUI defaults...");
|
||||
Structure.addGlobalIngredient('#', new SimpleItem(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE)));
|
||||
Structure.addGlobalIngredient('%', new SimpleItem(new ItemBuilder(Material.ORANGE_STAINED_GLASS_PANE)));
|
||||
|
||||
getLogger().info("Loading persistence...");
|
||||
dataStore = new PlayerDataStore(this);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.artelnatif.nicko.disguise;
|
||||
|
||||
import io.vavr.control.Either;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -65,7 +66,7 @@ public class AppearanceManager {
|
|||
updatePlayer(true);
|
||||
}
|
||||
|
||||
public void updatePlayer(boolean skinChange) {
|
||||
NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
|
||||
public Either<String, Void> updatePlayer(boolean skinChange) {
|
||||
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.artelnatif.nicko.event;
|
|||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -17,7 +19,9 @@ public class PlayerJoinListener implements Listener {
|
|||
|
||||
if (appearanceManager.hasData()) {
|
||||
final boolean skinChange = !player.getName().equals(appearanceManager.getSkin());
|
||||
appearanceManager.updatePlayer(skinChange);
|
||||
appearanceManager.updatePlayer(skinChange).peek(unused -> player.sendMessage(I18N.translate(player, I18NDict.Event.PREVIOUS_SKIN_APPLIED.getKey()))).peekLeft(s -> {
|
||||
player.sendMessage(I18N.translate(player, s));
|
||||
});
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ public class I18N {
|
|||
|
||||
private static Locale getLocale(Player player) {
|
||||
try {
|
||||
return LocaleUtils.toLocale(player.getLocale().substring(0, 1));
|
||||
System.out.println("player.getLocale() = " + player.getLocale());
|
||||
System.out.println("player.getLocale().substring(0, 2) = " + player.getLocale().substring(0, 2));
|
||||
return LocaleUtils.toLocale(player.getLocale().substring(0, 2));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
NickoBukkit.getInstance().getLogger().severe("Invalid locale provided, defaulting to " + Locale.getDefault().getDisplayName() + ".");
|
||||
return Locale.getDefault();
|
||||
|
@ -27,9 +29,9 @@ public class I18N {
|
|||
public static String translate(Player player, String key, Object... arguments) {
|
||||
try {
|
||||
formatter.applyPattern(getBundle(player).getString(key));
|
||||
return formatter.format(arguments);
|
||||
return NickoBukkit.getInstance().getNickoConfig().getPrefix() + formatter.format(arguments);
|
||||
} catch (Exception e) {
|
||||
return key;
|
||||
return NickoBukkit.getInstance().getNickoConfig().getPrefix() + key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
public class I18NDict {
|
||||
public enum Event {
|
||||
PREVIOUS_SKIN_APPLIED("previous_skin_applied.ok"),
|
||||
PREVIOUS_SKIN_APPLY_FAIL("previous_skin_applied.fail");
|
||||
|
||||
private final String messageKey;
|
||||
|
||||
Event(String messageKey) {
|
||||
this.messageKey = "event." + messageKey;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return messageKey;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Error {
|
||||
SKIN_FAIL_MOJANG("couldnt_get_skin_from_mojang"),
|
||||
SKIN_FAIL_CACHE("couldnt_get_skin_from_cache"),
|
||||
NAME_FAIL_MOJANG("couldnt_get_name_from_mojang"),
|
||||
UNEXPECTED_ERROR("generic");
|
||||
|
||||
private final String messageKey;
|
||||
|
||||
Error(String messageKey) {
|
||||
this.messageKey = "error." + messageKey;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return messageKey;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
package net.artelnatif.nicko.impl;
|
||||
|
||||
import io.vavr.control.Either;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Internals {
|
||||
void updateSelf(Player player);
|
||||
void updateOthers(Player player);
|
||||
void updateProfile(Player player, NickoProfile profile, boolean skinChange);
|
||||
Either<String, Void> updateProfile(Player player, NickoProfile profile, boolean skinChange);
|
||||
}
|
||||
|
|
|
@ -1 +1,7 @@
|
|||
player.offline="§c{0} §fis offline, please try again."
|
||||
event.previous_skin_applied.ok=§2Applied your previous disguise back.
|
||||
event.previous_skin_applied.fail=§cFailed to apply your §2previous §cdisguise back.
|
||||
player.offline=§c{0} §fis offline, please try again.
|
||||
error.generic=§cAn unknown error occured. Please contact the developer.
|
||||
error.couldnt_get_name_from_mojang=§cFailed to get username from Mojang. Does the user exists?
|
||||
error.couldnt_get_skin_from_mojang=§cFailed to get skin from Mojang.
|
||||
error.couldnt_get_skin_from_cache=§cFailed to get skin from cache.
|
|
@ -1 +1,7 @@
|
|||
player.offline="§c{0} §fest hors-ligne, veuillez réessayer."
|
||||
event.previous_skin_applied.ok=§2Déguisement précédent appliqué.
|
||||
event.previous_skin_applied.fail=§cImpossible d'appliquer votre déguisement précédent.
|
||||
player.offline=§c{0} §fest hors-ligne, veuillez réessayer.
|
||||
error.generic=§cUne erreur inconnue est survenue. Veuillez contacter le développeur.
|
||||
error.couldnt_get_name_from_mojang=§cImpossible de récupérer le nom d'utilisateur depuis Mojang. Cet utilisateur existe-il?
|
||||
error.couldnt_get_skin_from_mojang=§cImpossible de récupérer le skin depuis Mojang.
|
||||
error.couldnt_get_skin_from_cache=§cImpossible de récupérer le skin depuis le cache.
|
Loading…
Add table
Add a link
Reference in a new issue