Interface LocalizationService
A service for obtaining ResourceBundle
s from the repository.
The ResourceBundle
s are located at /hippo:configuration/hippo:translations.
ResourceBundle
s are identified by a combination of a name and a Locale
.
ResourceBundle
resolution is implemented as follows. A Locale is interpreted to have
three levels of identity, which from least to most specific are: language, country, and variant.
These may not all be specified, only the least specific locale identifier, the language is mandatory.
When a ResourceBundle
is requested from the service, first an exact match is attempted, i.e.
a ResourceBundle
is searched that matches the full identity of the given Locale
.
If an exact match is not found a less exact match is attempted.
For example, if the ResourceBundle
for the Locale
th_TH_TH
is requested, first an exact match is attempted, if no such
ResourceBundle
exists one less specific ResourceBundle
is searched, i.e. th_TH
,
and if that also does not yield a result, the ResourceBundle
for the th
locale is looked up.
Finally, if still no ResourceBundle
is found, a ResourceBundle
with that name for the
DEFAULT_LOCALE
is returned if one exists.
In the same way, according to the same criteria of decreasing specificity of identity, ResourceBundle
s
are linked in a fallback hierarchy: If the ResourceBundle
matching the exact identity of th_TH_TH
does not yield a result for a specific ResourceBundle.getString(String)
, the implementation falls back on
a match higher up in the hierarchy: first the ResourceBundle
for th_TH
is attempted (if it exists)
all the way up to the default bundle.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Locale
The defaultLocale
this service uses as fallback when theResourceBundle
in the requested Locale is not available.static final String
The root path in the repository whereResourceBundle
s are stored. -
Method Summary
Modifier and TypeMethodDescriptiongetResourceBundle
(String name, Locale locale) Get aResourceBundle
from the repository by name andLocale
.
-
Field Details
-
TRANSLATIONS_PATH
The root path in the repository whereResourceBundle
s are stored.- See Also:
-
DEFAULT_LOCALE
The defaultLocale
this service uses as fallback when theResourceBundle
in the requested Locale is not available.
-
-
Method Details
-
getResourceBundle
Get aResourceBundle
from the repository by name andLocale
. The name of a resource bundle is path relative to theTRANSLATIONS_PATH
where the path elements are separated by periods (".") instead of forward slashes. ALocale
object identifies theResourceBundle
among the bundles identified by same path. If theResourceBundle
for the requested locale is not available the implementation tries to return theResourceBundle
for the defaultLocale
identified by the same name.- Parameters:
name
- the name of theResourceBundle
locale
- the locale of theResourceBundle
- Returns:
- the
ResourceBundle
identified by thename
andlocale
, theDEFAULT_LOCALE
if the requested locale is not available ornull
if no defaultResourceBundle
with that name exists either.
-