Liferay 7 Language Properties Hook

Liferay 7 Language Properties Hook tutorial will drive you on overriding liferay core language properties.

Types of language properties:

  • Liferay core language properties  : Application level properties which is accessible  to all modules:   “portal-impl/content/” folder
  • Liferay module language properties: Module level properties

In this tutorial,  we will see overriding Liferay DXP core language properties and  next tutorial will give you example to override liferay module language properties,

Liferay 7 Core Language Properties Hook:

    • Create liferay language module project.  In Eclipse: File -> New -> Liferay Module Project and select project template Name as “activator” and click on Finish. We will make the activator to component later.Liferay 7 Language Hook
    • Delete the generated package along with activator and create new  package: org.javasavvy.hook.language
    • edit bnd.bnd
      • Remove the bundle activator
      • Update the Bundle-Symbolic  Name to ” org.javasavvy.hook.language”
      • bnd.bnd file is:
        1. Bundle-Name: hooks-language
          Bundle-Version: 1.0.2
    • Edit the build.gradle and add below dependencies. Right click on project and select  -> Gradle ->Refresh Gradle Project to refresh the gradle dependencies.
      1. dependencies {
         compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
         compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
         compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
         compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
         compileOnly group: "jstl", name: "jstl", version: "1.2"
         compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
         compile group: "org.osgi", name:"org.osgi.service.component.annotations", version:"1.3.0"
    • Create the Component class:
    • Add the @Component annotation with below config:
      1. @Component(
         property = { "" }, 
         service = ResourceBundle.class
    • In the @Component annotation,provide from below locales which ever you want to override. does not take multple locales, need  to create new module again if you wish to override language properties for another locale. This is only limitation.
      1. locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,hr_HR,cs_CZ,da_DK,nl_NL,nl_BE,en_US,en_GB,en_AU,et_EE,
    • Create the content folder in src/main/resource
    • Create and files
    • Project Structure is: 
      • This class need to extend ResourceBundle
      • Resource.getBundlle(“{foldername.Language}”)
      • package org.javasavvy.hook.language;
        import java.util.Enumeration;
        import java.util.ResourceBundle;
        import org.osgi.service.component.annotations.Component;
        import com.liferay.portal.kernel.language.UTF8Control;
         property = { "" }, 
         service = ResourceBundle.class
        public class CustomLanguageComponent extends ResourceBundle {
        ResourceBundle bundle = ResourceBundle.getBundle("content.Language", UTF8Control.INSTANCE);
         protected Object handleGetObject(String key) {
         System.out.println("getting key"+key);
         return bundle.getObject(key);
         public Enumeration<String> getKeys() {
         return bundle.getKeys();
    • Authenticate with invalid credentials and you can see customized error message:


some times, you might get the below exception.  to fix this, move the to  /src/main/resource/content folder.

java.util.MissingResourceException: Can’t find bundle for base name content.Language, locale en_US


Download Liferay DXP Language Hook Code

Leave a Reply

Your email address will not be published. Required fields are marked *