Class I18N
java.lang.Object
io.github.belgif.rest.problem.i18n.I18N
Helper class for I18N (Internationalization).
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetLocalizedDetail(Class<? extends Problem> problemClass, Object... args) Get a localized detail string with key "[problem-class].detail" from the resource bundle "[problem-package].Messages".static StringgetLocalizedString(Class<?> context, String key, Object... args) Get a localized string from the resource bundle "[context-package].Messages".static StringgetLocalizedString(String key, Object... args) Get a localized string from the default Belgif resource bundle.static LocaleGet the locale of the current request.static booleanReturn whether I18N is enabled.static voidsetEnabled(boolean enabled) Enable or disable I18N.
-
Field Details
-
DEFAULT_LOCALE
The default locale: ROOT (=English). -
DEFAULT_BUNDLE
The Belgif default resource bundle.- See Also:
-
-
Method Details
-
getRequestLocale
Get the locale of the current request.- Returns:
- the locale of the current request
-
getLocalizedDetail
Get a localized detail string with key "[problem-class].detail" from the resource bundle "[problem-package].Messages".For example, for problem class = com.acme.custom.CustomProblem, the localized string with key "CustomProblem.detail" would be loaded from resource bundle "com.acme.custom.Messages".
- Parameters:
problemClass- the context classargs- the optional arguments that will be resolved withString.format(String, Object...)- Returns:
- the localized string
-
getLocalizedString
Get a localized string from the default Belgif resource bundle.- Parameters:
key- the keyargs- the optional arguments that will be resolved withString.format(String, Object...)- Returns:
- the localized string
-
getLocalizedString
Get a localized string from the resource bundle "[context-package].Messages".For example, for context class = com.acme.custom.CustomProblem, the localized string would be loaded from resource bundle "com.acme.custom.Messages".
- Parameters:
context- the context classkey- the keyargs- the optional arguments that will be resolved withString.format(String, Object...)- Returns:
- the localized string
-
setEnabled
public static void setEnabled(boolean enabled) Enable or disable I18N.- Parameters:
enabled- true to enable, false to disable
-
isEnabled
public static boolean isEnabled()Return whether I18N is enabled.- Returns:
- whether I18N is enabled
-