Improved /bbox locale

This commit is contained in:
Florian CUNY 2019-05-01 10:48:47 +02:00
parent 51505ce276
commit 95c0c612da
3 changed files with 48 additions and 27 deletions

View File

@ -1,15 +1,16 @@
package world.bentobox.bentobox.commands; package world.bentobox.bentobox.commands;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand; import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import java.util.List;
/** /**
* Manages localization. * Performs localization analysis.
* *
* @author tastybento * @author tastybento
* @since 1.5.0
*/ */
public class BentoBoxLocaleCommand extends ConfirmableCommand { public class BentoBoxLocaleCommand extends ConfirmableCommand {
@ -30,7 +31,8 @@ public class BentoBoxLocaleCommand extends ConfirmableCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
// Basic operation to start // Basic operation to start
getPlugin().getLocalesManager().analyzeLocales(user, false); user.sendMessage("commands.bentobox.locale.see-console");
getPlugin().getLocalesManager().analyzeLocales(false);
return true; return true;
} }
} }

View File

@ -1,5 +1,15 @@
package world.bentobox.bentobox.managers; package world.bentobox.bentobox.managers;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.localization.BentoBoxLocale;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.FileLister;
import world.bentobox.bentobox.util.Util;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
@ -13,16 +23,6 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.bukkit.configuration.file.YamlConfiguration;
import net.md_5.bungee.api.ChatColor;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.localization.BentoBoxLocale;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.FileLister;
import world.bentobox.bentobox.util.Util;
/** /**
* @author tastybento, Poslovitch * @author tastybento, Poslovitch
*/ */
@ -240,17 +240,23 @@ public class LocalesManager {
} }
/** /**
* Loads all the locales available in the locale folder given. Used for loading all locales from plugin and addons * Loads all the locales available in the locale folder given.
* Used for loading all locales from plugin and addons.
* *
* @param localeFolder - locale folder location relative to the plugin's data folder * @param fix whether or not locale files with missing translations should be fixed.
* Not currently supported.
* @since 1.5.0
*/ */
public void analyzeLocales(User user, boolean fix) { public void analyzeLocales(boolean fix) {
languages.clear(); languages.clear();
User user = User.getInstance(Bukkit.getConsoleSender());
user.sendRawMessage(ChatColor.AQUA + "*************************************************"); user.sendRawMessage(ChatColor.AQUA + "*************************************************");
plugin.log(ChatColor.AQUA + "Analyzing BentoBox locale files"); plugin.log(ChatColor.AQUA + "Analyzing BentoBox locale files");
user.sendRawMessage(ChatColor.AQUA + "*************************************************"); user.sendRawMessage(ChatColor.AQUA + "*************************************************");
loadLocalesFromFile(BENTOBOX); loadLocalesFromFile(BENTOBOX);
analyze(user, fix); analyze(fix);
user.sendRawMessage(ChatColor.AQUA + "Analyzing Addon locale files"); user.sendRawMessage(ChatColor.AQUA + "Analyzing Addon locale files");
plugin.getAddonsManager().getAddons().forEach(addon -> { plugin.getAddonsManager().getAddons().forEach(addon -> {
user.sendRawMessage(ChatColor.AQUA + "*************************************************"); user.sendRawMessage(ChatColor.AQUA + "*************************************************");
@ -258,20 +264,30 @@ public class LocalesManager {
user.sendRawMessage(ChatColor.AQUA + "*************************************************"); user.sendRawMessage(ChatColor.AQUA + "*************************************************");
languages.clear(); languages.clear();
loadLocalesFromFile(addon.getDescription().getName()); loadLocalesFromFile(addon.getDescription().getName());
analyze(user, fix); analyze(fix);
}); });
reloadLanguages(); reloadLanguages();
} }
private void analyze(User user, boolean fix) { /**
if (!languages.containsKey(Locale.US)) return; *
* @param fix whether or not locale files with missing translations should be fixed.
* Not currently supported.
* @since 1.5.0
*/
private void analyze(boolean fix) {
if (!languages.containsKey(Locale.US)) {
return;
}
User user = User.getInstance(Bukkit.getConsoleSender());
user.sendRawMessage(ChatColor.GREEN + "The following locales are supported:"); user.sendRawMessage(ChatColor.GREEN + "The following locales are supported:");
languages.forEach((k,v) -> { languages.forEach((k,v) -> user.sendRawMessage(ChatColor.GOLD + k.toLanguageTag() + " " + k.getDisplayLanguage() + " " + k.getDisplayCountry()));
user.sendRawMessage(ChatColor.GOLD + k.toLanguageTag() + " " + k.getDisplayCountry() + " " + k.getDisplayLanguage());
});
// Start with US English // Start with US English
YamlConfiguration usConfig = languages.get(Locale.US).getConfig(); YamlConfiguration usConfig = languages.get(Locale.US).getConfig();
languages.entrySet().stream().filter(e -> !e.getKey().equals(Locale.US)).map(Map.Entry::getValue).forEach(l -> {
languages.values().stream().filter(l -> !l.toLanguageTag().equals(Locale.US.toLanguageTag())).forEach(l -> {
System.out.println(l.toLanguageTag());
user.sendRawMessage(ChatColor.GREEN + "*************************************************"); user.sendRawMessage(ChatColor.GREEN + "*************************************************");
user.sendRawMessage(ChatColor.GREEN + "Analyzing locale file " + l.toLanguageTag() + ":"); user.sendRawMessage(ChatColor.GREEN + "Analyzing locale file " + l.toLanguageTag() + ":");
YamlConfiguration c = l.getConfig(); YamlConfiguration c = l.getConfig();
@ -289,7 +305,5 @@ public class LocalesManager {
user.sendRawMessage(ChatColor.GREEN + "Language file covers all strings."); user.sendRawMessage(ChatColor.GREEN + "Language file covers all strings.");
} }
}); });
} }
} }

View File

@ -266,6 +266,11 @@ commands:
description: "display the management panel" description: "display the management panel"
catalog: catalog:
description: "display the Addons catalog" description: "display the Addons catalog"
locale:
description: "perform locale analysis"
see-console: |-
&aCheck the console to see the feedback.
&aThis command is so spammy that the feedback cannot be read from chat...
confirmation: confirmation:
confirm: "&cType command again within &b[seconds]s&c to confirm." confirm: "&cType command again within &b[seconds]s&c to confirm."
previous-request-cancelled: "&6Previous confirmation request cancelled." previous-request-cancelled: "&6Previous confirmation request cancelled."