Package ninja.i18n

Class LangImpl

  • All Implemented Interfaces:
    Lang

    public class LangImpl
    extends Object
    implements Lang
    • Constructor Detail

    • Method Detail

      • clearLanguage

        public void clearLanguage​(Result result)
        Description copied from interface: Lang
        Clears the current language. This will trigger resolving language from request (Accept lang) if not manually set. Note: The language is set by a cookie. To delete a cookie the max-age is set to 0. It can therefore be the case that the lang cookie still exists in the thread. Make sure your module / app handles this properly.
        Specified by:
        clearLanguage in interface Lang
      • setLanguage

        public Result setLanguage​(String locale,
                                  Result result)
        Description copied from interface: Lang
        Force a language in Ninja framwork. This is usually done by a cookie NINJA_LANG. This overrides any Accept-Language languages.
        Specified by:
        setLanguage in interface Lang
        Parameters:
        locale - (fr, ja, it ...)
      • getLanguage

        public Optional<String> getLanguage​(Context context,
                                            Optional<Result> result)
        Description copied from interface: Lang
        Retrieve the current language or null if not set. It will try to determine the language by: 1) Checking if result contains a forced language 2) Checking if context has a NINJA_LANG cookie with a forced language 3) Getting the first language from the Accept-Language header
        Specified by:
        getLanguage in interface Lang
        Returns:
        The current language (fr, ja, it ...) - may be absent
      • isLanguageDirectlySupportedByThisApplication

        public boolean isLanguageDirectlySupportedByThisApplication​(String language)
        Description copied from interface: Lang
        application.conf usually contains the following: application.languages=en,de This little helper checks if the language is supported.
        Specified by:
        isLanguageDirectlySupportedByThisApplication in interface Lang
        Parameters:
        language - The language to check (en, en-US etc)
        Returns:
        true if supported directly, false if not
      • getLocaleFromStringOrDefault

        public Locale getLocaleFromStringOrDefault​(Optional<String> language)
        Description copied from interface: Lang
        application.conf usually contains the following: application.languages=en,de This little helper converts a language code like (en, en-US etc) to a Java locale. It takes null as input and falls back to the default language. By convention this is the first language of application.languages. In the case of application.languages=en,de The default language is "en".
        Specified by:
        getLocaleFromStringOrDefault in interface Lang
        Parameters:
        language - The language to check (en, en-US etc)
        Returns:
        The Java locale or a default locale based on the first language in your application.languages configuration.