public class I18N extends Object
ApplicationContext
that uses the locale of the current UI to lookup messages. Use it like this:
@VaadinUI
public class MyUI extends UI {
@Autowired I18N i18n;
...
void init() {
myLabel.setCaption(i18n.get("myLabel.caption"));
}
}
Please note, that you also need to configure a MessageSource inside your application context
that contains all the messages to resolve.| Constructor and Description |
|---|
I18N(ApplicationContext applicationContext) |
| Modifier and Type | Method and Description |
|---|---|
String |
get(String code,
Object... arguments)
Tries to resolve the specified message for the current locale.
|
Locale |
getLocale()
Gets the locale of the current Vaadin UI.
|
String |
getWithDefault(String code,
String defaultMessage,
Object... arguments)
Tries to resolve the specified message for the current locale.
|
String |
getWithLocale(String code,
Locale locale,
Object... arguments)
Tries to resolve the specified message for the given locale.
|
boolean |
isRevertToDefaultBundle()
Returns whether
I18N will try the default bundle if a message cannot be resolved for the
current locale. |
void |
setRevertToDefaultBundle(boolean revertToDefaultBundle)
|
@Autowired public I18N(ApplicationContext applicationContext)
applicationContext - the application context to read messages from, never null.public boolean isRevertToDefaultBundle()
I18N will try the default bundle if a message cannot be resolved for the
current locale. By default, this is true.public void setRevertToDefaultBundle(boolean revertToDefaultBundle)
public String get(String code, Object... arguments)
code - the code to lookup up, such as 'calculator.noRateSet', never null.arguments - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}"), or null if none.MessageSource.getMessage(String, Object[], java.util.Locale),
getLocale()public String getWithLocale(String code, Locale locale, Object... arguments)
code - the code to lookup up, such as 'calculator.noRateSet', never null.arguments - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}"), or null if none.locale - The Locale for which it is tried to look up the code. Must not be nullIllegalArgumentException - if the given Locale is nullMessageSource.getMessage(String, Object[], java.util.Locale),
Localepublic String getWithDefault(String code, String defaultMessage, Object... arguments)
code - the code to lookup up, such as 'calculator.noRateSet', never null.defaultMessage - string to return if the lookup fails, never null.arguments - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}"), or null if none.defaultMessage if the lookup fails.MessageSource.getMessage(String, Object[], String, java.util.Locale),
getLocale()public Locale getLocale()
null.AbstractComponent.getLocale(),
Locale.getDefault()Copyright © 2016. All rights reserved.