3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Load localizations automatically.

Also included a sample "backwards" localization to demonstrate that it does in fact work.
Dieser Commit ist enthalten in:
Andrew Steinborn 2021-04-17 09:00:48 -04:00
Ursprung c0b6f461cb
Commit 69cba59630
5 geänderte Dateien mit 159 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -54,6 +54,7 @@ import com.velocitypowered.proxy.scheduler.VelocityScheduler;
import com.velocitypowered.proxy.server.ServerMap;
import com.velocitypowered.proxy.util.AddressUtil;
import com.velocitypowered.proxy.util.EncryptionUtils;
import com.velocitypowered.proxy.util.FileSystemUtils;
import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
import com.velocitypowered.proxy.util.bossbar.AdventureBossBarManager;
import com.velocitypowered.proxy.util.ratelimit.Ratelimiter;
@ -246,9 +247,43 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
private void registerTranslations() {
final TranslationRegistry translationRegistry = TranslationRegistry
.create(Key.key("velocity", "translations"));
translationRegistry.registerAll(Locale.US,
ResourceBundle.getBundle("com/velocitypowered/proxy/messages", Locale.US,
UTF8ResourceBundleControl.get()), false);
try {
FileSystemUtils.visitResources(VelocityServer.class,
Paths.get("com", "velocitypowered", "proxy", "l10n"), path -> {
logger.info("Loading localizations...");
try {
Files.walk(path).forEach(file -> {
if (!Files.isRegularFile(file)) {
return;
}
String filename = com.google.common.io.Files
.getNameWithoutExtension(file.getFileName().toString());
String localeName = filename.replace("messages_", "")
.replace("messages", "")
.replace('_', '-');
Locale locale;
if (localeName.isEmpty()) {
locale = Locale.US;
} else {
locale = Locale.forLanguageTag(localeName);
}
translationRegistry.registerAll(locale,
ResourceBundle.getBundle("com/velocitypowered/proxy/l10n/messages",
locale, UTF8ResourceBundleControl.get()), false);
});
} catch (IOException e) {
logger.error("Encountered an I/O error whilst loading translations", e);
System.exit(1);
}
});
} catch (IOException e) {
logger.error("Encountered an I/O error whilst loading translations", e);
System.exit(1);
return;
}
GlobalTranslator.get().addSource(translationRegistry);
}

Datei anzeigen

@ -226,8 +226,8 @@ public class VelocityCommand implements SimpleCommand {
.translatable("velocity.command.version-copyright",
Component.text(version.getVendor()),
Component.text(version.getName()));
source.sendMessage(Identity.nil(), velocity);
source.sendMessage(Identity.nil(), copyright);
source.sendMessage(velocity);
source.sendMessage(copyright);
if (version.getName().equals("Velocity")) {
TextComponent embellishment = Component.text()

Datei anzeigen

@ -0,0 +1,56 @@
package com.velocitypowered.proxy.util;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.function.Consumer;
public class FileSystemUtils {
/**
* Visits the resources at the given {@link Path} within the resource
* path of the given {@link Class}.
*
* @param target The target class of the resource path to scan
* @param path The path to scan within the resource path
* @param consumer The consumer to visit the resolved path
*/
public static boolean visitResources(Class<?> target, Path path, Consumer<Path> consumer)
throws IOException {
final File file = new File(target
.getProtectionDomain().getCodeSource().getLocation().getPath());
if (file.isFile()) { // jar
URI uri = file.toURI();
try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
Path toVisit = fileSystem.getPath(path.toString());
if (Files.exists(toVisit)) {
consumer.accept(toVisit);
return true;
}
return false;
}
} else {
URI uri;
try {
URL url = target.getClassLoader().getResource(path.toString());
if (url == null) {
return false;
}
uri = url.toURI();
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
consumer.accept(Paths.get(uri));
return true;
}
}
}

Datei anzeigen

@ -27,7 +27,7 @@ velocity.error.online-mode-only=You are not logged into your Minecraft account.
velocity.error.player-connection-error=An internal error occurred in your connection.
velocity.error.modern-forwarding-needs-new-client=This server is only compatible with Minecraft 1.13 and above.
velocity.error.modern-forwarding-failed=Your server did not send a forwarding request to the proxy. Make sure the server is configured for Velocity forwarding.
velocity.error.moved-to-new-server=YOu were kicked from {0}: {1}
velocity.error.moved-to-new-server=You were kicked from {0}: {1}
velocity.error.no-available-servers=There are no available servers to connect you to. Try again later or contact an admin.
# Commands

Datei anzeigen

@ -0,0 +1,62 @@
#
# Copyright (C) 2018 Velocity Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
velocity.error.already-connected=¡ɹǝʌɹǝs sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎpɐǝɹlɐ ǝɹɐ no⅄
velocity.error.already-connected-proxy=¡ʎxoɹd sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎpɐǝɹlɐ ǝɹɐ no⅄
velocity.error.already-connecting=¡ɹǝʌɹǝs ɐ oʇ ʇɔǝuuoɔ oʇ ƃuᴉʎɹʇ ʎpɐǝɹlɐ ǝɹɐ no⅄
velocity.error.cant-connect={1} :{0} oʇ ʇɔǝuuoɔ oʇ ǝlqɐu∩
velocity.error.connecting-server-error=˙ɹǝʇɐl uᴉɐƃɐ ʎɹʇ ǝsɐǝlԀ ˙{0} oʇ noʎ ʇɔǝuuoɔ oʇ ǝlqɐu∩
velocity.error.connected-server-error=˙ɯǝlqoɹd ɐ pǝɹǝʇunoɔuǝ {0} oʇ uoᴉʇɔǝuuoɔ ɹno⅄
velocity.error.internal-server-connection-error=˙pǝɹɹnɔɔo ɹoɹɹǝ uoᴉʇɔǝuuoɔ ɹǝʌɹǝs lɐuɹǝʇuᴉ u∀
velocity.error.logging-in-too-fast=˙ɹǝʇɐl uᴉɐƃɐ ʎɹʇ 'ʇsɐɟ ooʇ uᴉ ƃuᴉƃƃol ǝɹɐ no⅄
velocity.error.online-mode-only=˙ʇuǝᴉlɔ ʇɟɐɹɔǝuᴉW ɹnoʎ ƃuᴉʇɹɐʇsǝɹ ʎɹʇ 'ʇunoɔɔɐ ʇɟɐɹɔǝuᴉW ɹnoʎ oʇuᴉ pǝƃƃol ǝɹɐ noʎ ɟI ˙ʇunoɔɔɐ ʇɟɐɹɔǝuᴉW ɹnoʎ oʇuᴉ pǝƃƃol ʇou ǝɹɐ no⅄
velocity.error.player-connection-error=˙uoᴉʇɔǝuuoɔ ɹnoʎ uᴉ pǝɹɹnɔɔo ɹoɹɹǝ lɐuɹǝʇuᴉ u∀
velocity.error.modern-forwarding-needs-new-client=˙ǝʌoqɐ puɐ ƐƖ˙Ɩ ʇɟɐɹɔǝuᴉW ɥʇᴉʍ ǝlqᴉʇɐdɯoɔ ʎluo sᴉ ɹǝʌɹǝs sᴉɥ┴
velocity.error.modern-forwarding-failed=˙ƃuᴉpɹɐʍɹoɟ ʎʇᴉɔolǝΛ ɹoɟ pǝɹnƃᴉɟuoɔ sᴉ ɹǝʌɹǝs ǝɥʇ ǝɹns ǝʞɐW ˙ʎxoɹd ǝɥʇ oʇ ʇsǝnbǝɹ ƃuᴉpɹɐʍɹoɟ ɐ puǝs ʇou pᴉp ɹǝʌɹǝs ɹno⅄
velocity.error.moved-to-new-server={1} :{0} ɯoɹɟ pǝʞɔᴉʞ ǝɹǝʍ no⅄
velocity.error.no-available-servers=˙uᴉɯpɐ uɐ ʇɔɐʇuoɔ ɹo ɹǝʇɐl uᴉɐƃɐ ʎɹ┴ ˙oʇ noʎ ʇɔǝuuoɔ oʇ sɹǝʌɹǝs ǝlqɐlᴉɐʌɐ ou ǝɹɐ ǝɹǝɥ┴
# Commands
velocity.command.generic-error=˙puɐɯɯoɔ sᴉɥʇ ƃuᴉuunɹ ǝlᴉɥʍ pǝɹɹnɔɔo ɹoɹɹǝ u∀
velocity.command.command-does-not-exist=˙ʇsᴉxǝ ʇou sǝop puɐɯɯoɔ sᴉɥ┴
velocity.command.players-only=Only players can run this command.
velocity.command.server-does-not-exist=˙puɐɯɯoɔ sᴉɥʇ unɹ uɐɔ sɹǝʎɐld ʎluO
velocity.command.server-current-server=˙{0} oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ no⅄
velocity.command.server-too-many=˙sʇunoɔ ɹǝʌɹǝs lɐnpᴉʌᴉpuᴉ ʇǝƃ oʇ uoᴉʇǝldɯoɔ qɐʇ ǝs∩ ˙dn ʇǝs sɹǝʌɹǝs ʎuɐɯ ooʇ ǝɹɐ ǝɹǝɥ┴
velocity.command.server-available=:sɹǝʌɹǝs ǝlqɐlᴉɐʌ∀
velocity.command.server-tooltip-player-online=ǝuᴉluo ɹǝʎɐld {0}
velocity.command.server-tooltip-players-online=ǝuᴉluo sɹǝʎɐld {0}
velocity.command.server-tooltip-current-server=ɹǝʌɹǝs sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnƆ
velocity.command.server-tooltip-offer-connect-server=ɹǝʌɹǝs sᴉɥʇ oʇ ʇɔǝuuoɔ oʇ ʞɔᴉlƆ
velocity.command.glist-player-singular=ɹǝʎɐld
velocity.command.glist-player-plural=sɹǝʎɐld
velocity.command.glist-total-suffix=˙ʎxoɹd ǝɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ
velocity.command.glist-view-all=˙/glist all ǝsn 'sɹǝʌɹǝs uo sɹǝʎɐld llɐ ʍǝᴉʌ o┴
velocity.command.reload-success=˙pǝpɐolǝɹ ʎllnɟssǝɔɔns uoᴉʇɐɹnƃᴉɟuoɔ ʎʇᴉɔolǝΛ
velocity.command.reload-failure=˙slᴉɐʇǝp ǝɹoɯ ɹoɟ ǝlosuoɔ ǝɥʇ ʞɔǝɥƆ ˙uoᴉʇɐɹnƃᴉɟuoɔ ʎʇᴉɔolǝΛ ɹnoʎ pɐolǝɹ oʇ ǝlqɐu∩
velocity.command.version-copyright=˙Ɛʌ ǝsuǝɔᴉ˥ ɔᴉlqnԀ lɐɹǝuǝפ ∩Nפ ǝɥʇ ɟo sɯɹǝʇ ǝɥʇ ɹǝpun pǝsuǝɔᴉl sᴉ {1} ˙{0} Ɩᄅ0ᄅ-8Ɩ0ᄅ ʇɥƃᴉɹʎdoƆ
velocity.command.no-plugins=˙pǝllɐʇsuᴉ ʎlʇuǝɹɹnɔ suᴉƃnld ou ǝɹɐ ǝɹǝɥ┴
velocity.command.plugins-list={0}: suᴉƃnlԀ
velocity.command.plugin-tooltip-website={0}: ǝʇᴉsqǝM
velocity.command.plugin-tooltip-author={0}: ɹoɥʇn∀
velocity.command.plugin-tooltip-authors={0}: sɹoɥʇn∀