Class LanguageInfo


  • public final class LanguageInfo
    extends Object
    This is a utility class that provides information about locales and allows to convert locale codes.
    • Method Detail

      • getWikiLanguagePrefix

        public static String getWikiLanguagePrefix​(LanguageInfo.LocaleType type)
        Replies the wiki language prefix for the given locale. The wiki language prefix has the form 'Xy:' where 'Xy' is a ISO 639 language code in title case (or Xy_AB: for sub languages).
        Parameters:
        type - the type
        Returns:
        the wiki language prefix or null for LanguageInfo.LocaleType.BASELANGUAGE, when base language is identical to default or english
        Since:
        5915
      • getJOSMLocaleCode

        public static String getJOSMLocaleCode​(Locale locale)
        Replies the locale code used by JOSM for a given locale. In most cases JOSM uses the 2-character ISO 639 language code (Locale.getLanguage() to identify the locale of a localized resource, but in some cases it may use the programmatic name for locales, as replied by Locale.toString(). For unknown country codes and variants this function already does fallback to internally known translations.
        Parameters:
        locale - the locale. Replies "en" if null.
        Returns:
        the JOSM code for the given locale
      • getJavaLocaleCode

        public static String getJavaLocaleCode​(String localeName)
        Replies the locale code used by Java for a given locale. In most cases JOSM and Java uses the same codes, but for some exceptions this is needed.
        Parameters:
        localeName - the locale. Replies "en" if null.
        Returns:
        the Java code for the given locale
        Since:
        8232
      • getDisplayName

        public static String getDisplayName​(Locale locale)
        Replies the display string used by JOSM for a given locale. In most cases returns text replied by Locale.getDisplayName(), for some locales an override is used (i.e. when unsupported by Java).
        Parameters:
        locale - the locale. Replies "en" if null.
        Returns:
        the display string for the given locale
        Since:
        8232
      • getLocale

        public static Locale getLocale​(String localeName)
        Replies the locale used by Java for a given language code. Accepts JOSM and Java codes as input.
        Parameters:
        localeName - the locale code.
        Returns:
        the resulting locale
      • getLocale

        public static Locale getLocale​(String localeName,
                                       boolean useDefaultCountry)
        Replies the locale used by Java for a given language code. Accepts JOSM, Java and POSIX codes as input.
        Parameters:
        localeName - the locale code.
        useDefaultCountry - if true, the current locale country will be used if no country is specified
        Returns:
        the resulting locale
        Since:
        15547
      • isBetterLanguage

        public static boolean isBetterLanguage​(String oldLanguage,
                                               String newLanguage)
        Check if a new language is better than a previous existing. Can be used in classes where multiple user supplied language marked strings appear and the best one is searched. Following priorities: current language, english, any other
        Parameters:
        oldLanguage - the language code of the existing string
        newLanguage - the language code of the new string
        Returns:
        true if new one is better
        Since:
        8091
      • getLanguageCodes

        public static List<StringgetLanguageCodes​(Locale l)
        Replies a list of language codes for local names. Prefixes range from very specific to more generic.
        • lang_COUNTRY@variant of the current locale
        • lang@variant of the current locale
        • lang_COUNTRY of the current locale
        • lang of the current locale
        Parameters:
        l - the locale to use, null for default locale
        Returns:
        list of codes
        Since:
        8283