mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 13:15:44 +01:00
Fix various translation issues
This commit is contained in:
parent
2c7ff2120c
commit
d7fa9e08f3
@ -48,6 +48,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -128,7 +129,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
|
||||
// deny the connection
|
||||
this.deniedAsyncLogin.add(e.getUniqueId());
|
||||
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), Locale.getDefault());
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUniqueId(), e.getName(), null);
|
||||
}
|
||||
@ -177,7 +178,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
|
||||
if (this.detectedCraftBukkitOfflineMode) {
|
||||
printCraftBukkitOfflineModeError();
|
||||
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR_CB_OFFLINE_MODE.build(), TranslationManager.parseLocale(player.getLocale(), TranslationManager.DEFAULT_LOCALE));
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR_CB_OFFLINE_MODE.build(), TranslationManager.parseLocale(player.getLocale(), Locale.getDefault()));
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
return;
|
||||
}
|
||||
@ -188,7 +189,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
|
||||
" - denying login.");
|
||||
}
|
||||
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR.build(), TranslationManager.parseLocale(player.getLocale(), TranslationManager.DEFAULT_LOCALE));
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR.build(), TranslationManager.parseLocale(player.getLocale(), Locale.getDefault()));
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
return;
|
||||
}
|
||||
@ -207,7 +208,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
|
||||
player.getUniqueId() + " - " + player.getName() + " - denying login.");
|
||||
t.printStackTrace();
|
||||
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_SETUP_ERROR.build(), TranslationManager.parseLocale(player.getLocale(), TranslationManager.DEFAULT_LOCALE));
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_SETUP_ERROR.build(), TranslationManager.parseLocale(player.getLocale(), Locale.getDefault()));
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
return;
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bungee.listeners;
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
|
||||
@ -44,6 +43,7 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BungeeConnectionListener extends AbstractConnectionListener implements Listener {
|
||||
@ -100,7 +100,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
|
||||
// there was some error loading
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
||||
// cancel the login attempt
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), Locale.getDefault());
|
||||
e.setCancelReason(BungeeComponentSerializer.get().serialize(reason));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
@ -70,29 +70,29 @@ public enum Dependency {
|
||||
ADVENTURE_PLATFORM(
|
||||
"me{}lucko",
|
||||
"adventure-platform-api",
|
||||
"4.0.0",
|
||||
"SgUP+9qpF0QogfbR7NOmXJ9zoi3gyMAAh4igc4SivO4=",
|
||||
"4.0.1",
|
||||
"ie3rz49jg5HU04mWe/f6lXjHt6L+S2SQp/x6YFbhxsc=",
|
||||
Relocation.of("adventure", "net{}kyori{}adventure")
|
||||
),
|
||||
ADVENTURE_PLATFORM_BUKKIT(
|
||||
"me{}lucko",
|
||||
"adventure-platform-bukkit",
|
||||
"4.0.0",
|
||||
"St2dvhkBLX4Wr+yZeRbICh/hlw0uhA6cfN/0Ua6YGw4=",
|
||||
"4.0.1",
|
||||
"dVbYfUJqmde8jeuTvknCL9hbzqxybal00TELTzQgLbk=",
|
||||
Relocation.of("adventure", "net{}kyori{}adventure")
|
||||
),
|
||||
ADVENTURE_PLATFORM_BUNGEECORD(
|
||||
"me{}lucko",
|
||||
"adventure-platform-bungeecord",
|
||||
"4.0.0",
|
||||
"CNvYc3//7OqEz2615Omuq0rRpORvDiy1kEJuzi0lc4Q=",
|
||||
"4.0.1",
|
||||
"4phi0TxNKVj5Lko63nlkrd5snIJcaU+cXUfAWsbCX1U=",
|
||||
Relocation.of("adventure", "net{}kyori{}adventure")
|
||||
),
|
||||
ADVENTURE_PLATFORM_SPONGEAPI(
|
||||
"me{}lucko",
|
||||
"adventure-platform-spongeapi",
|
||||
"4.0.0",
|
||||
"qVFz5oHdpiHI+KLMKSigpmu+T5nYZ25BmGYC6Imcx9A=",
|
||||
"4.0.1",
|
||||
"6fjWuZMeJ6633RKuZh6sIlMyVIzryQoewONeei2nB+4=",
|
||||
Relocation.of("adventure", "net{}kyori{}adventure")
|
||||
),
|
||||
EVENT(
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.locale;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
@ -33,12 +35,17 @@ import net.kyori.adventure.translation.TranslationRegistry;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
import net.kyori.adventure.util.UTF8ResourceBundleControl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -105,28 +112,51 @@ public class TranslationManager {
|
||||
translationFiles = Collections.emptyList();
|
||||
}
|
||||
|
||||
Map<Locale, ResourceBundle> loaded = new HashMap<>();
|
||||
for (Path translationFile : translationFiles) {
|
||||
try {
|
||||
loadCustomTranslationFile(translationFile);
|
||||
Map.Entry<Locale, ResourceBundle> result = loadCustomTranslationFile(translationFile);
|
||||
if (result != null) {
|
||||
loaded.put(result.getKey(), result.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.plugin.getLogger().warn("Error loading locale file: " + translationFile.getFileName().toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// try registering the locale without a country code - if we don't already have a registration for that
|
||||
loaded.forEach((locale, bundle) -> {
|
||||
Locale localeWithoutCountry = new Locale(locale.getLanguage());
|
||||
if (!locale.equals(localeWithoutCountry) && this.installed.add(localeWithoutCountry)) {
|
||||
this.registry.registerAll(localeWithoutCountry, bundle, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadCustomTranslationFile(Path translationFile) {
|
||||
private Map.Entry<Locale, ResourceBundle> loadCustomTranslationFile(Path translationFile) {
|
||||
String fileName = translationFile.getFileName().toString();
|
||||
String localeString = fileName.substring(0, fileName.length() - ".properties".length());
|
||||
Locale locale = parseLocale(localeString, null);
|
||||
|
||||
if (locale == null) {
|
||||
this.plugin.getLogger().warn("Unknown locale '" + localeString + "' - unable to register.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
this.registry.registerAll(locale, translationFile, true);
|
||||
PropertyResourceBundle bundle;
|
||||
try (BufferedReader reader = Files.newBufferedReader(translationFile, StandardCharsets.UTF_8)) {
|
||||
bundle = new PropertyResourceBundle(reader);
|
||||
} catch(IOException e) {
|
||||
this.plugin.getLogger().warn("Error loading locale file: " + localeString);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
this.registry.registerAll(locale, bundle, false);
|
||||
this.plugin.getLogger().info("Registered additional translations for " + locale.toString());
|
||||
this.installed.add(locale);
|
||||
return Maps.immutableEntry(locale, bundle);
|
||||
}
|
||||
|
||||
public static Locale parseLocale(String locale, Locale defaultLocale) {
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.nukkit;
|
||||
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.sender.SenderFactory;
|
||||
|
||||
@ -64,9 +63,11 @@ public class NukkitSenderFactory extends SenderFactory<LPNukkitPlugin, CommandSe
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, Component message) {
|
||||
// Fallback to legacy format
|
||||
Locale locale = TranslationManager.DEFAULT_LOCALE;
|
||||
Locale locale;
|
||||
if (sender instanceof Player) {
|
||||
locale = ((Player) sender).getLocale();
|
||||
} else {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
Component rendered = GlobalTranslator.render(message, locale);
|
||||
sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(rendered));
|
||||
|
@ -27,7 +27,6 @@ package me.lucko.luckperms.nukkit.listeners;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||
@ -48,6 +47,7 @@ import cn.nukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -99,7 +99,7 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
|
||||
// deny the connection
|
||||
this.deniedAsyncLogin.add(e.getUuid());
|
||||
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), Locale.getDefault());
|
||||
e.disAllow(LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUuid(), e.getName(), null);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ package me.lucko.luckperms.sponge.listeners;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
@ -45,6 +44,7 @@ import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -101,7 +101,7 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
|
||||
|
||||
e.setCancelled(true);
|
||||
e.setMessageCancelled(false);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), Locale.getDefault());
|
||||
e.setMessage(SpongeComponentSerializer.get().serialize(reason));
|
||||
this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(profile.getUniqueId(), username, null);
|
||||
}
|
||||
@ -155,7 +155,7 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
|
||||
|
||||
e.setCancelled(true);
|
||||
e.setMessageCancelled(false);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
|
||||
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR.build(), Locale.getDefault());
|
||||
e.setMessage(SpongeComponentSerializer.get().serialize(reason));
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.velocity;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.sender.SenderFactory;
|
||||
import me.lucko.luckperms.velocity.service.CompatibilityUtil;
|
||||
@ -64,9 +63,11 @@ public class VelocitySenderFactory extends SenderFactory<LPVelocityPlugin, Comma
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSource source, Component message) {
|
||||
Locale locale = TranslationManager.DEFAULT_LOCALE;
|
||||
Locale locale;
|
||||
if (source instanceof Player) {
|
||||
locale = ((Player) source).getPlayerSettings().getLocale();
|
||||
} else {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
Component rendered = GlobalTranslator.render(message, locale);
|
||||
AdventureCompat.sendMessage(source, rendered);
|
||||
|
Loading…
Reference in New Issue
Block a user