Class L10NCompatibleLocaleResolverServiceImpl
java.lang.Object
ch.tocco.nice2.textresources.impl.i18n.L10NCompatibleLocaleResolverServiceImpl
- All Implemented Interfaces:
LocaleResolverService
@Component
public class L10NCompatibleLocaleResolverServiceImpl
extends Object
implements LocaleResolverService
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncompleteWithSystemDefaults
(@Nullable String localeString) Adds the systems defaults to empty fields of a locale stringcompleteWithSystemDefaults
(@Nullable Locale locale) Adds the system defaults to empty fields of a locale.Returns the project-specific available languages.getBestLocale
(Set<Locale> preferredLocales) Returns the first Locale from preferredLocales that is provided by the current project.Returns the project-specific default language.Returns the gui locale for the current user to be used in the gui right now.Returns the preferred locales of the current user.Loops the preferred locales of the current user.void
setLocaleResolver
(List<LocaleResolver> localeResolvers)
-
Constructor Details
-
L10NCompatibleLocaleResolverServiceImpl
-
-
Method Details
-
getDefaultLocale
- Specified by:
getDefaultLocale
in interfaceLocaleResolverService
- Returns:
- the project-specific default locale
-
getDefaultLanguage
Description copied from interface:LocaleResolverService
Returns the project-specific default language.- Specified by:
getDefaultLanguage
in interfaceLocaleResolverService
- Returns:
- 2-letter iso code in lower case eg 'fr'.
-
getAvailableLanguagesAsString
Description copied from interface:LocaleResolverService
Returns the project-specific available languages.- Specified by:
getAvailableLanguagesAsString
in interfaceLocaleResolverService
- Returns:
- Unmodifiable, not empty, contains at least one 2-letter iso code in lower case.
-
getBestLocale
Description copied from interface:LocaleResolverService
Returns the first Locale from preferredLocales that is provided by the current project.Notes:
- Compares on language level only, it does not matter if and what Country/Variant the given Locales have.
- Falls back to the project default.
- //Caches the result.
- Specified by:
getBestLocale
in interfaceLocaleResolverService
- Parameters:
preferredLocales
- May be empty. Iteration order matters, so use a LinkedHashSet or NavigableSet.
-
getLocaleForGui
Description copied from interface:LocaleResolverService
Returns the gui locale for the current user to be used in the gui right now.It is guaranteed to be one of the project-offered gui locales, and falls back to the default one.
Note that this may differ from the user-configured gui locale, for example when a request comes in with an overriding locale.
- Specified by:
getLocaleForGui
in interfaceLocaleResolverService
-
getPreferredLocales
Description copied from interface:LocaleResolverService
Returns the preferred locales of the current user.Note: All locale resolvers are asked to return all their entries. Thus this call is more expensive than
LocaleResolverService.iteratePreferredLocales()
and stopping early.- Specified by:
getPreferredLocales
in interfaceLocaleResolverService
- See Also:
-
iteratePreferredLocales
Description copied from interface:LocaleResolverService
Loops the preferred locales of the current user.Compared to
LocaleResolverService.getPreferredLocales()
this has the advantage that you may abort early when you've find a good match. Then not all locale resolvers must be consulted.- Specified by:
iteratePreferredLocales
in interfaceLocaleResolverService
- See Also:
-
completeWithSystemDefaults
Description copied from interface:LocaleResolverService
Adds the systems defaults to empty fields of a locale string- Specified by:
completeWithSystemDefaults
in interfaceLocaleResolverService
- Parameters:
localeString
- a locale string (e.g. as received from DB)- Returns:
- a locale for the localeString with added system defaults
-
completeWithSystemDefaults
Description copied from interface:LocaleResolverService
Adds the system defaults to empty fields of a locale. This method does not overwrite any of the settings of the locale- Specified by:
completeWithSystemDefaults
in interfaceLocaleResolverService
- Parameters:
locale
- a locale- Returns:
- a locale with fields filled with system defaults.
-
setLocaleResolver
-