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

View File

@ -1,5 +1,15 @@
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.FilenameFilter;
import java.io.IOException;
@ -13,16 +23,6 @@ import java.util.Map;
import java.util.Objects;
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
*/
@ -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();
User user = User.getInstance(Bukkit.getConsoleSender());
user.sendRawMessage(ChatColor.AQUA + "*************************************************");
plugin.log(ChatColor.AQUA + "Analyzing BentoBox locale files");
user.sendRawMessage(ChatColor.AQUA + "*************************************************");
loadLocalesFromFile(BENTOBOX);
analyze(user, fix);
analyze(fix);
user.sendRawMessage(ChatColor.AQUA + "Analyzing Addon locale files");
plugin.getAddonsManager().getAddons().forEach(addon -> {
user.sendRawMessage(ChatColor.AQUA + "*************************************************");
@ -258,20 +264,30 @@ public class LocalesManager {
user.sendRawMessage(ChatColor.AQUA + "*************************************************");
languages.clear();
loadLocalesFromFile(addon.getDescription().getName());
analyze(user, fix);
analyze(fix);
});
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:");
languages.forEach((k,v) -> {
user.sendRawMessage(ChatColor.GOLD + k.toLanguageTag() + " " + k.getDisplayCountry() + " " + k.getDisplayLanguage());
});
languages.forEach((k,v) -> user.sendRawMessage(ChatColor.GOLD + k.toLanguageTag() + " " + k.getDisplayLanguage() + " " + k.getDisplayCountry()));
// Start with US English
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 + "Analyzing locale file " + l.toLanguageTag() + ":");
YamlConfiguration c = l.getConfig();
@ -289,7 +305,5 @@ public class LocalesManager {
user.sendRawMessage(ChatColor.GREEN + "Language file covers all strings.");
}
});
}
}

View File

@ -266,6 +266,11 @@ commands:
description: "display the management panel"
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:
confirm: "&cType command again within &b[seconds]s&c to confirm."
previous-request-cancelled: "&6Previous confirmation request cancelled."