The Ext Manage Pages portlet not only clones the out of the box Manage Pages portlet, but it also extends the model and service — supporting customized data, for example, Keywords. We can make these Keywords localized too.
Liferay portal is designed to handle as many languages as you want to support. By default, it supports up to 22 languages. When a page is loading, the portal will detect the language, pull up the corresponding language file, and display the text in the correct language.
We want the Keywords to be localized too. For example, the default language is English (United States) and the localized language is Deutsch (Deutschland). Thus, you have the ability to enter not only the Name and HTML Title in German, but also the Keywords in German.
As shown in the following screenshot, when you change the language of the page in German using the language portlet, you will see the entire web site changed to German, including the portlet title and input fields. For example, the title of the portlet now has the Ext Seiteneinstellungen value and the Keywords now become Schlüsselwörter.
How do we implement this feature? In other words, how do we customize the language display in the page management? Let’s add the localized feature for the Ext Manage Pages portlet.
First of all, we need to extend the model and to implement that model in order to support the localized feature. For the ExtLayout model, let’s add the locale method first.
public String getKeywords(Locale locale);
public String getKeywords(String localeLanguageId);
public String getKeywords(Locale locale,
boolean useDefault);
public String getKeywords(String localeLanguageId,
boolean useDefault);
public void setKeywords(String keywords, Locale locale);
As shown in the code above, it adds getting and setting methods for the Keywords field with locale features. Now let’s add the implementation for the ExtLayout model:
public String getKeywords(Locale locale) {
String localeLanguageId = LocaleUtil.toLanguageId(locale);
return getKeywords(localeLanguageId);
}
public String getKeywords(String localeLanguageId) {
return LocalizationUtil.getLocalization(getKeywords(),
localeLanguageId);
}
public String getKeywords(Locale locale, boolean useDefault) {
String localeLanguageId = LocaleUtil.toLanguageId(locale);
return getKeywords(localeLanguageId, useDefault);
}
public String getKeywords(String localeLanguageId, boolean
useDefault) {
return LocalizationUtil.getLocalization( getKeywords(),
localeLanguageId, useDefault);
}
public void setKeywords(String keywords, Locale locale) {
String localeLanguageId = LocaleUtil.toLanguageId(locale);
if (Validator.isNotNull(keywords)) {
setKeywords(LocalizationUtil.updateLocalization(
getKeywords(), "keywords", keywords, localeLanguageId));
}
else {
setKeywords(LocalizationUtil.removeLocalization(
getKeywords(), "keywords", localeLanguageId));
}
}
As shown in the code above, it adds implementation for get and set methods of the ExtLayout model.
Language files have locale-specific definitions. By default, Language.properties (at /portal/portal-impl/src/content) contains English phrase variations further defined for United States, while Language_de.properties (at /portal/portal-impl/src/content) contains German phrase variations further defined for Germany. In Ext, Language-ext.properties (available at /ext/ext-impl/src/content) contains English phrase variations further defined for United States, while Language-ext_de.properties (should be available at /ext/ext-impl/src/content) contains German phrase variations further defined for Germany.
First, let’s add a message in Language-ext.properties, by using the following steps:
keywords=Keywords
This code specifies the keywords message key with a Keywords value in English:
Then we need to add German language feature in Language-ext_de.properties as follows:
## Portlet names
javax.portlet.title.EXT_1=Berichte
javax.portlet.title.jsp_portlet=JSP Portlet
javax.portlet.title.book_reports=Berichte für das Buch
javax.portlet.title.extLayoutManagement=Ext Seiteneinstellungen
javax.portlet.title.extCommunities=Ext Communities
## Messages
view-reports=Ansicht-Berichte für Bücher
keywords=Schlüsselwörter
## Category titles
category.book=Buch
## Model resources
model.resource.com.ext.portlet.reports.model.ReportsEntry= Buch ## Action names
action.ADD_BOOK=Fügen Sie Buch hinzu
As shown in the code above, it specifies the same keys as that of Language-ext.properties. But all the keys’ values were specified in German instead of English. For example, the message keywords has a Schlüsselwörter value in German.
In addition, you can set German as the default language and Germany as the default country if it is required. Here are the simple steps to do so:
user.country=DE
user.language=de
The code above sets the default locale — the language German (Deutsch) and the country Germany (Deutschland). In general, there are many language files, for example Language-ext.properties and Language-ext_de.properties, and some language files would overwrite others in runtime loading. For example, Languageext_de.properties will overwrite Language-ext.properties when the language is set as German.
These are the three simple rules which indicate the priorities of these language files:
For instance, the following is a ranking from bottom to top for the German language:
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…