Java Reference
In-Depth Information
We've seen how to translate the three types of text (form field labels,
error/information messages, and free-form text). Lather, rinse, and re-
peat for each page, and you have a fully translated French webmail
application! Well, almost. The only thing we haven't seen so far is how
to localize certain types of input controls, so let's discuss them briefly.
Localizing Radio Buttons
In the previous chapter, we added radio buttons for the gender in the
contact form:
Stripes doesn't generate labels for radio buttons; they are just text after
the <s:radio> tag. You can use the <fmt:message> tag and use the
value of the gender object with ${gender} to build the key:
Download email_20/web/WEB-INF/jsp/contact_form.jsp
<c:forEach var="gender" items="${actionBean.genders}">
<s:radio name="contact.gender" value="${gender}"/>
<fmt:message key="${prefix}.${gender}"/>
</c:forEach>
Now you can put the text in the resource bundles as follows:
Download email_20/res/StripesResources.properties
stripesbook.action.ContactFormActionBean.Female=Female
stripesbook.action.ContactFormActionBean.Male=Male
Download email_20/res/StripesResources_fr.properties
stripesbook.action.ContactFormActionBean.Female=F\u00e9minin
stripesbook.action.ContactFormActionBean.Male=Masculin
The radio buttons are now translated:
Localizing Select Boxes
For select boxes with options generated by Stripes with <s:options-
enumeration>, <s:options-collection>, or <s:options-map>, you can
add entries in the resource bundle with the keys that Stripes uses to
look up localized labels. For example, we used <s:options-collection>
to render a select box with the list of Folder objects.
 
 
Search WWH ::




Custom Search