Package org.openstreetmap.josm.tools
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.
-
-
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 String
getDisplayName(Locale locale)
Replies the display string used by JOSM for a given locale.static String
getJavaLocaleCode(String localeName)
Replies the locale code used by Java for a given locale.static String
getJOSMLocaleCode()
Replies the JOSM locale code for the default locale.static String
getJOSMLocaleCode(Locale locale)
Replies the locale code used by JOSM for a given locale.static String
getLanguageCodeManifest()
Replies the language prefix for use in manifests (with an underscore appended).static List<String>
getLanguageCodes(Locale l)
Replies a list of language codes for local names.static String
getLanguageCodeXML()
Replies the language prefix for use in XML elements (with a dot appended).static Locale
getLocale(String localeName)
Replies the locale used by Java for a given language code.static Locale
getLocale(String localeName, boolean useDefaultCountry)
Replies the locale used by Java for a given language code.static String
getWikiLanguagePrefix()
Replies the wiki language prefix for the current locale.(package private) static String
getWikiLanguagePrefix(Locale locale, LanguageInfo.LocaleType type)
static String
getWikiLanguagePrefix(LanguageInfo.LocaleType type)
Replies the wiki language prefix for the given locale.static boolean
isBetterLanguage(String oldLanguage, String newLanguage)
Check if a new language is better than a previous existing.
-
-
-
Constructor Detail
-
LanguageInfo
private LanguageInfo()
-
-
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
forLanguageInfo.LocaleType.BASELANGUAGE
, when base language is identical to default or english - Since:
- 5915
-
getWikiLanguagePrefix
static String getWikiLanguagePrefix(Locale locale, LanguageInfo.LocaleType type)
-
getWikiLanguagePrefix
public static String getWikiLanguagePrefix()
Replies the wiki language prefix for the current locale.- Returns:
- the wiki language prefix
- See Also:
Locale.getDefault()
,getWikiLanguagePrefix(LocaleType)
-
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(Locale)
-
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 byLocale.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 byLocale.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
- iftrue
, 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 stringnewLanguage
- 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:
getJOSMLocaleCode()
-
getLanguageCodeManifest
public static 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 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
-
-