Class LanguageInfo

java.lang.Object
org.openstreetmap.josm.tools.LanguageInfo

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

  • Method Details

    • getWikiLanguagePrefix

      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
    • getWikiLanguagePrefix

    • getWikiLanguagePrefix

      public static String getWikiLanguagePrefix()
      Replies the wiki language prefix for the current locale.
      Returns:
      the wiki language prefix
      See Also:
    • getJOSMLocaleCode

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

      public static String[] getOSMLocaleCodes(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

      public static String[] getOSMLocaleCodes(String prefix, 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 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
    • getLanguageCodeXML

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

      Replies the language prefix for use in manifests (with an underscore appended).
      Returns:
      the manifest language prefix
      See Also:
    • getLanguageCodes

      public static List<String> getLanguageCodes(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