Class L10NImpl

java.lang.Object
ch.tocco.nice2.textresources.impl.i18n.L10NImpl
All Implemented Interfaces:
L10N

@Component public class L10NImpl extends Object implements L10N
  • Constructor Details

    • L10NImpl

      public L10NImpl(org.slf4j.Logger log)
  • Method Details

    • setContexts

      @Autowired public void setContexts(List<ContextContribution> contexts)
    • setSystemLocale

      public void setSystemLocale(Locale systemLocale)
    • systemLocale

      public Locale systemLocale()
      Description copied from interface: L10N
      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`.
      Specified by:
      systemLocale in interface L10N
      Returns:
      The system locale.
    • fallbackLocale

      public Locale fallbackLocale()
      Description copied from interface: L10N
      Gets the fallback locale for the thread's current context.
      Specified by:
      fallbackLocale in interface L10N
      Returns:
      The fallback locale.
    • fallbackLocale

      public Locale fallbackLocale(@Nullable @Nullable String contextName)
      Description copied from interface: L10N
      Gets the fallback locale for the specified context.
      Specified by:
      fallbackLocale in interface L10N
      Parameters:
      contextName - The context or `null` for the current context.
      Returns:
      The fallback locale.
    • availableLocales

      public Set<Locale> availableLocales()
      Description copied from interface: L10N
      Gets the available locales for the thread's current context ordered by their preference.
      Specified by:
      availableLocales in interface L10N
      Returns:
      A Set of all available locales.
    • availableLocales

      public Set<Locale> availableLocales(@Nullable @Nullable String contextName)
      Description copied from interface: L10N
      Gets the available locales for the specified context ordered by their preference.
      Specified by:
      availableLocales in interface L10N
      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

      public Set<L10N.Context> availableContexts()
      Description copied from interface: L10N
      Gets the available contexts.
      Specified by:
      availableContexts in interface L10N
      Returns:
      A Set of available contexts.
    • currentLocale

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

      public L10N.Context currentContext()
      Description copied from interface: L10N
      Gets the current context.
      Specified by:
      currentContext in interface L10N
      Returns:
      The current context.
    • bestLocaleFor

      public Locale bestLocaleFor(List<Locale> requested)
      Description copied from interface: L10N
      Gets the best available locale for the specified list of requested locales based on the thread's current context.
      Specified by:
      bestLocaleFor in interface L10N
      Parameters:
      requested - The list of preferred locales.
      Returns:
      The best available locale for the requested locale.
      See Also:
    • bestLocaleFor

      public Locale bestLocaleFor(List<Locale> requested, @Nullable @Nullable String contextName)
      Description copied from interface: L10N
      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.
      Specified by:
      bestLocaleFor in interface L10N
      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

      public ch.tocco.nice2.textresources.impl.i18n.L10NImpl.Invoker using(Locale locale)
      Description copied from interface: L10N
      Returns an Invoker that can be used to invoke code using the specified locale.
      Specified by:
      using in interface L10N
      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

      public ch.tocco.nice2.textresources.impl.i18n.L10NImpl.Invoker using(Locale locale, String contextName)
      Description copied from interface: L10N
      Returns an Invoker that can be used to invoke code changing the context and locale.
      Specified by:
      using in interface L10N
      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

      public ch.tocco.nice2.textresources.impl.i18n.L10NImpl.Invoker using(String contextName)
      Description copied from interface: L10N
      Returns an Invoker that can be used to invoke code changing the context.
      Specified by:
      using in interface L10N
      Parameters:
      contextName - The name of the context.
      Returns:
      An invoker that invokes code using the specified context.