One of the best features of Liferay is its ability to support multiple language. Currently Liferay provide support for 40 languages out of the box. Consider you encounter a situation where you have to add a new language support to Liferay that is not one of the ones supported? In other words, in this blog we will see how to add a new language to Liferay 7.1 It is almost same as Liferay 7. In this blog we will add “Gujarati” language.

Following are the steps that we need to carry out to add new language Liferay 7

  1. Each language that Liferay supports, has its own servlet-mapping and URL-pattern which is defined in “web.xml” (Liferay_HOME\tomcat-\webapps\ROOT\WEB-INF) so we will have to do this for “Gujarati” language like this Servet-mapping entry is like this
Liferay

Here I18N servlet is servlet name which means Internationalization because there are total 18 characters between the first letter ‘I’ and the last letter ‘N’.Internationalization is a mechanism to create such an application that can be adapted to different languages and regions.URL pattern entry is like this.This step will active “Gujarati” language in Liferay.

2
This step will active “Gujarati” language in Liferay.
  1. In order to make visible “Gujarati” language in Liferay portal and in control panel we have to define new locale in “portal-ext.properties” like this.
3
  • Restart your server.
  • Go to Control Panel–>Configuration–>Instance Settings.
  • Go to Miscellaneous which is at top of the page.
  • Now you can see following screen.
Control-Panel
  • Move Gujarati language from available to current and click save.
  • Now you can see Gujarati language in Default Language.
  • Select Gujarati language as default language and click save
default-language

This is how we add “Gujarati” language in Liferay portal.

Now, we will see how to show some text in Gujarati.

Create new language hook to add new language_gu_IN.properties file with all the keys and their respective translations.

  1. Open eclipse and create new Liferay Module Project and select Project Template Name as activator
Liferay-Module-Project
  1. Click next and click finish.
  2. Create “content” folder in “src/main/resources”.
  3. Create “language_gu_IN.properties” file in content folder.
  4. Give following dependencies and refresh gradle.
4
  1. Open java file and write below code.
4
  1. Open “language_gu_IN.properties” and add all keys which you want to translate from Liferay “language.properties” (portal-master/portal-impl/src/content) file like this
6
  1. Restart your server and deploy your hook.
  2. You can see following screen.
6
This way you can change text that you want in Liferay portal. Now we will see how to add language icon. Create one public page and add language selector portlet on that page. You can’t see Gujarati language icon.
Gujarati-language-icon

To add language icon follow below steps.

Once theme created successfully then go to that theme open cmd and write gulp build.

It automatically create build folder.

Copy images folder from build\images and copy it into src folder.

Liferay using 2 things for displaying icons. Somewhere it uses png flag and somewhere svg you need to adjust both.

Add .png file in images\languages folder and name the file like png.

Add .svg file in images\lexicon folder and name the file like flags-gu-IN.svg.

Open icons.svg file which is in images\lexicon folder and add symbol for Gujarati language flag like

Gujarati-language-flag

Deploy theme using command gulp deploy.

Go to Liferay portal.

Go to page that you created and configure that page.

Go to look and feel of that page and select specific look and feel for this page option.

You can see theme which you created.

Select that theme and click save.

Go to that page and refresh that page.

You can see Language icon.

Gujarati-language-flag1

Why we require Admin Theme: In Control Panel there is no icon available for our New Language.

In this I add Gujarati language.

To add this icon we have to Create Custom Admin Theme.

Create regular theme using theme builder.
Add below code in Liferay-look-and-feel.xml file

Liferay-look-and-feel

Add .png file in images\languages folder and name the file like png.

Add .svg file in images\lexicon folder and name the file like flags-gu-IN.svg.

Open icons.svg file which is in images\lexicon folder and add symbol for Gujarati language as shown above.

Build and deploy your theme.

Go to Control Panel–>Configuration–>Instance Settings –>Miscellaneous

You can see Your custom theme in default control panel theme select it and save.

You can now see that language icon when you create any web content or anything else.

Blog Written By Aneri Jhaveri Jr. Consultant, Anblicks