-
You must first add the
<SupportI18N> tag in the widget.xml , as shown below.
<Widget name="Widget name">
...
<SupportI18N supported="true" />
...
</Widget>
This <SupportI18N> xml tag allows all messages*.properties
files located in the widget folder to be loaded by the I18NLoader automatically.
-
Convert JSP pages using the
<i18n:message> tag from the i18n tag library.
<%@ taglib prefix="i18n" uri="http://www.exalead.com/jspapi/i18n"%>
The <i18n:message> tag is a subset of the Spring <spring:message> tag
(see http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/tags/MessageTag.html )
<i18n:message code="application.name" text="hola mundo" />
If the application.name key is undefined in all properties files, the text="" attribute is used as backup.
-
By convention, all metas are prefixed by
meta_ and facets by facet_ .
To get consistency when displaying meta and facets between all widgets, you must set the following:
<i18n:message code="meta_${metaName)}" text="${metaName}" />
<i18n:message code="facet_${fn:replace(category.path, ' ', '_')}" text="${category.description}" />
-
I18N can be used server-side like in a custom controller. To achieve
this, you need the
ServletContext and the HttpServletRequest ,
for example:
import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.web.context.support.WebApplicationContextUtils;
MessageSource messageSource = (MessageSource) WebApplicationContextUtils.getWebApplicationContext
(this.pageContext.getServletContext()).getBean("messageSource");
Locale locale = RequestContextUtils.getLocale((HttpServletRequest) this.pageContext.getRequest());
String str = I18NLoader.getMessage(messageSource, "application.name", "hola mundo", locale);
System.out.println(str);
|