package me.teridax.jcash.lang; import java.util.Locale; /** * Class for storing static information about the locale used by the application instance at runtime. */ @SuppressWarnings("unused") public class Locales { /** * Locale string used to identify a certain locale */ private static String defaultLocale = "en_EN"; /** * Sets the default locale to use for the application instance. * This will instruct the translator to use the default locale as well as * Java swing components. * @param language the locale to use for language * @param country the locale to use for country */ public static void setDefaultLocale(String language, String country) { var locale = language + "_" + country; if (Translator.setTranslationLocale(locale)) { // apply locale to JVM Locale.setDefault(new Locale(language, country)); defaultLocale = locale; } } public static String getDefaultLocale() { return defaultLocale; } /** * Tries to automatically detect the default locale. * This will prefer the users locale over the systems locale. * If both fail, the JVMs default locale will be used. */ public static void autodetectDefaultLocale() { var country = System.getProperty("user.country"); var language = System.getProperty("user.language"); var jvmLocale = Locale.getDefault(); if (null == country) country = jvmLocale.getCountry(); if (null == language) language = jvmLocale.getLanguage(); setDefaultLocale(language, country); } }