New Language Support In Liferay DXP

blog-banner

About this Blog :

If your portal needs a language which is not given out of the box in Liferay DXP then you can add new one or more based on your needs. You can follow below content which gives you a way to add a language which is not given out of the box in Liferay DXP e.g. Gujarati.

Adding new language to Liferay :

  • To add a new language in Liferay, it requires a servlet mapping entry in web.xml (which resides in “LIFERAY HOME\tomcat\webapps\ROOT\WEB-INF” directory ) and a locale entry in portal-ext.properties.
  • For desired language, we can make servlet mapping entry directly in web.xml or use ext plugin which will add servlet mapping.

    Here, we have used ext plugin to add servlet mapping entry.

Please note that "Ext plugins are deprecated for Liferay Portal CE 7.0 and should only be used if absolutely necessary."

  • As we are modifying Liferay Portal’s web.xml file, it's necessary to use Ext plugin.

>> gujarati-language-support-ext\docroot\WEB-INF\ext-web\docroot\WEB-INF\web.xml<<

<servlet-mapping>
	<servlet-name>I18n Servlet</servlet-name>
	<url-pattern>/gu/*</url-pattern>
</servlet-mapping>
    
<security-constraint>
	<web-resource-collection>
		<web-resource-name>/c/portal/protected</web-resource-name>
		<url-pattern>/gu/c/portal/protected</url-pattern>
	</web-resource-collection>
</security-constraint>

>> gujarati-language-support-ext/docroot/WEB-INF/ext-impl/src/main/resource/content/Language_gu.properties <<

  • Deploy the ext plugin.

Once servlet mapping entry is configured, required locale entries needs to be configured as well.

  • We can specify required locale entries in portal-ext.properties using "locales" property.

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,fi_FI,

fr_FR,fr_CA,gl_ES,de_DE,el_GR,iw_IL,hi_IN,hu_HU,in_ID,it_IT,ja_JP,ko_KR,lo_LA,lt_LT,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ro_RO,

ru_RU,sr_RS,sr_RS_latin,sl_SI,sk_SK,es_ES,sv_SE,tr_TR,uk_UA,vi_VN, gu

Gujarati language uses "gu" language id. Refer to following link for more language ids : https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

  • After deploying the ext plugin and adding locale entries in portal-ext.properties, just restart Liferay and then the Gujarati language should appear in available locales.

Adding new language to Liferay

  • To override the liferay's language keys, it requires module with class that extends ResourceBundle along with language key file.

Folder Structure for Language Support in Liferay DXP

@Component(
	immediate = true,
	property = {
		"language.id=gu"
	},
	service = ResourceBundle.class
)
public class extends ResourceBundle {
	
	@Override
	public Enumeration<String> getKeys() {
		return _resourceBundle.getKeys();
	}

	@Override
	protected Object handleGetObject(String key) {
		return _resourceBundle.getObject(key);
	}

	private final ResourceBundle _resourceBundle = ResourceBundle.getBundle(
		"content.Language", UTF8Control.INSTANCE);

}
  • Add the keys that you need to modify in Language.properties and deploy the module.

New Language Support in Liferay DXP
 

Contact us

For Your Business Requirements

: 0 / 65000

: 0 / 280

: 0 / 280

: 0 / 280

: 0 / 280

: 0 / 280

: 0 / 65000

Text to Identify Refresh CAPTCHA
Background Image Close Button

2 - 4 October 2024

Hall: 10, Booth: #B8 Brussels, Belgium