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