Localization in liferay.

Liferay support several localization.You can easily localize your application to support more than one language.

You can override existing language key and also add language key in hook.
Configure your hook as below.

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">

<hook>
    <portal-properties>portal.properties</portal-properties>
    <language-properties>content/Language_en.properties</language-properties>
    <language-properties>content/Language_nl.properties</language-properties>
    <language-properties>content/Language_pt.properties</language-properties>
</hook>

Here above hook show three language(nl,pt and en) support.

Add above three language files in src/content folder.

You can also say in hook, how many languages support by your application.
For do so you need to customize portal.properties.
Add portal.properties in src folder of hook.
and add below lines >

locales.enabled=nl_NL,en_US,pt_PT
locales=nl_NL,en_US,pt_PT

Here above lines say, your application support three language nl,en and pt.

There  several location where need to use language key.
  1. From jsp page
  2. From java class
  3. From javascript file
  4. From web content template


1. jsp files:
            You can  use <liferay-ui message> tag if you prefer to use taglib.Taglib definition can be found on /util-taglib/src/META-INF/liferay-ui.tld file.For this you need to import  liferay-ui taglib at jsp page start.

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

Example: <liferay-ui:message key='conversation'/>

2. java class:
             For java classes, you can get localized text / content by using com.liferay.portal.kernel.language.LanguageUtil class. There are a few methods there to get localized text, for example :

    LanguageUtil.get(locale, key);
 

3. From javascript file:

                        Liferay  make our life easier by providing javascript API for this. You can just call

Liferay.Language.get("your-language-key")
This javascript API is defined in portal-web/docroot/html/js/liferay/language.js file.

4.From web content template:

In velocity template you can use language key as below>
                                        #language('your-key')

Enjoy....
 
             






Comments

Popular posts from this blog

How to run ofbiz as ubuntu Service.

JPA vs Spring JPA vs Spring Data JPA vs Hibernate

Java Array Interview Questions for Entry-Level Developers Part 01