Wednesday Feb 11, 2009

Web Space Server - Localization

We are back after hectic one month or so ... It was one of the interesting and challenging period ... So much of excitement so much to do less time .. pressure ... etc etc ... But but , Finally its out .. On Time ... Leaving behind happy faces :-).

Yeah , I'm talking about  Sun Glassfish Web Space Server 10.0 release (derived from Liferay 5.2) , first release from Sun  after one of the unique development relationship between Sun and Liferay .

 To get more details .. Refer this blog on Portal Post .

Download link.

Let move to topic of blog i.e Localization (L10n).

FAQ 1.0 : How can I get localized version Web Space Server ?

To simplify customer experience , there is not extra steps to get localized version. It has been bundled in by default. So when you download install Web Space Server , You by default get localization support.

FAQ 2.0 : In which languages Web Space Server is available ?

Web Space Server is localized out-of-box in 22 languages , out of which Sun provides localization support for Japanese (ja) and Simplified Chinese (zh_CN). Remaining languages are community driven

FAQ 4.0 : Can I add new Language ?

Yes ,Web Space Server is Internationalized. Allow you to add new languages which is not shipped out of box.

Refer Localization section of Admin Guide for exact steps of how to do the same.

FAQ 5.0 : Where I can get more information about Localization ?

Refer Localization section of Admin Guide

FAQ 6.0 :  If you have Ask Me :-) ...

Beginning ... Focus ... Success ... Beginning  ............ (Life goes on )



Monday Dec 22, 2008

How to configure WebSynergy/Liferay on MySQL for UTF-8

Recently I was using WebSynergy with default database (HSQL in memory) and all my localized data were just doing fine. Happily making trip to UI to Database and vice versa. Then when I switch my database to MySQL , everything went haywire , Data turned in to ??? (okie let me be clear , when Data turns to ??? its mostly case of wrong encoding).

It was small challenge for me to get it right on MySQL. Challenge is Challenge. 

I have explored on MySQL side and found that , it very easy to create database which can handle UTF-8 character (by default it comes in ASCII). so create database to handle WebSynergy data with UTF-8 encoding.

CREATE DATABASE mydb DEFAULT CHARACTER SET utf8; 

 :-) .. am I done .. I did a check but situation refuse to change .. there was something else also needs to be done. To call it done.

Database is in UTF-8 but communication between Portal and Database was not in UTF-8.  How to enable that?

I have found a simple straight way.

Add following two properties to "LiferayPool" and "JIRAPool".

useUnicode=true
characterEncoding=utf8 

.. are we done .. Yes , we are done. Enjoy the advantages of MySQL with WebSynergy in language you want to communicate.

"No Problem is small problem until you know the solution" 




Friday Sep 19, 2008

How to do Internationalization(I18n) and Localization(L10n) in Liferay , WebSynergy

Hi .. I'm Back .. was busy exploring more on I18n of Liferay

This blog will describe how to do i18n in development environment of Liferay and WebSynergy(now on will be referred as Portal). Also while adding new Portlets to Portal how to leverage existing Portal UI tag lib and Language utility class for I18n in quicker and easier way.

Resource Bundle

Key Points

  • Portal has only One Resource Bundle for all the components . Refer my previous entry for more details
  • Location in workspace : portal-impl/content/Language.properties
  •  Location in Installation :
          • Unjar portal-impl.jar (it will be lib directory of workspace)
          • Language.properties file will be found in content directory
  • Either you can directly modify this Language.properties OR (most preferred way) to create Language-ext.properties and bundle in same jar. Because if you directly modify Language.properties then you need to manually take care of adding your changes during updated to latest default Language.properties which you will get in install.


Convention to add messages in Resource bundle

  1. This file follows same convention as defined for Liferay's default Language.properties liferay/trunk/portal-impl/content/Language.properties.
  2. Each property should key should be prefix by your portlet name .
  3. File is well-defined in to various section descried below
    1. Portlet Titles : Portlet titles of your portlet. - NEEDS TO VERIFY
      1. Portlet title key should be constructed as javax.portlet.title.PORTLETNAME , where PORTLETNAME is name which you have mentioned in portlet-name tag of your portlet.xml.
        ex. java.portlet.title.FriendsPortlet=Friends Widget
      2. This feature is yet to test (by me) so you can use Portlet specific resource bundle to define title.
    2. Category Titles : Category titles which appears in "Add Application" list
      1. It should be prefix by category.CATEGORYNAME where CATEGORYNAME is name of category.
      2. ex. category.admin=Admin
      3. this category key will be used in liferay-display.xml of portlet which are part of category
        1. ex. <display>
              <category name="category.cms">
                  <category name="category.alfresco">
                      <portlet id="1" />
                  </category>
              </category>
          </display>
    3. Model resources : Model resources should be prefix by model.
      1. ex. model.resource.com.liferay.portal.model.Group=Community
      2. ex. model.resource.com.liferay.portlet.blogs.model.BlogsEntry=Blogs Entry
    4. Action Items : Messages which used as action items. Should be prefix by action.. All words are in uppercase. Word seperator is _
      1. ex. action.ADD_ARTICLE=Add Article
    5. Messages : General messages
      1. Key should be construed from Message. ex Key for message My Friends will be my-friends
      2. Use x for dynamic parameter in messages ex. Key for message This {0} is great will be this-x-is-great
      3. If message is very long (ex. more then 15 words) you can use small key but make sure it is giving information about message
        ex. an-applet-version-of-the-editor-is-also-available=An applet version of the editor is also available. It is a heavier but more user friendly editor that provides colorized text, search and replace, and other functionality. You can choose to use that editor by editing your portlet preferences.
  4. Keep each section of file in ascending order

How to use liferay ui taglib to fetch messages in JSP/Java Script

There are various ways to fetch message from resource bundle.

NOTE : All the following approach will consider Language.properties as Resource bundle and will fetch messages form there based on locale. However following methods support -ext mechanism i.e It will first look in Language-ext.properties file.

  1. liferay-ui:message tag
  2. LanguageUtil class
  3. UnicodeLanguageUtil class
  4. Other liferay ui tags - I18n'ed

liferay-ui:message tag

  • For simple messages which does not have dynamic parameter use this tag
    ex. < liferay-ui:message key="my-friends"/ >
  • This tag internally calls LangaugeUtil class

LangaugeUtil class

LanguageUtil class has various formatter methods use them based on situation.

  • For messages which has dynamic parameter use following method. Make last argument as "true" if you want your parameter to be translated as well
    ex. <%= LanguageUtil.format(pageContext, "upload-a-gif-or-jpeg-that-is-x-pixels-tall-and-x-pixels-wide", new Object {"120", "100"}, false) %>
  • For messages which has html code along with parameter then use LangaugeWrapper as argument instead of Object
    ex.<%= LanguageUtil.format(pageContext, "your-account-with-login-x-is-not-active", new LanguageWrapper {new LanguageWrapper("", user.getFullName(), ""), new LanguageWrapper("< b >< i >", userLogin, "< /b >")}, false) %>

Other liferay ui tags and LanguageUtil class methods- I18n'ed

  • liferay-ui:icon-help - This tag is i18n'ed. You can use key value in message attribute of this tag
    • < liferay-ui:icon-help message="allow-dictionary-words-help"/ >
  • LanguageUtil.getTimeDescription - to get localized time descrption
    • <%= LanguageUtil.getTimeDescription(pageContext, _DURATIONSi? \* 1000) %>

UnicodeLanguageUtil Class

  • Use this class in Java Script in JSP pages
  • UnicodeLanguageUtil has similar method singature as found in LanguageUtil class.
  • ex. function copyFromLive() {

if (confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-copy-from-live-and-overwrite-the-existing-staging-configuration") %>')) { document. fm. <%= Constants.CMD %>.value = "copy_from_live"; submitForm(document. fm); } }

  • Also use in alert within jsp
  • ex2.
    " method="post" name=" fm" onSubmit="alert('<%= UnicodeLanguageUtil.get(pageContext, "please-be-patient") %>'); submitForm(this); return false;">

Import and define tag lib in your jsp or included jsp

  • <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
  • Import following classes
    • <%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
    • <%@ page import="com.liferay.portal.kernel.language.LanguageWrapper" %>
    • <%@ page import="com.liferay.portal.kernel.language.UnicodeLanguageUtil" %>

How to use liferay Language Utill classes to fetch messages in JAVA programs

In order to fetch localized messages in java program we will be using same Util classes which has been used in JSP/Java Script

  • LanguageUtil class
  • If your message does not have any dynamic parameter then use any of LanguageUtil.get(...,key) method. this method will fetch message assicated with key. There are various overloaded version of LanguageUtil.get are available , use desired get method based on situation.  Some of commonely used version of get method.
    • LanguageUtil.get(pageContext,key)
    • LanguageUtil.get(companyId,key) etc.
    • there are other overloaded version of get method is available. You need to use them based on your requirement.
    • Refer class "portal/trunk/portal-kernel/src/com/liferay/portal/kernel/language/LanguageUtil.java for details.
  • If your message has  dynamic parameter then use any of LanguageUtil.format(...,key,Object) method.  this method will fetch message assicated with key. There are various overloaded version of LanguageUtil.form are available , use desired format method based on situation.  Some of commonely used version of form method.
    • LanguageUtil.get(pageContext,key, object)
    • LanguageUtil.get(pageContext,key, new Object[])
    • there are other overloaded version of format method is available. You need to use them based on your requirement.
    • Refer class "portal/trunk/portal-kernel/src/com/liferay/portal/kernel/language/LanguageUtil.java for details.

How to use liferay Language Utill classes to fetch messages in Velocity templates

Portal uses velocity engine to create templates i.e. .vm files which are used to define layout and in themes.

  • Set Language Id : #set ($language_id = $user.getLanguageId()) in your init template.
  • You can use following syntex to fetch messages from Language.properties file
    • #language ("KEY-NAME")
  • Some places I have also seen usage of language util as follow.
    • $languageUtil.get($company_id, $locale, "add-application"))

There is also certain changes required in portlet.xml <resource-bundle> tag to allow container to fetch portlet title from common resource bundle. Watch out for this space , I will update it shortly. 

 Never shy away from re using stuff which already exists ... It gives more time to innovate...

About

Mahipalsinh Rana

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today