Liferay currently supports about 40 languages out of the box. The full list of translated languages and their progress may be seen here: http://translate.liferay.com/pootle/
What about adding a language to Liferay that is not one of the ones supported? The Cherokee language was chosen for this article along with Liferay v6.1.
1. In the Liferay web.xml (webapps/ROOT/WEB-INF/web.xml) a few lines will be needed to ensure that the new language will be recognized by the server:
To add a new language, in this case Cherokee, add the following two entries to the servlet-mappings:
<servlet-mapping> <servlet-name>I18n Servlet</servlet-name> <url-pattern>/chr/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>I18n Servlet</servlet-name> <url-pattern>/chr_US/*</url-pattern> </servlet-mapping>
The first entry is just for Cherokee itself. Since Cherokee is only native to the United States the second entry should not be needed and was added for demonstration only.
2. Then find the url-patterns in your web.xml and add the following entries:
These url-patterns tell liferay that the url will be http://mydomain.com/language/c/portal/everythingElse – for example, http://mydomain.com/en/myPage or http://mydomain.com/chr/myPage.
In order to test this out, the following restrictions were added to the portal-ext.properties file:
In this way, the user would only see Arabic, English, Cherokee, Cherokee (US), and Japanese in the Language portlet added to the home page.
3. Two new properties files were added to the portlet in the resources directory: Langauge-ext_chr.properties, and Language-ext_chr_US.properties
4. The final step needed to display this new language, if the language is Unicode (as Cherokee is) is to add the following to the top of your portlet:
<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %>
Here is the final code for this demonstration:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %><%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" language="java" %>
spring:message tag -- <spring:message code="displayName"/><br/><br/> liferay-ui:message tag -- <liferay-ui:message key="displayName" /><br/><br/>
Cherokee display (with escaped unicode):
Cherokee display (with straight unicode):
Note: spring:message tags — you must use native2ascii to convert the language to escaped unicode (u+xxxx) before using them and the default ResourceBundleMessageSource and not ReloadableResourceBundleMessageSource. However, if you are attempting to use native2ascii on Cherokee it will not work. Your conversion will turn Cherokee into multibyte representation.
Note: liferay-ui:message tags – as stated above, as of 6.1 unicode is permitted inside the properties file (just as Grails has); before Liferay v6.1 you are still required to convert the unicode to escaped unicode (u+xxxx) before using.