feat: update lang command to add missing translation keys

This commit is contained in:
Sekwah 2023-04-12 12:20:48 +01:00
parent a9f2c532b8
commit 4174b59942
No known key found for this signature in database
GPG Key ID: 9E0D654FC942286D
5 changed files with 18 additions and 26 deletions

View File

@ -60,13 +60,6 @@ public class LangUpdateSubCommand implements SubCommand {
Lang.loadLanguage(configRepository.getTranslation());
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translateInsertVariables("translatedata.updated", newTranslations.size()));
/*if(!configRepository.getTranslation().equals("en_GB")) {
// Copy this just to allow people to check the new translations.
this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", "lang/en_GB-new.lang", true);
}
this.portalsCore.getDataStorage().copyDefaultFile("lang/" + configRepository.getTranslation() + ".lang", "lang/" + configRepository.getTranslation() + "-new.lang", true);
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("translatedata.replaced") + Lang.translate("translatedata.overwrite"));*/
}
}

View File

@ -7,6 +7,8 @@ import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.Lang;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ListSubCommand implements SubCommand {
@ -15,7 +17,8 @@ public class ListSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.list"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.list")
+ " " + portalServices.getPortals().asList().stream().map(Map.Entry::getKey).sorted().collect(Collectors.joining(", ")));
}
@Override

View File

@ -8,6 +8,8 @@ import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@Singleton
@ -25,7 +27,7 @@ public class PortalServices {
}
public ImmutableList<? extends Map.Entry<String, AdvancedPortal>> getPortals() {
return null;
return ImmutableList.copyOf(Collections.emptyList());
}
public boolean removePortal(String name, PlayerContainer player) {

View File

@ -1,7 +1,6 @@
package com.sekwah.advancedportals.core.util;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.data.DataStorage;
import java.io.IOException;
@ -17,19 +16,14 @@ import java.util.Scanner;
* <p>
* The language translation file for the game. Will always load english first
* so that if the translations are missing any then they are still readable and can then be translated.
* (Its better than a raw translate string)
* (It's better than a raw translate string)
* <p>
* TODO add a loaddefault where it only loads from the plugins version of the data rather than paying attention to any
* possible changed versions in the lang folder.
*/
public class Lang {
public static final Lang instance = new Lang();
private final HashMap<String, String> languageMap = new HashMap<>();
@Inject
private AdvancedPortalsCore portalsCore;
@Inject
private DataStorage dataStorage;
@ -40,14 +34,15 @@ public class Lang {
public static void loadLanguage(String fileName) {
if(!DEFAULT_LANG.equals(fileName)) {
instance.injectTranslations(instance, DEFAULT_LANG);
instance.injectTranslations(DEFAULT_LANG);
}
instance.injectTranslations(instance, fileName);
instance.injectTranslations(fileName);
}
public static String translate(String s) {
if (instance.languageMap.containsKey(s)) {
String translation = instance.languageMap.get(s);
// noinspection ALL (not sure what the specific warning is for escaped unicode)
translation = translation.replaceAll("&([0-9a-frk-o])", "\u00A7$1");
return translation;
} else {
@ -56,7 +51,7 @@ public class Lang {
}
public static String translateInsertVariables(String s, Object... args) {
String translation = instance.translate(s);
String translation = translate(s);
for (int i = 1; i <= args.length; i++) {
translation = translation.replaceAll("%" + i + "\\$s", args[i-1].toString());
}
@ -79,12 +74,12 @@ public class Lang {
return Collections.emptyMap();
}
private void injectTranslations(Lang lang, String fileName) {
private void injectTranslations(String fileName) {
try {
URL url = lang.getClass().getClassLoader().getResource("lang/" + fileName + ".lang");
URL url = Lang.instance.getClass().getClassLoader().getResource("lang/" + fileName + ".lang");
if (url != null) {
Map<String, String> initialMap = Lang.parseLang(url.openStream());
lang.languageMap.putAll(initialMap);
Lang.instance.languageMap.putAll(initialMap);
} else {
this.infoLogger.logWarning("Could not load " + fileName + ".lang from within Advanced Portals as it doesn't exist.");
}
@ -93,8 +88,8 @@ public class Lang {
this.infoLogger.logWarning("Could not load " + fileName + ".lang from within Advanced Portals.");
}
Map<String, String> newLangMap = this.getLanguageMap("lang/" + fileName + ".lang");
lang.languageMap.putAll(newLangMap);
Map<String, String> newLangMap = this.getLanguageMap(fileName );
Lang.instance.languageMap.putAll(newLangMap);
}
public static Map<String, String> parseLang(InputStream inputStream) {

View File

@ -35,8 +35,7 @@
translatedata.translationsoutdated= Some of the translations from the current translation file &e%1$s&c are out of date.
translatedata.replacecommand= Use &e/portal langupdate&c to copy out a new default &een_GB&c file.
translatedata.replaced= A new &een_GB&a file has been copied to the data folder.
translatedata.overwrite= Please use "&elangupdate overwrite&a" to replace the original file.
translatedata.updated= &e%1$s &atranslations have been added to the lang file.
translatedata.updated= &e%1$s &atranslations have been added to the lang file. If you want to reset the lang file, Please use "&elangupdate overwrite&a".
messageprefix.positive=&a[&eAdvancedPortals&a]
messageprefix.negative=&c[&7AdvancedPortals&c]