Can I write my own JSP tag to take the i18n message key and display the translation phrase for this request?
Usually in JSP / JSTL I do:
<fmt:message key="${messageKey}"><fmt:param>arg1</fmt:param></fmt:message>
And I get the translation phrase. Now I need to do the following (there is a good reason for this):
<custom:translate key="${messageKey}" arg="arg1"/>
But I do not know how to search for a translation in the code of a user tag. The TagSupport base class provides a pageContext from which I can get a ServletRequest that has a Locale ... but how can I look for a translation for a key?
I use Spring 3.0 and in my application-context.xml, I defined the source ReloadableBundleMessageSource, so I can call:
messageSource.getMessage(
key, new Object[] {arg}, pageContext.getRequest().getLocale()
);
, messageSource , ? , ? , messageSource .