Skip to content

Commit

Permalink
Using language tag to store locale
Browse files Browse the repository at this point in the history
  • Loading branch information
JayPi4c committed Jun 18, 2024
1 parent 7f7640c commit 5faa925
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/JayPi4c/RobbiSimulator/utils/I18nUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ public static void setLocale(Locale locale) {
/**
* Setter for the current locale by the String representation of the locale.
*
* @param locale the locale as String
* @param languageTag the locale defined by a language tag
*/
public static void setLocale(String locale) {
public static void setLocale(String languageTag) {
try {
String[] parts = locale.split("_");
setLocale(new Locale(parts[0], parts[1]));
setLocale(Locale.forLanguageTag(languageTag));
} catch (IndexOutOfBoundsException | NullPointerException e) {
setLocale(Locale.UK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public static boolean getSounds() {
}

/**
* Getter for the sounds property.
* Getter for the darkmode-property.
*
* @return true if the sounds property is set to true
* @return true if the darkmode property is set to true
*/
public static boolean getDarkmode() {
return Boolean.parseBoolean(properties.getProperty(DARKMODE_PROPERTY));
Expand All @@ -103,9 +103,9 @@ public static String getTutorhost() {
}

/**
* Getter for the tutorport.
* Getter for the tutor-port.
*
* @return the tutorport stored in the properties file
* @return the tutor-port stored in the properties file
*/
public static int getTutorport() {
try {
Expand All @@ -123,11 +123,10 @@ public static int getTutorport() {
*/
public static Locale getLocale() {
try {
String[] parts = properties.getProperty(LANGUAGE_PROPERTY).split("_");
return new Locale(parts[0], parts[1]);
return Locale.forLanguageTag(properties.getProperty(LANGUAGE_PROPERTY));
} catch (IndexOutOfBoundsException | NullPointerException e) {
logger.debug("Failed to load locale from properties");
properties.put(LANGUAGE_PROPERTY, Locale.GERMANY.toString());
properties.put(LANGUAGE_PROPERTY, Locale.GERMANY.toLanguageTag());
return Locale.GERMANY;
}
}
Expand All @@ -154,7 +153,7 @@ public static boolean finish() {
* application failed to load properties from the file.
*/
private static void loadDefaultProperties() {
properties.put(LANGUAGE_PROPERTY, Locale.GERMANY.toString());
properties.put(LANGUAGE_PROPERTY, Locale.GERMANY.toLanguageTag());
properties.put(ROLE_PROPERTY, "student");
properties.put(TUTORPORT_PROPERTY, TUTORPORT_DEFAULT_VALUE);
properties.put(TUTORHOST_PROPERTY, TUTORHOST_DEFAULT_VALUE);
Expand Down

0 comments on commit 5faa925

Please sign in to comment.