Package nl.rrd.wool.i18n
Class I18nLanguageFinder
- java.lang.Object
-
- nl.rrd.wool.i18n.I18nLanguageFinder
-
public class I18nLanguageFinder extends Object
This class can find a preferred language from a list of available languages. After construction you can set properties with the set methods. Then callfind().Example
Find properties:
- userLocales: ["nl_NL"]
- honorifics: true
It will try the following keys, in this order:
- "nl_NL_v" (if the locale contains a country; v = vos, t = tu)
- "nl_NL" (if the locale contains a country)
- "nl_v"
- "nl"
- "v"
- ""
If nothing is found, it will try the following locales: en_GB, en_US, en.
-
-
Constructor Summary
Constructors Constructor Description I18nLanguageFinder(List<String> available)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringfind()Tries to find a preferred language matching the specified properties.voidsetHonorifics(boolean honorifics)Sets whether the resource should use honorifics.voidsetUserLocale(Locale userLocale)Sets the preferred locale of the user.voidsetUserLocales(List<Locale> userLocales)Sets the preferred locales of the user.
-
-
-
Method Detail
-
setUserLocale
public void setUserLocale(Locale userLocale)
Sets the preferred locale of the user. If no resource is found for this locale, the resource finder will try en_GB, en_US or en. The default is the locale of the system.- Parameters:
userLocale- the preferred locale of the user- See Also:
setUserLocales(List)
-
setUserLocales
public void setUserLocales(List<Locale> userLocales)
Sets the preferred locales of the user. If no resource is found for these locales, the resource finder will try en_GB, en_US or en. The default is the locale of the system.- Parameters:
userLocales- the preferred locales of the user (at least one)
-
setHonorifics
public void setHonorifics(boolean honorifics)
Sets whether the resource should use honorifics. This is true for vos (u, vous, Sie) in tu-vos distinction, and false for tu (jij, tu, du). For languages without honorifics, such as English, there will be no resources with tu-vos designation, so the value of this property is not relevant. The default is true.- Parameters:
honorifics- true if the resource should use honorifics, false otherwise
-
find
public String find()
Tries to find a preferred language matching the specified properties. If a language is found, this method will return the code. Otherwise it returns null.- Returns:
- the string map
-
-