public class LocaleHelper extends Object
Modifier and Type | Class and Description |
---|---|
static class |
LocaleHelper.LocaleInfoComparator
Locale-sensitive comparison for LocaleInfo.
|
Constructor and Description |
---|
LocaleHelper() |
Modifier and Type | Method and Description |
---|---|
static Locale |
addLikelySubtags(Locale locale)
Adds the likely subtags for a provided locale ID.
|
static String |
getDisplayCountry(Locale locale)
Returns a locale's country localized for display in the default locale.
|
static String |
getDisplayCountry(Locale locale,
Locale displayLocale)
Returns a locale's country localized for display in the provided locale.
|
static String |
getDisplayLocaleList(LocaleList locales,
Locale displayLocale,
int maxLocales)
Returns the locale list localized for display in the provided locale.
|
static String |
getDisplayName(Locale locale,
boolean sentenceCase)
Returns the locale localized for display in the default locale.
|
static String |
getDisplayName(Locale locale,
Locale displayLocale,
boolean sentenceCase)
Returns the locale localized for display in the provided locale.
|
static String |
normalizeForSearch(String str,
Locale locale)
Normalizes a string for locale name search.
|
static String |
toSentenceCase(String str,
Locale locale)
Sentence-case (first character uppercased).
|
public static String toSentenceCase(String str, Locale locale)
There is no good API available for this, not even in ICU. We can revisit this if we get some ICU support later.
There are currently several tickets requesting this feature:
A (clunky) option with the current ICU API is:
{{ BreakIterator breakIterator = BreakIterator.getSentenceInstance(locale); String result = UCharacter.toTitleCase(locale, source, breakIterator, UCharacter.TITLECASE_NO_LOWERCASE); }}That also means creating a BreakIterator for each locale. Expensive...
str
- the string to sentence-case.locale
- the locale used for the case conversion.public static String normalizeForSearch(String str, Locale locale)
Warning: it is only intended to be used in searches by the locale picker. Don't use it for other things, it is very limited.
str
- the string to normalizelocale
- the locale that might be used for certain operations (i.e. case conversion)public static String getDisplayName(Locale locale, Locale displayLocale, boolean sentenceCase)
locale
- the locale whose name is to be displayed.displayLocale
- the locale in which to display the name.sentenceCase
- true if the result should be sentence-casedpublic static String getDisplayName(Locale locale, boolean sentenceCase)
locale
- the locale whose name is to be displayed.sentenceCase
- true if the result should be sentence-casedpublic static String getDisplayCountry(Locale locale, Locale displayLocale)
locale
- the locale whose country will be displayed.displayLocale
- the locale in which to display the name.public static String getDisplayCountry(Locale locale)
locale
- the locale whose country will be displayed.public static String getDisplayLocaleList(LocaleList locales, Locale displayLocale, int maxLocales)
locales
- the list of locales whose names is to be displayed.displayLocale
- the locale in which to display the names.
If this is null, it will use the default locale.maxLocales
- maximum number of locales to display. Generates ellipsis after that.