Thursday, June 2, 2016

Internationalization (i18n) in Liferay

Today we will discuss about Internationalization (i18n) in liferay. By default Liferay support English language. Here we add Hindi language support in our portlet. So lets start this Step by Step:-



Step 1:-Create Liferay Project and Portlet
Just create a Liferay project and then create a MVC portlet in it.

Step 2:-Create your Language.properties file
Now create a folder content inside docroot/WEB-INF/src .Create two files Language.properties and Language_hi_IN.properties and paste the content as:-

a)Language.properties
Welcome_Msg =Welcome to Liferayiseasy

b)Language_hi_IN.properties
Welcome_Msg =आपका स्वागत है LiferayisEasy में

Explanation:-
Here Language.properties file support English Language and Language_hi_IN.properties supports Hindi Language.For different languages you change the name of files accordingly.
Ex- For Spanish use Language_es.properties


Step 3:-Change view.jsp
Open view.jsp and paste this:-

view.jsp

Explanation:-
Here we are using <liferay-ui> tag for accessing our keys that are mention in our properties files.


Step 4:-Add resource bundle entry
Open portlet.xml and provide resourse bundle entry:-

<resource-bundle>content.Language</resource-bundle>

Now your portlet.xml become:-





Step 5:-Check output
First Go to Admin-->Control panel-->Portal Setting-->Display Setting(inside Miscellaneous) and add Hindi language to current languages.








Now add Language portlet(OOTB) and your custom portlet to page:-




Click on Indian Flag Symbol:-





Your text automatically chage to Hindi Language.

Note:-

If you don't want to use  Language portlet (OOTB) than you can directly mention Language_hi_IN in portlet.xml (Step 4).In this case only Hindi language is supported by your portlet.

Project Structure





Hope this will Help....

You can Download Source code from  Internationalization in Liferay.


Related Post:-


No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!