public class MessageLocaleHelper extends Object
Locale
of the
preferred (or secondary) Language for the user stored in
UIPreferencesSubProfile
. Then it can be used as normal messages
class, to retrieve the correct internationalized messages for the given user.Constructor and Description |
---|
MessageLocaleHelper(ModuleContext mc,
UIPreferencesSubProfile uiPreferencesSubprofile,
List<URL> urlList)
This constructor is to be used when the
UIPreferencesSubProfile
is already available, IE: by the DialogManager. |
MessageLocaleHelper(ModuleContext mc,
User user,
List<URL> urlList)
This constructor should be used by Applications.
|
Modifier and Type | Method and Description |
---|---|
Locale |
getSelectedMessageLocale()
Get the selected Locale for the messages.
|
String |
getString(String key)
Get a string in internationalization Messages file.
|
String |
getString(String key,
String[] substitutions)
Like
getString(String) , This method will get
the internationalization string for a given key. |
Locale |
getUserLocaleFromPreferredLanguage()
Get the language for the user.
|
void |
reloadMessages()
Reloads the messages.
|
public MessageLocaleHelper(ModuleContext mc, User user, List<URL> urlList) throws Exception
ArrayList list = new ArrayList();
list.add(getClass().getClassLoader().getResource("messages.properties"));
list.add(new File(CONFIG_FOLDER, "messages.properties").toURI().toURL());
list.add(new URL("Form_Resource_Server"));
//list.add(Other sources, for example a web server hosting these files);
MessageLocaleHelper messages = new MessageLocaleHelper(mc, user, list);
...
messages.getString("welcomeScreen.sayHello");
mc
- The ModuleContext
to enable logging and service call.user
- The User
to address the messages.urlList
- the list of alternative URL
locations for messages.Exception
MessageLocaleHelper#reloadMessages()}
public MessageLocaleHelper(ModuleContext mc, UIPreferencesSubProfile uiPreferencesSubprofile, List<URL> urlList) throws Exception
UIPreferencesSubProfile
is already available, IE: by the DialogManager.mc
- uiPreferencesSubprofile
- urlList
- Exception
MessageLocaleHelper#reloadMessages()}
public void reloadMessages() throws Exception
Exception
public final Locale getUserLocaleFromPreferredLanguage()
Locale
from the preferred (or if preferred not found
secondary) language for the user stored in
UIPreferencesSubProfile
.public final Locale getSelectedMessageLocale()
public final String getString(String key)
key
- the key for the stringpublic String getString(String key, String[] substitutions)
getString(String)
, This method will get
the internationalization string for a given key. Aditionally it will
subsitude the variables defined like "{n}" with the String in the index n
of the substitutions parameter. key=page \{0\} of \{1\}
MessageLocaleHelper
mlh = ...
mlh.getString("key",new String[]{"1","10"});
will return: "page 1 of 10"
key
- substitutions
- Copyright © 2018 universAAL Consortium. All rights reserved.