Skip to content

Commit

Permalink
java locale painful, fix - and _
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
soloturn committed Jul 27, 2024
1 parent e938ac9 commit 4e595b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/rarchives/ripme/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
*/
public class Utils {

private static final Pattern pattern = Pattern.compile("LabelsBundle_(?<lang>[A-Za-z_]+).properties");
private static final String DEFAULT_LANG = "en_US";
private static final String RIP_DIRECTORY = "rips";
private static final String CONFIG_FILE = "rip.properties";
private static final String OS = System.getProperty("os.name").toLowerCase();
Expand Down Expand Up @@ -740,8 +738,8 @@ public static ResourceBundle getResourceBundle(String langSelect) {
new UTF8Control());
}
} else {
String[] langCode = langSelect.split("_");
LOGGER.info("Setting locale to " + langSelect);
String[] langCode = langSelect.split("-");
LOGGER.info("set locale, langcoe: {}, selected langauge: {}, locale: {}", langCode, langSelect, Locale.forLanguageTag(langSelect));
return ResourceBundle.getBundle("LabelsBundle", Locale.forLanguageTag(langSelect), new UTF8Control());
}
try {
Expand All @@ -755,6 +753,7 @@ public static ResourceBundle getResourceBundle(String langSelect) {

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

public static String getSelectedLanguage() {
Expand All @@ -763,6 +762,8 @@ public static String getSelectedLanguage() {

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

return langs;
Expand Down

0 comments on commit 4e595b1

Please sign in to comment.