Try to load locale from plugin data folder first

This commit is contained in:
Mark Vainomaa 2019-04-29 01:25:00 +03:00
parent a496b1fd71
commit c2d4aeaf85

View File

@ -4,10 +4,17 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mcMMO;
import org.bukkit.ChatColor;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.logging.Level;
public final class LocaleLoader {
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
@ -85,7 +92,21 @@ public final class LocaleLoader {
locale = new Locale(myLocale[0], myLocale[1]);
}
if (locale == null) {
throw new IllegalStateException("Failed to parse locale string '" + Config.getInstance().getLocale() + "'");
}
Path localePath = Paths.get(mcMMO.getMainDirectory() + "locale_" + locale.toString() + ".properties");
if (Files.exists(localePath) && Files.isRegularFile(localePath)) {
try (Reader localeReader = Files.newBufferedReader(localePath)) {
bundle = new PropertyResourceBundle(localeReader);
} catch (IOException e) {
mcMMO.p.getLogger().log(Level.WARNING, "Failed to load locale from " + localePath, e);
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
}
} else {
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
}
enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
}
}