Interface L10N

All Known Implementing Classes:
L10NImpl

public interface L10N
The main entry point to the i18n system defining the l10n for the current thread. It can both be queried and used the change the locale. This service takes care of both the current locale and the time zone. Further, the available locales may differ depending on the context: For a language school in Zürich, the administration interface may be available in German only, however, correspondence may also be translated into other languages for the customers, e.g. English or Turkish. Four standard contexts are defined as constants: "system" "rendering", "application" and "web". These contexts are always available. By default, threads are set to the systemLocale(), the system time zone and the context "rendering". ### Note on the terms Internationalization (i18n) : The process of making a program capable of working with various locales Localization (l10n) : The process of localising a programm for one specific locale.
  • Field Details

    • SYSTEM_CONTEXT

      static final String SYSTEM_CONTEXT
      The system context. This context has always only one available locale, the system locale, which is also the fallback locale.
      See Also:
    • RENDERING_CONTEXT

      static final String RENDERING_CONTEXT
      The standard context for rendering.
      See Also:
    • APPLICATION_CONTEXT

      static final String APPLICATION_CONTEXT
      The standard context for the application (i.e. the admin user interface).
      See Also:
    • WEB_CONTEXT

      static final String WEB_CONTEXT
      The standard context for the web site.
      See Also:
  • Method Details

    • systemLocale

      Locale systemLocale()
      Gets the system locale. The system locale is the one used for all system tasks, that are basically *not* localised. The system locale is usually `en`.
      Returns:
      The system locale.
    • fallbackLocale

      Locale fallbackLocale()
      Gets the fallback locale for the thread's current context.
      Returns:
      The fallback locale.
    • fallbackLocale

      Locale fallbackLocale(@Nullable @Nullable String contextName)
      Gets the fallback locale for the specified context.
      Parameters:
      contextName - The context or `null` for the current context.
      Returns:
      The fallback locale.
    • availableLocales

      Set<Locale> availableLocales()
      Gets the available locales for the thread's current context ordered by their preference.
      Returns:
      A Set of all available locales.
    • availableLocales

      Set<Locale> availableLocales(@Nullable @Nullable String contextName)
      Gets the available locales for the specified context ordered by their preference.
      Parameters:
      contextName - The context or `null` for the current context.
      Returns:
      A Set of all available locales or an empty list, if no such context has been defined.
    • availableContexts

      Set<L10N.Context> availableContexts()
      Gets the available contexts.
      Returns:
      A Set of available contexts.
    • currentLocale

      Locale currentLocale()
      Gets the current locale. This is the locale that has been set by invoking code through the Invoker specified in Context.using().
      Returns:
      The current locale.
      See Also:
    • currentContext

      L10N.Context currentContext()
      Gets the current context.
      Returns:
      The current context.
    • bestLocaleFor

      Locale bestLocaleFor(List<Locale> requested)
      Gets the best available locale for the specified list of requested locales based on the thread's current context.
      Parameters:
      requested - The list of preferred locales.
      Returns:
      The best available locale for the requested locale.
      See Also:
    • bestLocaleFor

      Locale bestLocaleFor(List<Locale> requested, @Nullable @Nullable String contextName)
      Gets the best *available* locale for the specified list of requested locales in the current context. The locale list should be sorted by preference, the most preferred locale first. Returns the fallback locale if no suitable locale is available.
      Parameters:
      requested - The list of preferred locales.
      contextName - The context or `null` for the current context.
      Returns:
      The best available locale for the requested locale.
      See Also:
    • using

      Invoker using(Locale locale)
      Returns an Invoker that can be used to invoke code using the specified locale.
      Parameters:
      locale - The locale to be used when invoking code or `null` for no change.
      Returns:
      An invoker that invokes code using the specified locale.
      See Also:
    • using

      Invoker using(Locale locale, String contextName)
      Returns an Invoker that can be used to invoke code changing the context and locale.
      Parameters:
      locale - The locale to be used when invoking code or `null` for no change.
      contextName - The context or to switch to when invoking code or `null` for no change.
      Returns:
      An invoker that invokes code using the specified locale and context.
      See Also:
    • using

      Invoker using(String contextName)
      Returns an Invoker that can be used to invoke code changing the context.
      Parameters:
      contextName - The name of the context.
      Returns:
      An invoker that invokes code using the specified context.