feat: rework i18n
This commit is contained in:
parent
e46647214f
commit
cefef1e213
2 changed files with 18 additions and 6 deletions
|
@ -1,14 +1,18 @@
|
|||
package net.artelnatif.nicko.disguise;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class NickoProfile implements Cloneable {
|
||||
public static final NickoProfile EMPTY_PROFILE = new NickoProfile(null, null);
|
||||
public static final NickoProfile EMPTY_PROFILE = new NickoProfile(null, null, Locale.ENGLISH);
|
||||
|
||||
private String name;
|
||||
private String skin;
|
||||
private Locale locale;
|
||||
|
||||
public NickoProfile(String name, String skin) {
|
||||
public NickoProfile(String name, String skin, Locale locale) {
|
||||
this.name = name;
|
||||
this.skin = skin;
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
@ -31,6 +35,10 @@ public class NickoProfile implements Cloneable {
|
|||
this.skin = skin;
|
||||
}
|
||||
|
||||
public Locale getLocale() { return locale; }
|
||||
|
||||
public void setLocale(Locale locale) { this.locale = locale; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NickoProfile{" +
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import org.apache.commons.lang.LocaleUtils;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class I18N {
|
||||
|
@ -13,9 +14,12 @@ public class I18N {
|
|||
|
||||
private static Locale getLocale(Player player) {
|
||||
try {
|
||||
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));
|
||||
final Optional<NickoProfile> profile = NickoBukkit.getInstance().getDataStore().getData(player.getUniqueId());
|
||||
if (profile.isEmpty()) {
|
||||
return Locale.ENGLISH;
|
||||
} else {
|
||||
return profile.get().getLocale();
|
||||
}
|
||||
} catch (IllegalArgumentException exception) {
|
||||
NickoBukkit.getInstance().getLogger().severe("Invalid locale provided, defaulting to " + Locale.getDefault().getDisplayName() + ".");
|
||||
return Locale.getDefault();
|
||||
|
|
Loading…
Reference in a new issue