-
Notifications
You must be signed in to change notification settings - Fork 17
Retrieve messages
Pu Chen edited this page Oct 16, 2017
·
4 revisions
Grammaticus provides full functional message formatter which can be easily used to retrieve the messages defined in message XML files. Refer to Message files on how to define messages.
Once you have messages, entities(nouns), adjectives and articles defined for certain language, you could start to retrieve them.
Here is simple test case to demonstrate the function to retrieve a simple message from XML.
/**
* Test case to load English message set and validate the retrieved message.
*
* @throws MalformedURLException
* @throws IOException
*/
@Test
public void testEnglishMessage() throws MalformedURLException, IOException {
HumanLanguage language = LanguageProviderFactory.get().getLanguage(Locale.US);
String msg = getLabelSet(language, false).getString("Icons", "colorPicker");
assertTrue("Got the wrong message.", msg.equals("Choose a Color"));
}
Before running this code, please define related message(in labels.xml), entities and articles(in names.xml) for English first. Then put those file under de/ directory.
Message is defined as,
<iniFile>
<section name="Global">
<param name="activity">Create <A/> <activity/></param>
<param name="contact">Create <A/> <contact/></param>
</section>
</iniFile>
Example code to retrieve the message.
/**
* Test case to load English message with entities.
*
* @throws MalformedURLException
* @throws IOException
*/
@Test
public void testMessageWithEntity() throws MalformedURLException, IOException {
// English
HumanLanguage language = LanguageProviderFactory.get().getLanguage(Locale.US);
LabelSet ls = getLabelSet(language, false);
System.out.println(ls.getString("Global", "activity"));
System.out.println(ls.getString("Global", "contact"));
}
It will output following result.
Create An activity
Create A contact