feat wip(i18n): gui translation
This commit is contained in:
parent
fe78fd0e2b
commit
2ef21a796e
6 changed files with 68 additions and 7 deletions
|
@ -107,7 +107,7 @@ public class AnvilManager {
|
||||||
if (!actionResult.isError()) {
|
if (!actionResult.isError()) {
|
||||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Set.OK));
|
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Set.OK));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Set.ERROR, i18n.translateWithoutPrefix(actionResult.getErrorKey())));
|
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Set.ERROR, i18n.translatePrefixless(actionResult.getErrorKey())));
|
||||||
}
|
}
|
||||||
return Collections.singletonList(AnvilGUI.ResponseAction.close());
|
return Collections.singletonList(AnvilGUI.ResponseAction.close());
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class NickoDebugSubCmd {
|
||||||
target.playSound(target.getLocation(), Sound.ENTITY_ITEM_FRAME_PLACE, 1, 1);
|
target.playSound(target.getLocation(), Sound.ENTITY_ITEM_FRAME_PLACE, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
final I18N i18n = new I18N(target);
|
final I18N i18n = new I18N(target);
|
||||||
target.sendMessage(prefix + "§cWhoops. Something happened: " + i18n.translateWithoutPrefix(result.getErrorKey()));
|
target.sendMessage(prefix + "§cWhoops. Something happened: " + i18n.translatePrefixless(result.getErrorKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class PlayerJoinListener implements Listener {
|
||||||
if (!actionResult.isError()) {
|
if (!actionResult.isError()) {
|
||||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Restore.OK));
|
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Restore.OK));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Restore.ERROR, i18n.translateWithoutPrefix(actionResult.getErrorKey())));
|
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Restore.ERROR, i18n.translatePrefixless(actionResult.getErrorKey())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 20L);
|
}, 20L);
|
||||||
|
|
|
@ -7,6 +7,9 @@ import xyz.atnrch.nicko.appearance.AppearanceManager;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class I18N {
|
public class I18N {
|
||||||
private final MessageFormat formatter = new MessageFormat("");
|
private final MessageFormat formatter = new MessageFormat("");
|
||||||
|
@ -19,6 +22,21 @@ public class I18N {
|
||||||
this.playerLocale = getPlayerLocale();
|
this.playerLocale = getPlayerLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> translateItem(String key, Object... arguments) {
|
||||||
|
final ArrayList<String> lines = new ArrayList<>();
|
||||||
|
final String itemNameKey = readString(key + ".name");
|
||||||
|
final List<String> itemLoreKey = readString(key + ".lore");
|
||||||
|
try {
|
||||||
|
// Item Name
|
||||||
|
formatter.applyPattern(itemNameKey);
|
||||||
|
final String itemNameTranslated = formatter.format(arguments);
|
||||||
|
lines.add(itemNameTranslated);
|
||||||
|
return lines;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Collections.singletonList(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String translate(String key, Object... arguments) {
|
public String translate(String key, Object... arguments) {
|
||||||
final String string = readString(key);
|
final String string = readString(key);
|
||||||
|
|
||||||
|
@ -30,7 +48,7 @@ public class I18N {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String translateWithoutPrefix(String key, Object... arguments) {
|
public String translatePrefixless(String key, Object... arguments) {
|
||||||
final String translation = readString(key);
|
final String translation = readString(key);
|
||||||
try {
|
try {
|
||||||
formatter.applyPattern(translation);
|
formatter.applyPattern(translation);
|
||||||
|
@ -43,7 +61,20 @@ public class I18N {
|
||||||
private String readString(String key) {
|
private String readString(String key) {
|
||||||
String string;
|
String string;
|
||||||
if (playerLocale == Locale.CUSTOM) {
|
if (playerLocale == Locale.CUSTOM) {
|
||||||
string = instance.getLocaleFileManager().get(key);
|
string = instance.getLocaleFileManager().getString(key);
|
||||||
|
} else {
|
||||||
|
final InputStream resource = instance.getResource(playerLocale.getCode() + ".yml");
|
||||||
|
final YamlConfig yamlConfig = YamlConfig.load(resource);
|
||||||
|
string = yamlConfig.getString(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> readList(String key) {
|
||||||
|
String string;
|
||||||
|
if (playerLocale == Locale.CUSTOM) {
|
||||||
|
string = instance.getLocaleFileManager().getString(key);
|
||||||
} else {
|
} else {
|
||||||
final InputStream resource = instance.getResource(playerLocale.getCode() + ".yml");
|
final InputStream resource = instance.getResource(playerLocale.getCode() + ".yml");
|
||||||
final YamlConfig yamlConfig = YamlConfig.load(resource);
|
final YamlConfig yamlConfig = YamlConfig.load(resource);
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class LocaleFileManager {
|
||||||
private final File folder = new File(NickoBukkit.getInstance().getDataFolder() + "/lang/");
|
private final File folder = new File(NickoBukkit.getInstance().getDataFolder() + "/lang/");
|
||||||
private final File file = new File(folder, "lang.yml");
|
private final File file = new File(folder, "lang.yml");
|
||||||
|
|
||||||
public String get(String key) {
|
public String getString(String key) {
|
||||||
if (!file.exists()) return key;
|
if (!file.exists()) return key;
|
||||||
try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
|
try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
|
||||||
final YamlConfig yamlConfig = YamlConfig.load(inputStream);
|
final YamlConfig yamlConfig = YamlConfig.load(inputStream);
|
||||||
|
|
|
@ -23,4 +23,34 @@ event:
|
||||||
admin:
|
admin:
|
||||||
cache:
|
cache:
|
||||||
invalidate_cache: "§fCache complet invalidé."
|
invalidate_cache: "§fCache complet invalidé."
|
||||||
invalidate_entry: "§6{0} §fa été invalidé."
|
invalidate_entry: "§6{0} §fa été invalidé."
|
||||||
|
|
||||||
|
gui:
|
||||||
|
exit: "Quitter"
|
||||||
|
home:
|
||||||
|
admin:
|
||||||
|
name: "Panel d'administration"
|
||||||
|
lore:
|
||||||
|
- "Configurez et gérez Nicko."
|
||||||
|
settings:
|
||||||
|
name: "Paramètres"
|
||||||
|
lore:
|
||||||
|
- "Configurez votre expérience."
|
||||||
|
change_name:
|
||||||
|
name: "Changer le §6pseudo"
|
||||||
|
change_skin:
|
||||||
|
name: "Changer le §6skin"
|
||||||
|
change_both:
|
||||||
|
name: "Changer les §6deux"
|
||||||
|
reset:
|
||||||
|
name: "Réinitialiser l'apparence"
|
||||||
|
lore:
|
||||||
|
- "Supprime complètement votre déguisement."
|
||||||
|
settings:
|
||||||
|
language:
|
||||||
|
name: "Language"
|
||||||
|
lore:
|
||||||
|
# The language values will be filled at {0}
|
||||||
|
- "{0}"
|
||||||
|
- "§7§oParcourez les valeurs"
|
||||||
|
- "§7§oavec un clique gauche/droit."
|
Loading…
Reference in a new issue