Add hard mapping to convert to AuthMe language code from locale code
This commit is contained in:
parent
2219dd55dd
commit
d09e545554
@ -8,12 +8,14 @@ import fr.xephi.authme.output.ConsoleLoggerFactory;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.util.FileUtils;
|
import fr.xephi.authme.util.FileUtils;
|
||||||
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_LANGUAGE;
|
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_LANGUAGE;
|
||||||
@ -34,7 +36,7 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
|||||||
|
|
||||||
private String filename;
|
private String filename;
|
||||||
private FileConfiguration configuration;
|
private FileConfiguration configuration;
|
||||||
private ConcurrentHashMap<String, FileConfiguration> i18nConfiguration;
|
private Map<String, FileConfiguration> i18nConfiguration;
|
||||||
private final String defaultFile;
|
private final String defaultFile;
|
||||||
|
|
||||||
protected AbstractMessageFileHandler() {
|
protected AbstractMessageFileHandler() {
|
||||||
@ -120,6 +122,8 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
|||||||
i18nConfiguration = new ConcurrentHashMap<>();
|
i18nConfiguration = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locale = PlayerUtils.LocaleToCode(locale, settings);
|
||||||
|
|
||||||
if (i18nConfiguration.containsKey(locale)) {
|
if (i18nConfiguration.containsKey(locale)) {
|
||||||
return i18nConfiguration.get(locale);
|
return i18nConfiguration.get(locale);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -65,4 +67,100 @@ public final class PlayerUtils {
|
|||||||
|
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the AuthMe messages file language code, by given locale and settings.
|
||||||
|
* Dreeam - Hard mapping, based on mc1.20.6, 5/29/2024
|
||||||
|
*
|
||||||
|
* @param locale The locale that player client setting uses.
|
||||||
|
* @param settings The AuthMe settings, for default/fallback language usage.
|
||||||
|
*/
|
||||||
|
public static String LocaleToCode(String locale, Settings settings) {
|
||||||
|
locale = locale.toLowerCase();
|
||||||
|
|
||||||
|
switch (locale) {
|
||||||
|
case "pt_br":
|
||||||
|
return "br";
|
||||||
|
case "cs_cz":
|
||||||
|
return "cz";
|
||||||
|
case "lzh":
|
||||||
|
case "zh_cn":
|
||||||
|
return "zhcn";
|
||||||
|
case "zh_hk":
|
||||||
|
return "zhhk";
|
||||||
|
case "zh_tw":
|
||||||
|
return "zhtw";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (locale.contains("_")) {
|
||||||
|
locale = locale.substring(0, locale.indexOf("_"));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (locale) {
|
||||||
|
case "en":
|
||||||
|
return "en";
|
||||||
|
case "bg":
|
||||||
|
return "bg";
|
||||||
|
case "de":
|
||||||
|
case "nds":
|
||||||
|
case "sxu":
|
||||||
|
case "swg":
|
||||||
|
return "de";
|
||||||
|
case "eo":
|
||||||
|
return "eo";
|
||||||
|
case "es":
|
||||||
|
return "es";
|
||||||
|
case "et":
|
||||||
|
return "et";
|
||||||
|
case "eu":
|
||||||
|
return "eu";
|
||||||
|
case "fi":
|
||||||
|
return "fi";
|
||||||
|
case "fr":
|
||||||
|
return "fr";
|
||||||
|
case "gl":
|
||||||
|
return "gl";
|
||||||
|
case "hu":
|
||||||
|
return "hu";
|
||||||
|
case "id":
|
||||||
|
return "id";
|
||||||
|
case "it":
|
||||||
|
return "it";
|
||||||
|
case "ja":
|
||||||
|
return "ja";
|
||||||
|
case "ko":
|
||||||
|
return "ko";
|
||||||
|
case "lt":
|
||||||
|
return "lt";
|
||||||
|
case "nl":
|
||||||
|
return "nl";
|
||||||
|
case "pl":
|
||||||
|
return "pl";
|
||||||
|
case "pt":
|
||||||
|
return "pt";
|
||||||
|
case "ro":
|
||||||
|
return "ro";
|
||||||
|
case "ru":
|
||||||
|
case "rpr":
|
||||||
|
return "ru";
|
||||||
|
case "sl":
|
||||||
|
return "si";
|
||||||
|
case "sk":
|
||||||
|
return "sk";
|
||||||
|
case "sr":
|
||||||
|
return "sr";
|
||||||
|
case "tr":
|
||||||
|
return "tr";
|
||||||
|
case "uk":
|
||||||
|
return "uk";
|
||||||
|
case "vi":
|
||||||
|
return "vn";
|
||||||
|
case "lzh":
|
||||||
|
return "zhcn";
|
||||||
|
//case "zhmc":
|
||||||
|
// return "zhmc";
|
||||||
|
default:
|
||||||
|
return settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user