Using Liferay's Localization Settings

You can customize a given locale’s default language settings by overriding the properties that control those settings. For instructions on this, see Overriding Language Keys. Here, you’ll learn which properties correspond to common language settings.

So what all can be customized? This is an excellent question! Consider these examples:

  • In the add and edit user forms, you can configure the name fields that are displayed and the field values available in select fields. For example, you can leave out the middle name field or alter the prefix selections.

  • You can also control the directionality of content and messages (left to right or right to left).

Language properties exist in Language_xx.properties files, where xx represents the locale. For example, Language_es.properties contains the properties for Spanish, Language_en.properties contains the properties for English, and so on.

The default (core) language properties are in Language.properties. Do not edit this file. You can, however, open it to view the default language settings. There are two ways to do so:

  1. From Liferay Portal’s source code. Navigate to

    liferay-portal/portal-impl/src/content/Language.properties
    
  2. From a bundle’s portal-impl.jar.

    [Liferay Home]/tomcat-[version]/webapps/ROOT/WEB-INF/lib/portal-impl.jar
    

    Open the content folder in the JAR to find the language files.

The first section in the core Language.properties file is labeled Language Settings and contains language properties that begin with lang:

##
## Language Settings
##

lang.dir=ltr
lang.line.begin=left
lang.line.end=right
lang.user.default.portrait=initials
lang.user.initials.field.names=first-name,last-name
lang.user.name.field.names=prefix,first-name,middle-name,last-name,suffix
lang.user.name.prefix.values=Dr,Mr,Ms,Mrs
lang.user.name.required.field.names=last-name
lang.user.name.suffix.values=II,III,IV,Jr,Phd,Sr

To use the language settings mentioned here, you must have a module. See the articles on overriding language keys to set up a module with the following characteristics:

  • Contains an implementation of ResourceBundle that is registered in the OSGi runtime.

  • Contains a Language_xx.properties file for the locale whose properties you want to override.

Localizing User Names

Naming conventions can differ between locales. For example, users in some locales have more than one last name. You can therefore change the user name properties to fit the given locale. The properties for changing user name settings begin with lang.user.name.

User name fields are configurable in the following ways:

  • Remove certain name fields and make others appear more than once. Some locales need more than one last name, for example.

    lang.user.name.field.names=prefix,first-name,middle-name,last-name,suffix
    
  • Change the prefix and suffix values for a locale.

    lang.user.name.prefix.values=Dr,Mr,Ms,Mrs
    lang.user.name.suffix.values=II,III,IV,Jr,Phd,Sr
    
  • Specify which fields are required.

    lang.user.name.required.field.names=last-name
    

A user’s first name is mandatory. Because of this, take these two points into consideration when configuring a locale’s user name settings:

  • The first-name field can’t be removed from the field names list.

    lang.user.name.field.names=prefix,first-name,middle-name,last-name,suffix
    
  • Because a first name is required, it’s always implicitly included in the required field names property:

    lang.user.name.required.field.names=last-name
    

    Therefore, any fields you enter here are in addition to the first name field. Last name is required by default, but you can disable it by deleting its value from the property:

    lang.user.name.required.field.names=
    

    In that case, only a first name would be required.

For most of the locales enabled by default, the user name properties are tailored to each locale. The default locales are specified by the locales.enabled property:

locales.enabled=ar_SA,ca_ES,zh_CN,nl_NL,en_US,fi_FI,fr_FR,de_DE,hu_HU,ja_JP,pt_BR,es_ES,sv_SE

For example, here are the English (Language_en.properties) properties for setting user name fields:

lang.user.name.field.names=prefix,first-name,middle-name,last-name,suffix
lang.user.name.prefix.values=Dr,Mr,Ms,Mrs
lang.user.name.required.field.names=last-name
lang.user.name.suffix.values=II,III,IV,Jr,Phd,Sr

Figure 1: The user name settings impact the appearance of user information and forms.

Figure 1: The user name settings impact the appearance of user information and forms.

Compare those to the Spanish (Language_es.properties) settings:

lang.user.name.field.names=prefix,first-name,last-name
lang.user.name.prefix.values=Sr,Sra,Sta,Dr,Dra
lang.user.name.required.field.names=last-name

Figure 2: The Spanish user name settings omit the suffix and middle name fields.

Figure 2: The Spanish user name settings omit the suffix and middle name fields.

The biggest difference between the English and Spanish form fields is that the middle name and suffix fields are omitted in the Spanish configuration. Other differences include the specific prefix values. ¡Muy excelente!

Identifying User Initials

The default avatar displays a user’s initials. Some cultures use initials differently, so there’s a way to configure them in the appropriate Language_xx.properties file.

lang.user.default.portrait=initials
lang.user.initials.field.names=first-name,last-name

The lang.user.default.portrait property sets the type of portrait to use for users. This can be set to initials or image. If set to image, the default images defined by the image.default.user.female.portrait or image.default.user.male.portrait properties residing in the portal.properties file are used. Therefore, the lang.user.initials.field.names property is ignored.

Figure 3: The users initials are displayed for their avatar by default.

Figure 3: The user's initials are displayed for their avatar by default.

If you’re leveraging the user’s initials for the default avatar, you can use the lang.user.initials.field.names property to organize how the initials are displayed. Valid values for this property include first-name, middle-name, and last-name, in any order.

Right to Left or Left to Right?

The first three properties in the core Language.properties file’s Language Settings section change the display direction of a language’s characters. Most languages read from left to right, but some languages read from right to left (e.g., Arabic, Hebrew, and Persian).

Here are the relevant language properties for a right-to-left language:

lang.dir=rtl
lang.line.begin=right
lang.line.end=left

Overriding Language Keys

Localizing Your Application

Creating a Language Module

Using a Language Module

« Localizing Your ApplicationCreating a Language Module »
Was this article helpful?
0 out of 0 found this helpful