1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-15 10:24:04 +02:00

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.
This commit is contained in:
soloturn
2024-07-27 11:09:43 +02:00
parent e938ac97b1
commit 4e595b143b
2 changed files with 6 additions and 5 deletions

View File

@@ -53,8 +53,6 @@ import java.util.regex.Pattern;
*/ */
public class Utils { 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 RIP_DIRECTORY = "rips";
private static final String CONFIG_FILE = "rip.properties"; private static final String CONFIG_FILE = "rip.properties";
private static final String OS = System.getProperty("os.name").toLowerCase(); private static final String OS = System.getProperty("os.name").toLowerCase();
@@ -740,8 +738,8 @@ public class Utils {
new UTF8Control()); new UTF8Control());
} }
} else { } else {
String[] langCode = langSelect.split("_"); String[] langCode = langSelect.split("-");
LOGGER.info("Setting locale to " + langSelect); LOGGER.info("set locale, langcoe: {}, selected langauge: {}, locale: {}", langCode, langSelect, Locale.forLanguageTag(langSelect));
return ResourceBundle.getBundle("LabelsBundle", Locale.forLanguageTag(langSelect), new UTF8Control()); return ResourceBundle.getBundle("LabelsBundle", Locale.forLanguageTag(langSelect), new UTF8Control());
} }
try { try {
@@ -755,6 +753,7 @@ public class Utils {
public static void setLanguage(String langSelect) { public static void setLanguage(String langSelect) {
resourceBundle = getResourceBundle(langSelect); resourceBundle = getResourceBundle(langSelect);
LOGGER.info("Selected resource bundle locale: {}, from {}", resourceBundle.getLocale().toString(), langSelect);
} }
public static String getSelectedLanguage() { public static String getSelectedLanguage() {
@@ -763,6 +762,8 @@ public class Utils {
// All the langs ripme has been translated into // All the langs ripme has been translated into
public static String[] getSupportedLanguages() { 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<>(); ArrayList<Path> filesList = new ArrayList<>();
try { try {
URI uri = Objects.requireNonNull(Utils.class.getResource("/rip.properties")).toURI(); URI uri = Objects.requireNonNull(Utils.class.getResource("/rip.properties")).toURI();
@@ -782,7 +783,7 @@ public class Utils {
for (int i = 0; i < filesList.size(); i++) { for (int i = 0; i < filesList.size(); i++) {
Matcher matcher = pattern.matcher(filesList.get(i).toString()); Matcher matcher = pattern.matcher(filesList.get(i).toString());
if (matcher.find()) if (matcher.find())
langs[i] = matcher.group("lang"); langs[i] = matcher.group("lang").replace("_", "-");
} }
return langs; return langs;