Java Reference
In-Depth Information
Download email_20/res/StripesResources_fr.properties
stripesbook.action.LoginActionBean.primaryEmailNotFound=\
Le courriel principal n''existe pas.
stripesbook.action.LoginActionBean.passwordIncorrect=\
Le mot de passe est incorrect.
The constructor for LocalizableError also accepts an optional list of para-
meters that replaces tokens starting at {2} . 2 For example, the error mes-
sage on the Register page for a username that is already taken uses the
LocalizableError class as follows:
Download email_20/src/stripesbook/action/RegisterActionBean.java
if (userDao.findByUsername(username) != null ) {
errors.addGlobalError(
new LocalizableError("usernameAlreadyTaken", username));
}
The messages are now translated in the resource bundles:
Download email_20/res/StripesResources.properties
stripesbook.action.RegisterActionBean.usernameAlreadyTaken=\
{2} is already taken.
Download email_20/res/StripesResources_fr.properties
stripesbook.action.RegisterActionBean.usernameAlreadyTaken=\
{2} est d\u00e9j\u00e0 pris.
Making information messages translatable works in a similar way. In-
stead of using the SimpleMessage class and hard-coded text, use Localiz-
ableMessage and resource bundle keys:
Download email_20/src/stripesbook/action/ContactFormActionBean.java
public Resolution save() {
Contact contact = getContact();
getContactDao().save(contact);
getContext().getMessages().add(
new LocalizableMessage(getClass().getName()+".contactSaved",
contact)
);
return new RedirectResolution(ContactListActionBean. class );
}
@DontValidate
public Resolution cancel() {
getContext().getMessages().add(
new LocalizableMessage(getClass().getName()+".actionCancelled")
);
return new RedirectResolution(ContactListActionBean. class );
}
2. Remember that {0} and {1} are reserved for the field name and the value entered by
the user.
 
 
Search WWH ::




Custom Search