Class DefaultStrings
java.lang.Object
com.lokalized.DefaultStrings
- All Implemented Interfaces:
LocaleMatcher
,Strings
Default implementation of a localized string provider.
It is recommended to use a single instance of this class across your entire application.
In multi-tenant systems like a web application where each user might have a different locale,
your localeSupplier
might return the locale specified by the current request, e.g.
from a set of Locale.LanguageRange
parsed from the Accept-Language
header.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder used to construct instances ofDefaultStrings
.static enum
Strategies for handling localized string lookup failures. -
Method Summary
Modifier and TypeMethodDescriptionbestMatchFor
(List<Locale.LanguageRange> languageRanges) Given a list of language ranges (e.g. as parsed from anAccept-Language
HTTP request header), determine the best-matching localized strings file's locale.bestMatchFor
(Locale locale) Given a language range, determine the best-matching localized strings file's locale.Gets a localized string for the given key.Gets a localized string for the given key.Gets the strategy for handling string lookup failures.Gets the fallback locale.Gets the locale supplier.Gets the set of localized strings for each locale.Gets the mapping of a mapping of an ISO 639 language code to its ordered "tiebreaker" fallback locales.
-
Method Details
-
get
Description copied from interface:Strings
Gets a localized string for the given key.If no localized string is available, the key is returned.
-
get
Description copied from interface:Strings
Gets a localized string for the given key.If no localized string is available, the key is returned.
-
bestMatchFor
Description copied from interface:LocaleMatcher
Given a language range, determine the best-matching localized strings file's locale.- Specified by:
bestMatchFor
in interfaceLocaleMatcher
- Parameters:
locale
- the locale for which to find the best match.- Returns:
- the best-matching locale, not null
-
bestMatchFor
Description copied from interface:LocaleMatcher
Given a list of language ranges (e.g. as parsed from anAccept-Language
HTTP request header), determine the best-matching localized strings file's locale.- Specified by:
bestMatchFor
in interfaceLocaleMatcher
- Parameters:
languageRanges
- the ordered list of language ranges for which to find the best match.- Returns:
- the best-matching locale, not null
-
getLocalizedStringsByLocale
Gets the set of localized strings for each locale.- Returns:
- the set of localized strings for each locale, not null
-
getLocaleSupplier
Gets the locale supplier.- Returns:
- the locale supplier, not null
-
getTiebreakerLocalesByLanguageCode
-
getFailureMode
Gets the strategy for handling string lookup failures.- Returns:
- the strategy for handling string lookup failures, not null
-
getFallbackLocale
Gets the fallback locale.- Returns:
- the fallback locale, not null
-