Interface LocalizationService
-
public interface LocalizationService
A service for obtaining
ResourceBundle
s from the repository. TheResourceBundle
s are located at /hippo:configuration/hippo:translations.ResourceBundle
s are identified by a combination of a name and aLocale
.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 aResourceBundle
is requested from the service, first an exact match is attempted, i.e. aResourceBundle
is searched that matches the full identity of the givenLocale
. If an exact match is not found a less exact match is attempted.For example, if the
ResourceBundle
for theLocale
th_TH_TH
is requested, first an exact match is attempted, if no suchResourceBundle
exists one less specificResourceBundle
is searched, i.e.th_TH
, and if that also does not yield a result, theResourceBundle
for theth
locale is looked up. Finally, if still noResourceBundle
is found, aResourceBundle
with that name for theDEFAULT_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 theResourceBundle
matching the exact identity ofth_TH_TH
does not yield a result for a specificResourceBundle.getString(String)
, the implementation falls back on a match higher up in the hierarchy: first theResourceBundle
forth_TH
is attempted (if it exists) all the way up to the default bundle.
-
-
Field Summary
Fields Modifier and Type Field Description static Locale
DEFAULT_LOCALE
The defaultLocale
this service uses as fallback when theResourceBundle
in the requested Locale is not available.static String
TRANSLATIONS_PATH
The root path in the repository whereResourceBundle
s are stored.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ResourceBundle
getResourceBundle(String name, Locale locale)
Get aResourceBundle
from the repository by name andLocale
.
-
-
-
Field Detail
-
TRANSLATIONS_PATH
static final String TRANSLATIONS_PATH
The root path in the repository whereResourceBundle
s are stored.- See Also:
- Constant Field Values
-
DEFAULT_LOCALE
static final Locale DEFAULT_LOCALE
The defaultLocale
this service uses as fallback when theResourceBundle
in the requested Locale is not available.
-
-
Method Detail
-
getResourceBundle
ResourceBundle getResourceBundle(String name, Locale locale)
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.
-
-