Package com.globalmentor.model
Class Locales
- java.lang.Object
-
- com.globalmentor.model.Locales
-
public class Locales extends java.lang.Object
Utilities for manipulating Java locales.- Author:
- Garret Wilson
- See Also:
- RFC 4646
-
-
Field Summary
Fields Modifier and Type Field Description static char
LANGUAGE_TAG_SEPARATOR
The character '-' used to separate components in language tags as defined in RFC 4646, "Tags for the Identifying".static char
LOCALE_SEPARATOR
The character used to separate components in a locale: '_'.
-
Constructor Summary
Constructors Constructor Description Locales()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.Locale
createDisplayLanguageLocale(java.lang.String displayLanguage)
Retrieves a locale based upon a given display name in the current local.static java.util.Locale
createLocale(java.lang.String localeString)
Constructs a locale object from a locale string with a language, an optional country code, and an optional variant.static java.lang.String[]
getAvailableDisplayCountries()
Retrieves a sorted list of display countries for all available locales.static java.lang.String[]
getAvailableDisplayCountries(java.util.Locale inLocale)
Retrieves a sorted list of display countries for all available locales.static java.lang.String
getLanguageTag(java.util.Locale locale)
Determines the string to represent a language identifier according as defined in RFC 4646, "Tags for the Identification of Languages".static java.lang.String
getLocaleCandidatePath(java.lang.String basePath, java.util.Locale locale, int depth)
Deprecated.TODO move to Rincl
-
-
-
Field Detail
-
LOCALE_SEPARATOR
public static final char LOCALE_SEPARATOR
The character used to separate components in a locale: '_'.- See Also:
- Constant Field Values
-
LANGUAGE_TAG_SEPARATOR
public static final char LANGUAGE_TAG_SEPARATOR
The character '-' used to separate components in language tags as defined in RFC 4646, "Tags for the Identifying".- See Also:
- RFC 4646, Constant Field Values
-
-
Method Detail
-
createLocale
public static java.util.Locale createLocale(java.lang.String localeString)
Constructs a locale object from a locale string with a language, an optional country code, and an optional variant. These components can be separated by underscore characters ('_') as represented byLocale
, or by hyphen characters ('-') as defined in RFC 4646, "Tags for Identifying Languages".- Parameters:
localeString
- The string containing the language, optional country, and optional variant.- Returns:
- A local corresponding to the given local string.
- Throws:
java.lang.IllegalArgumentException
- if the given locale string has more than three components.- See Also:
- RFC 4646
-
createDisplayLanguageLocale
public static java.util.Locale createDisplayLanguageLocale(java.lang.String displayLanguage)
Retrieves a locale based upon a given display name in the current local. That is, if the default locale isen_US
, the display language "French" will return the local forfr
.- Parameters:
displayLanguage
- The name of a language in the current locale.- Returns:
- The local that matches the given language, or
null
if no locale could be found with the given display language.
-
getAvailableDisplayCountries
public static java.lang.String[] getAvailableDisplayCountries()
Retrieves a sorted list of display countries for all available locales. The display countries will use the default locale for the localized name.- Returns:
- An array of display country names for installed locales.
-
getAvailableDisplayCountries
public static java.lang.String[] getAvailableDisplayCountries(java.util.Locale inLocale)
Retrieves a sorted list of display countries for all available locales. The display countries will use the given locale for the localized name.- Parameters:
inLocale
- The locale for which the country names should be localized.- Returns:
- An array of display country names for installed locales.
-
getLanguageTag
public static java.lang.String getLanguageTag(java.util.Locale locale)
Determines the string to represent a language identifier according as defined in RFC 4646, "Tags for the Identification of Languages".- Parameters:
locale
- The language identifier.- Returns:
- The string representation of the language identifier.
- Throws:
java.lang.NullPointerException
- if the given locale isnull
.- See Also:
- RFC 4646
-
getLocaleCandidatePath
@Deprecated public static java.lang.String getLocaleCandidatePath(java.lang.String basePath, java.util.Locale locale, int depth)
Deprecated.TODO move to RinclDetermines the locale-sensitive path of the given base path based upon a depth index. Based upon the provided locale and depth, a candidate resource path is generated as follows:- depth 3
- basePath + "_" + language + "_" + country + "_" + variant + "." + extension
- depth 2
- basePath + "_" + language + "_" + country + "." + extension
- depth 1
- basePath + "_" + language + "." + extension
- depth 0
- basePath + "." + extension
null
will be returned.- Parameters:
basePath
- The base path for which a candidate path should be generated.locale
- The locale to use in generating the candidate path.depth
- The depth at which the candidate path should be generated.- Returns:
- The candidate path for provided base path at the given locale and depth, or
null
if the given locale does not have enough information to generate a candidate path at the given depth. - Throws:
java.lang.NullPointerException
- if the given base path and/or locale isnull
.java.lang.IllegalArgumentException
- if the given depth is not within the range (depth>=0 and depth<=3).
-
-