Programmer : Mashup Programmer : Customizing the Mashup UI : Customizing the Mashup UI Language
 
Customizing the Mashup UI Language
 
About Internationalization features
Set default language
Add a new language
Manage I18N for multiple applications
Develop with I18N
This section describes how to customize the UI language using I18n.
About Internationalization features
Set default language
Add a new language
Manage I18N for multiple applications
Develop with I18N
About Internationalization features
Text labels and headings can be externalized into resource bundles, allowing the Mashup UI internationalization features to automatically display web pages in the appropriate language.
Three resource bundle files are used:
messages_en.properties for English,
messages_fr.properties for French,
and messages.properties, the default used if no other file is found.
The following files contain key-value pairs representing text for the web pages in different languages, for example:
messages_en.properties with application.name=hello world
messages_fr.properties with application.name=bonjour monde
messages.properties with application.name=hello world
Important: All properties defined in the widget's messages*.properties (/WEB-INF/jsp/widgets/*/messages*.properties) will override global properties defined in /WEB-INF/i18n/messages*.properties. The override mechanism is case-sensitive.
Set default language
You can change the Mashup UI default language in the product configuration. For example, to change the default language to French, set the value to fr.
1. Go to <INSTALLDIR>/sdk/java-mashupui/project/war/WEB-INF/ directory.
2. Edit the 360-search-ui.xml file.
3. To set a default language:
a. Uncomment the defaultLocale property
b. Set its value to the ISO language of your choice.
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<!--<property name="defaultLocale" value="en"/>-->
...
</bean>
Note: If necessary, you can also specify the country code of the language. For example, en_US represents U.S. English.
4. Save and close the file.
5. Go to Administration Console > Home page and restart the search server in the list of Processes.
Add a new language
We recommend maintaining all UI labels in a centralized messages_<ISO NAME .properties file. Changing labels using the Debug mode I18n tool, as described in Using the Mashup Builder Developer Tools, is not recommended, as it saves changes in another file.
Do not configure your internationalization resources in the application.properties file.
Editing the messages*.properties located in <INSTALLDIR>/sdk/java-mashupui/project/war/WEB-INF/i18n/, will impact the whole Mashup UI.
To make a change for a specific widget only (for example, change a specific meta label), edit the messages*.properties file located in the widget’s folder. The widget-specific file will override the global one.
Create a new *.properties file
1. Go to <INSTALLDIR>/sdk/java-mashupui/project/war/WEB-INF/i18N
2. Copy the message.properties file to create a new messages_<ISO NAME >.properties file.
Configure the UI labels
1. Edit the messages_<ISO NAME .properties file
2. Edit the existing meta or facet label value you want to display in the UI.
3. To add a new meta, prefix it by meta_ and use the following format: meta_<new_meta>=<UI label> For example, meta_publicurl = Public URL
4. To add a new facet, prefix it by facet_ and use the following format: facet_<facet_Root>=<UI label> For example, facet_Top/classproperties/file_folder=File folder
5. Save and close the file.
6. Go to Administration Console > Home page and restart the search server in the list of Processes.
Manage I18N for multiple applications
If you have multiple Mashup UI applications made with a single Exalead CloudView instance, use the MashupI18n.xml file of each application to control its localization.
1. Go to the <DATADIR>/config/360/applications/<app-name>/*
2. Edit the MashupI18n.xml file of the application as needed. The following sample shows an application with two languages.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MashupI18N xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
fallbackOnNormalizedForm="true" xsi:noNamespaceSchemaLocation="">
<MessageList lang="fr">
<Message message="Suggestions activées" code="noresults.suggestionEnabled"/>
</MessageList>
<MessageList lang="en">
<Message message="Suggestions enabled" code="noresults.suggestionEnabled"/>
</MessageList>
</MashupI18N>
Develop with I18N
This procedure gives the main steps to develop your own I18N features.
1. 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.
2. 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.namekey is undefined in all properties files, the text=""attribute is used as backup.
3. 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}" />
4. 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);