Lukas Grygar's

Personal enterprise Java web development blog.

Liferay Theme localization without Hook

Easy tutorial to localize Liferay 6.2 Theme (which is build by Apache Maven) without using Liferay Hook.

The reason why I prefer having language files inside the theme project is simple: you have just one project with Liferay Theme instead of two projects Liferay Theme and Liferay Hook, which is convenient because if you’re developing theme for 3rd party and it’s part of big project then someone may forget to deploy Theme and Hook together on server and that’s why having two separate projects is prone to error.

The key is convention over configuration so if you have Liferay 6.2 Theme project which build by Maven the directory structure is following:

fooBar-theme
├── src/main/main/resources
|   └── content
|       ├── Language_cs.properties
|       └── Language_en.properties
└── src
    └── main
    	└── webapp
    	    └── templates
    	         └── init_custom.vm

First of all create two or more language files on you desired languages, mine are Czech and English:

Language_cs.properties

custom-theme-langtext-search=Hledat

Language_en.properties

custom-theme-langtext-search=Search

And then you can retrieve langtext and assign him to variable:

init_custom.vm

#set ($custom_theme_langtext_search = $languageUtil.get($locale, "custom-theme-langtext-search"))

And don’t forget to include init_custom.vm to init.vm:

init.vm

## ---------- Custom init ---------- ##

#parse ("$full_templates_path/init_custom.vm")

And then you finally use you langtext in portal_normal.vm

portal_normal.vm

<input type="text" name="q" id="q" placeholder="$custom_theme_langtext_search">

Tested on Liferay 6.2 CE GA2.


Tags: liferay  liferay-portal 

Share on: Twitter  Facebook  Google+ 


Previous post: Liferay: How to create expando (custom) attributes and roles programatically

Next post: Liferay Theme: How to put version information from Maven's POM.xml to header meta tag

Related posts: