Skip to content

Commit 4e595b1

Browse files
committed
java locale painful, fix - and _
java uses ietf-bcp-47 lanauge tags, which are strings separated by -. resource bundle names are _ separated. porrisavo not fixed, this is a one person artificial dialect from finish cities of pori and savo.
1 parent e938ac9 commit 4e595b1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/main/java/com/rarchives/ripme/utils/Utils.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
*/
5454
public class Utils {
5555

56-
private static final Pattern pattern = Pattern.compile("LabelsBundle_(?<lang>[A-Za-z_]+).properties");
57-
private static final String DEFAULT_LANG = "en_US";
5856
private static final String RIP_DIRECTORY = "rips";
5957
private static final String CONFIG_FILE = "rip.properties";
6058
private static final String OS = System.getProperty("os.name").toLowerCase();
@@ -740,8 +738,8 @@ public static ResourceBundle getResourceBundle(String langSelect) {
740738
new UTF8Control());
741739
}
742740
} else {
743-
String[] langCode = langSelect.split("_");
744-
LOGGER.info("Setting locale to " + langSelect);
741+
String[] langCode = langSelect.split("-");
742+
LOGGER.info("set locale, langcoe: {}, selected langauge: {}, locale: {}", langCode, langSelect, Locale.forLanguageTag(langSelect));
745743
return ResourceBundle.getBundle("LabelsBundle", Locale.forLanguageTag(langSelect), new UTF8Control());
746744
}
747745
try {
@@ -755,6 +753,7 @@ public static ResourceBundle getResourceBundle(String langSelect) {
755753

756754
public static void setLanguage(String langSelect) {
757755
resourceBundle = getResourceBundle(langSelect);
756+
LOGGER.info("Selected resource bundle locale: {}, from {}", resourceBundle.getLocale().toString(), langSelect);
758757
}
759758

760759
public static String getSelectedLanguage() {
@@ -763,6 +762,8 @@ public static String getSelectedLanguage() {
763762

764763
// All the langs ripme has been translated into
765764
public static String[] getSupportedLanguages() {
765+
final Pattern pattern = Pattern.compile("LabelsBundle_(?<lang>[A-Za-z_]+).properties");
766+
final String DEFAULT_LANG = "en-US";
766767
ArrayList<Path> filesList = new ArrayList<>();
767768
try {
768769
URI uri = Objects.requireNonNull(Utils.class.getResource("/rip.properties")).toURI();
@@ -782,7 +783,7 @@ public static String[] getSupportedLanguages() {
782783
for (int i = 0; i < filesList.size(); i++) {
783784
Matcher matcher = pattern.matcher(filesList.get(i).toString());
784785
if (matcher.find())
785-
langs[i] = matcher.group("lang");
786+
langs[i] = matcher.group("lang").replace("_", "-");
786787
}
787788

788789
return langs;

0 commit comments

Comments
 (0)