Multiple-language support for Knowledge Base articles

What’s knowledge base or knowledge management (KM)? The portlet Knowledge Base allows authoring articles and organize them in a hierarchy of navigable categories. It leverages Web Content articles, structures, and templates; allows rating on articles; allows commenting on articles; allows adding hierarchy of categories; allows adding tags on articles; exports articles to PDF and other formats; supports workflow; allows adding custom attributes (called custom fields); supports indexing and advanced search; allows using rule engine; search by keyword – look-ahead typing; multiple-language support, etc.

In general, the portlet Knowledge Base provides two pieces inside: Articles – managing knowledge base articles - and Article Aggregator - publishing knowledge base articles.

Abstracted from the book: Liferay Portal 6 Enterprise Intranets (coming out soon)

We have discussed main features of Knowledge base articles in both Liferay portal 5.2 EE SP1 (or SP2 or SP3) and 6.0 like

Taxonomies and Folksonomies - Increasing search and retrieve capabilities in Knowledge Base Articles

Sharing Content - Knowledge base - across Organizations and Communities

Search by keyword - look-ahead typing – based on Knowledge Base articles in Liferay portal 6

This article will share one more feature: Multiple-language support on Knowledge Base articles in Liferay portal 6 and 5.2 EE SP1 (or SP2 or SP3).

Introduction

In Liferay portal, you can use your own language. Multilingual organizations get out-of-the-box support for up to 22 languages. Users can toggle among different language settings with just one click and produce/publish multilingual documents and web content. You can also easily add other languages in your public, private pages, or other organizations.

Multi-languages get supported as well in Web Content. That is, web content can be entered in as many languages as desired. As you can see, only content got localized. In addition, the name (article title) and the summary, that is, abstract description of web content, should be localizable, too.

Fortunately, knowledge base articles have fields: title, content, summary (description), etc. Multi-languages should get supported as well in knowledge base articles. That is, knowledge base articles (title, content and summary) can be entered in as many languages as desired.

How to achieve this?

Multi-languages get support on knowledge base articles could be achieved in following steps. Here English and German are used as examples.

  • Add locale methods in the model.

    public String getTitle(Locale locale);   
    public String getTitle(String localeLanguageId);   
    public String getTitle(Locale locale, boolean useDefault);   
    public String getTitle(String localeLanguageId,boolean useDefault);   
    public void setTitle(String title, Locale locale);   
    public String getContent(Locale locale);   
    public String getContent(String localeLanguageId);   
    public String getContent(Locale locale,boolean useDefault);   
    public String getContent(String localeLanguageId,boolean useDefault);   
    public void setContent(String content, Locale locale);   
    public String getDescription(Locale locale);   
    public String getDescription(String localeLanguageId);   
    public String getDescription(Locale locale, boolean useDefault);   
    public String getDescription(String localeLanguageId, boolean useDefault);   
    public void setDescription(String description, Locale locale);

  • Implement locale methods based on above model.

For more details, you may refer to chapter 5 Managing Pages of the book: Liferay Portal 5.2 Systems Development.

  • Input knowledge base articles in multiple languages.

In English, German, etc.

  • List knowledge base articles (Title and Summary) in selected language

In English.

 

In German.

  • List search results in selected language

In English.

In German.

  • List history (versions) in selected language

 In German

  • View knowledge base article in selected language

 In German

In English

What’s happening?

The portal has following default settings for languages in portal.properties.

locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,cs_CZ,nl_NL,en_US,fi_FI,fr_FR,gl_ES,de_DE,el_GR,hu_HU,it_IT,ja_JP,ko_KR,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ru_RU,sk_SK,es_ES,sv_SE,tr_TR,vi_VN
locale.default.request=false
locale.prepend.friendly.url.style=1
time.zones=Pacific/Midway,Pacific/Honolulu,America/Anchorage,America/Los_Angeles,America/Denver,America/Chicago,America/New_York,America/Puerto_Rico,America/St_Johns,America/Sao_Paulo,America/Noronha,Atlantic/Azores,UTC,Europe/Lisbon,Europe/Paris,Europe/Istanbul,Asia/Jerusalem,Asia/Baghdad,Asia/Tehran,Asia/Dubai,Asia/Kabul,Asia/Karachi,Asia/Calcutta,Asia/Katmandu,Asia/Dhaka,Asia/Rangoon,Asia/Saigon,Asia/Shanghai,Asia/Tokyo,Asia/Seoul,Australia/Darwin,Australia/Sydney,Pacific/Guadalcanal,Pacific/Auckland,Pacific/Enderbury,Pacific/Kiritimati

As shown in above code, the portal specifies the available locales. Messages corresponding to a specific language are specified in properties files with file names matching that of content/Language_$[language locale code]*.properties. Of course, these values can also be overridden in properties files with file names matching that of content/Language-ext_$[language locale code]*.properties at $PORTAL_ROOT_HOME/WEB-INF/classes. Obviously you can use a comma to separate each entry. Note that all locales must use UTF-8 encoding.

The portal sets the property locale.default.request to false – that is, unauthenticated users get their preferred language from their company; you can set it true in portal-ext.properties if unauthenticated users get their preferred language from the Accept-Language header.

The portal sets the property locale.prepend.friendly.url.style to 1 – that is, the locale is automatically pre-pended to a URL when the requested locale isn’t the default locale. This means that each URL points to just one language. For example, the URL http://localhost:8080/web/guest/home would point to the default language; The URL http://localhost:8080/zh/web/guest/home and http://localhost:8080/zh_CN/web/guest/home would both point to the Chinese language.

In addition, you would be able to set the property locale.prepend.friendly.url.style to 2 - that is, the locale is automatically pre-pended to every URL, meaning that each URL points to just one language; or you could set the property locale.prepend.friendly.url.style to 0 - that is, the locale isn’t automatically pre-pended to a URL, meaning that each URL could potentially point to many different languages. For instance, the URL http://localhost:8080/web/guest/home could then be viewed by users in many different languages.

The portal specifies available time zones with the property time.zones.

Default language and time zone

The default language is set in system.properties with the following properties.

user.country=US
user.language=en
user.timezone=Europe/Paris

As shown in above code, the portal sets the default locale like country as US and language as en. The portal also sets the default time zone as Europe/Paris (UTC).

Of course, you can customize default language as your own. Supposed that you want to country China Mainland, language Chinese, and time zone Asia/Shanghai, you could add the following lines at $PORTAL_ROOT_HOME/WEB-INF/classes/system-ext.properties.

user.country=CN
user.language=zh
user.timezone=Asia/Shanghai

Remove unwanted languages

As mentioned above, the portal following default languages.

locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,cs_CZ,nl_NL,en_US,fi_FI,fr_FR,gl_ES,de_DE,el_GR,hu_HU,it_IT,ja_JP,ko_KR,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ru_RU,sk_SK,es_ES,sv_SE,tr_TR,vi_VN

Of course, you could remove unwanted languages. Supposed that you want to support English, German and Chinese only, you can simply remove the unwanted locales so that your locales value looks like following in portal-ext.properties.

locales=en_US,de_DE,zh_CN,zh_TW

Abstracted from the book: Liferay Portal 6 Enterprise Intranets (coming out soon)

Summary

As you can see, multiple-language support based on Knowledge Base articles is useful.  By the way, this solution would be helpful in Liferay portal core portlets like Web Content and any plugin portlets.

Last but not least, I'd like to send special thanks to Robert Chen and Frank Yu who did an amazing job to make multiple-language support based on Knowledge base articles a reality.

Blogs
Multiple-language feature based on Knowledge base articles is very helpful. Sir, Thank you once again for a wonderful article emoticon
Thank you, Jonas, this is a great feature. But I still have questions: If there contain multiple-languages in an article, how do you process it? and how to search it by any of its title,content keywords? you know that some of languages are totally different, especially for CJK, we can't treat them like English. Any comments on this?