Class LanguageInfo


  • public final class LanguageInfo
    extends java.lang.Object
    This is a utility class that provides information about locales and allows to convert locale codes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LanguageInfo.LocaleType
      Type of the locale to use
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LanguageInfo()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getDisplayName​(java.util.Locale locale)
      Replies the display string used by JOSM for a given locale.
      static java.lang.String getJavaLocaleCode​(java.lang.String localeName)
      Replies the locale code used by Java for a given locale.
      static java.lang.String getJOSMLocaleCode()
      Replies the JOSM locale code for the default locale.
      static java.lang.String getJOSMLocaleCode​(java.util.Locale locale)
      Replies the locale code used by JOSM for a given locale.
      static java.lang.String getLanguageCodeManifest()
      Replies the language prefix for use in manifests (with an underscore appended).
      static java.util.List<java.lang.String> getLanguageCodes​(java.util.Locale l)
      Replies a list of language codes for local names.
      static java.lang.String getLanguageCodeXML()
      Replies the language prefix for use in XML elements (with a dot appended).
      static java.util.Locale getLocale​(java.lang.String localeName)
      Replies the locale used by Java for a given language code.
      static java.util.Locale getLocale​(java.lang.String localeName, boolean useDefaultCountry)
      Replies the locale used by Java for a given language code.
      static java.lang.String[] getOSMLocaleCodes​(java.lang.String prefix)
      Replies the OSM locale codes for the default locale.
      static java.lang.String[] getOSMLocaleCodes​(java.lang.String prefix, java.util.Locale locale)
      Replies the locale codes used by OSM for a given locale.
      static java.lang.String getWikiLanguagePrefix()
      Replies the wiki language prefix for the current locale.
      (package private) static java.lang.String getWikiLanguagePrefix​(java.util.Locale locale, LanguageInfo.LocaleType type)  
      static java.lang.String getWikiLanguagePrefix​(LanguageInfo.LocaleType type)
      Replies the wiki language prefix for the given locale.
      static boolean isBetterLanguage​(java.lang.String oldLanguage, java.lang.String newLanguage)
      Check if a new language is better than a previous existing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getWikiLanguagePrefix

        public static java.lang.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 java.lang.String getJOSMLocaleCode()
        Replies the JOSM locale code for the default locale.
        Returns:
        the JOSM locale code for the default locale
        See Also:
        getJOSMLocaleCode(Locale)
      • getJOSMLocaleCode

        public static java.lang.String getJOSMLocaleCode​(java.util.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
      • getOSMLocaleCodes

        public static java.lang.String[] getOSMLocaleCodes​(java.lang.String prefix)
        Replies the OSM locale codes for the default locale.
        Parameters:
        prefix - a prefix like name:.
        Returns:
        the OSM locale codes for the default locale
        Since:
        19045
        See Also:
        getOSMLocaleCodes(String, Locale)
      • getOSMLocaleCodes

        public static java.lang.String[] getOSMLocaleCodes​(java.lang.String prefix,
                                                           java.util.Locale locale)
        Replies the locale codes used by OSM for a given locale.

        In most cases OSM 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:
        prefix - a prefix like name:.
        locale - the locale. Replies "en" if null.
        Returns:
        the OSM codes for the given locale
        Since:
        19045
      • getJavaLocaleCode

        public static java.lang.String getJavaLocaleCode​(java.lang.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 java.lang.String getDisplayName​(java.util.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 java.util.Locale getLocale​(java.lang.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 java.util.Locale getLocale​(java.lang.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​(java.lang.String oldLanguage,
                                               java.lang.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
      • getLanguageCodeXML

        public static java.lang.String getLanguageCodeXML()
        Replies the language prefix for use in XML elements (with a dot appended).
        Returns:
        the XML language prefix
        See Also:
        getJOSMLocaleCode()
      • getLanguageCodeManifest

        public static java.lang.String getLanguageCodeManifest()
        Replies the language prefix for use in manifests (with an underscore appended).
        Returns:
        the manifest language prefix
        See Also:
        getJOSMLocaleCode()
      • getLanguageCodes

        public static java.util.List<java.lang.String> getLanguageCodes​(java.util.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