Class LocaleUtil
java.lang.Object
ch.tocco.nice2.textresources.api.locale.LocaleUtil
Provides utility functions for handling
Locale
s.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Specifies to which level a locale needs to match. -
Method Summary
Modifier and TypeMethodDescriptionstatic Locale
getBest
(Set<Locale> desired, Set<Locale> available, LocaleUtil.LocaleLevel compareLevel, Locale fallback) Returns the most desired locale that is available, or fallback.static Locale
Overloaded method where compareLevel = LocaleLevel.TO_VARIANT.getIntersection
(Set<Locale> desired, Set<Locale> available) Overloaded method where compareLevel = LocaleLevel.TO_VARIANT.getIntersection
(Set<Locale> desired, Set<Locale> available, LocaleUtil.LocaleLevel compareLevel) Returns the intersection in the order of the first (desired) param.static Locale
setCountry
(Locale locale, String country) Returns a new locale with the given country applied.static Locale
simplify
(Locale locale, LocaleUtil.LocaleLevel level) Simplifies a locale by stripping off information (if there).simplify
(Set<Locale> set, LocaleUtil.LocaleLevel level) Simplifies a set of locales by stripping off information (if there).
-
Method Details
-
getIntersection
public static Set<Locale> getIntersection(Set<Locale> desired, Set<Locale> available, LocaleUtil.LocaleLevel compareLevel) Returns the intersection in the order of the first (desired) param.Compares the locales to the level specified.
Note: For example a comparison to level TO_LANGUAGE will match two locales that have conflicting country information too, not just when one has no country information. This may not be desired.
- Returns:
- Ordered by desired, may be empty. The returned Locales contains all available info, even if it was simplified temporarily for comparison.
-
getIntersection
Overloaded method where compareLevel = LocaleLevel.TO_VARIANT.- Returns:
- ordered by desired, may be empty
-
getBest
public static Locale getBest(Set<Locale> desired, Set<Locale> available, LocaleUtil.LocaleLevel compareLevel, Locale fallback) Returns the most desired locale that is available, or fallback.Compares the
locales
to the level specified.Note: For example a comparison to level TO_LANGUAGE will match two locales that have conflicting country information too, not just when one has no country information. This may not be desired.
- Returns:
- The returned Locale contains all available info, even if it was simplified temporarily for comparison.
-
getBest
Overloaded method where compareLevel = LocaleLevel.TO_VARIANT.- Parameters:
fallback
- Does not check if fallback is in available. Pass null to get null.
-
simplify
Simplifies a set of locales by stripping off information (if there). Note that obviously the returned set may strink.- Returns:
- may be empty
-
simplify
Simplifies a locale by stripping off information (if there). -
setCountry
Returns a new locale with the given country applied.- Parameters:
locale
- The sourcecountry
- 2 letter iso in upper case, eg "CH", not null, may be empty.- Returns:
- The new locale with the new country and the existing language and variant.
-