Class 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 call find().

    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 Detail

      • I18nLanguageFinder

        public I18nLanguageFinder​(List<String> available)
    • 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