Interface LocaleResolverService
- All Known Implementing Classes:
L10NCompatibleLocaleResolverServiceImpl
public interface LocaleResolverService
Service for dealing with
locales
and languages.
The service provides access to:
- the project's languages
- the project's default language
- the project's default locale
- the contributed locale resolvers for the current user, which may read his locale from places like the profile, request parameter, etc.
-
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.
-
Method Details
-
getDefaultLocale
Locale getDefaultLocale()- Returns:
- the project-specific default locale
-
getDefaultLanguage
String getDefaultLanguage()Returns the project-specific default language.- Returns:
- 2-letter iso code in lower case eg 'fr'.
-
getAvailableLanguagesAsString
Returns the project-specific available languages.- Returns:
- Unmodifiable, not empty, contains at least one 2-letter iso code in lower case.
-
getBestLocale
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.
- Parameters:
preferredLocales
- May be empty. Iteration order matters, so use a LinkedHashSet or NavigableSet.
-
getLocaleForGui
Locale getLocaleForGui()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.
-
getPreferredLocales
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
iteratePreferredLocales()
and stopping early.- See Also:
-
iteratePreferredLocales
Loops the preferred locales of the current user.Compared to
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.- See Also:
-
completeWithSystemDefaults
Adds the systems defaults to empty fields of a locale string- Parameters:
localeString
- a locale string (e.g. as received from DB)- Returns:
- a locale for the localeString with added system defaults
-
completeWithSystemDefaults
Adds the system defaults to empty fields of a locale. This method does not overwrite any of the settings of the locale- Parameters:
locale
- a locale- Returns:
- a locale with fields filled with system defaults.
-