Tuesday 7 May 2013

Internationalization in Liferay + Zk Portlet


Internationalization in Zk+liferay Portlet

We have already created one simple portlet. Now we gonna build one by one functionality on top of that.


In this post we gonna see how internationalization could be done in zk+liferay portlet.

So you can refer earlier post for making a simple portlet.

For adding internationalization follow below steps:

1)Create zk-label.properties file and also create /docroot/properties folder and put zk-label.properties file in that folder which you have created.

 Content of zk-label.properties:

 #--------------------#  
 # Label for zkdemo #  
 #--------------------#  
 username=Username  
 password=Password  
 message=Available Language : ${number}  

2)Add below entry in zk.xml under <zk> tag.

  <system-config>  
        <label-location>/properties/zk-label.properties</label-location>  
   </system-config>  

3) Now You can refer this key-value like pair from .zul page.
edit view.zul file as given below:
 <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>  
 <zk>  
  <zscript><![CDATA[  
     String number = "10";  
   ]]></zscript>  
   <grid id="demoGrid" width="300px">  
     <rows>  
       <row>  
         <!-- Using The Tag Lib -->  
         ${c:l('username')}<textbox hflex="1"/>  
       </row>  
       <row>  
         <!-- Using EL implicit object labels -->  
         *${labels.password} 1 <textbox type="password" hflex="1"/>  
       </row>  
       <row>  
         <!-- Using The Java Way -->  
         <label id="pwd" /><textbox type="password" hflex="1"/>  
       </row>  
     </rows>  
     <foot>  
       <!-- Properties can get the variable in the page -->  
       <footer style="text-align:right;" span="2"><label value="${c:l('message')}" /></footer>  
     </foot>  
   </grid>  
    <zscript><![CDATA[           
     import org.zkoss.util.resource.Labels; //Labels utility included the international functionality  
     pwd.setValue("*" + Labels.getLabel("password") + " 2" );  
   ]]></zscript>  
 </zk>  

Here in view.zul I have given different way of referring properties key now just deploy it and its ready to go..


Structure of the project:

You can see added zk-label.properties file in our project.



Screenshot-> what we have done:




Now If You change the content of the zk-label.properties as Below:

 #--------------------#  
 # Label for zkdemo #  
 #--------------------#  
 username=उपयोगकर्ता नाम  
 password=पासवर्ड  
 message=भाषा उपलब्ध : ${number}  

You will see like:



In next post -> how could we integrate ck editor in this portlet !!?... GOOD DAY

No comments:

Post a Comment