From 5faa925a711c4f36dd08278b1eee9ceaa54358b2 Mon Sep 17 00:00:00 2001 From: Jonas Pohl Date: Tue, 18 Jun 2024 22:13:00 +0200 Subject: [PATCH] Using language tag to store locale --- .../JayPi4c/RobbiSimulator/utils/I18nUtils.java | 7 +++---- .../RobbiSimulator/utils/PropertiesLoader.java | 15 +++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/JayPi4c/RobbiSimulator/utils/I18nUtils.java b/src/main/java/com/JayPi4c/RobbiSimulator/utils/I18nUtils.java index 540495c..3897137 100644 --- a/src/main/java/com/JayPi4c/RobbiSimulator/utils/I18nUtils.java +++ b/src/main/java/com/JayPi4c/RobbiSimulator/utils/I18nUtils.java @@ -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); } diff --git a/src/main/java/com/JayPi4c/RobbiSimulator/utils/PropertiesLoader.java b/src/main/java/com/JayPi4c/RobbiSimulator/utils/PropertiesLoader.java index 98aa6d6..e375acc 100644 --- a/src/main/java/com/JayPi4c/RobbiSimulator/utils/PropertiesLoader.java +++ b/src/main/java/com/JayPi4c/RobbiSimulator/utils/PropertiesLoader.java @@ -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)); @@ -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 { @@ -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; } } @@ -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);