mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Try to load locale from plugin data folder first
This commit is contained in:
parent
a496b1fd71
commit
c2d4aeaf85
@ -4,10 +4,17 @@ import com.gmail.nossr50.config.Config;
|
|||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import org.bukkit.ChatColor;
|
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.text.MessageFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.PropertyResourceBundle;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public final class LocaleLoader {
|
public final class LocaleLoader {
|
||||||
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
|
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]);
|
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);
|
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
|
||||||
|
}
|
||||||
enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
|
enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user