
Configure time zones and locale
Summary #
By default Liferay sets the time zone to "GMT" (UTC) and the locale to "en_US". You can change these defaults by following the steps below.
In the examples below we are adding the Australian time zones and assuming the default time zone is "Australia/Perth" (GMT+8). Also, we are assuming the default locale is "en_AU" (Australian English). Please change these values to meet your own requirements.
Locations of the "portal-ext.properties" and "system-ext.properties" files referenced below vary between installations. If you are using the Liferay+Tomcat, you can create the files in your Tomcat home (the folder which contains /data /deploy /tomcat-version). If you are unsure consult the Liferay admin guide.
How to change / add time zones #
- The specified ids must match those from the class java.util.TimeZone.
- See http://download.oracle.com/javase/6/docs/api/java/util/TimeZone.html
- See http://tutorials.jenkov.com/java-date-time/java-util-timezone.html
Create/update "portal-ext.properties" with a comma-separated list of the time zones you wish to use.
eg,
time.zones=\ Australia/Perth,\ Australia/Adelaide,\ Australia/Darwin,\ Australia/Brisbane,\ Australia/Canberra,\ Australia/Hobart,\ Australia/Melbourne,\ Australia/Sydney
How to set the default timezone #
Create/update "system-ext.properties" and set the default time zone
eg.
user.timezone=Australia/Perth
Alternatively, you can add your new timezones to the existing values:
time.zones=\ Pacific/Midway,\ Pacific/Honolulu,\ America/Anchorage,\ America/Los_Angeles,\ America/Denver,\ America/Chicago,\ America/New_York,\ America/Caracas,\ 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/Perth,\ Australia/Adelaide,\ Australia/Darwin,\ Australia/Brisbane,\ Australia/Canberra,\ Australia/Hobart,\ Australia/Melbourne,\ Australia/Sydney,\ Pacific/Guadalcanal,\ Pacific/Auckland,\ Pacific/Enderbury,\ Pacific/Kiritimati === How to add / update locales === Create/update "portal-ext.properties" with a comma-separated list of the locales you wish to use. eg. locales=en_AU
Alternatively you can add your new locale to the existing locales
eg.
locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,cs_CZ,nl_NL,en_AU,en_US,en_ GB,et_EE,fi_FI,fr_FR,gl_ES,de_DE,el_GR,iw_IL,hi_IN,hu_HU,in_ID,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,uk_UA,vi_VN
Also remember to add new locales as URL patterns for the "I18n Servlet" in web descriptor file "ROOT/WEB-INF/web.xml".
The following snippet shows how to add the Australian English (en_AU) as a new URL pattern.
<servlet-mapping> <servlet-name>I18n Servlet</servlet-name> <url-pattern>/en_AU/*</url-pattern> </servlet-mapping>
How to set the default locale #
Create/update "system-ext.properties" and set the default user locale.
eg.
user.country=AU user.language=en
Common Issues / Important Notes #
When Liferay starts for the first time, it creates a default user for the company. This user is assigned the time zone obtained from "system.properties" and the value of "user.timezone".
CompanyLocalServiceImpl#checkCompany(String webId, String mx, String shardName
The data stored for the default user(s) can be viewed by running this SQL snippet:
select * from User_ where defaultuser = 1;
The default user is not visible in the Control Panel but it is possible to edit the default user's time zone using "Control Panel > Portal > Settings > Miscellaneous > Display Settings > Time Zone".
Whenever a new user is created, it is assigned the current time zone of the default user, irrespective of the current value of the "user.timezone" system property.
UserLocalServiceImpl#addUser()
If Liferay has already been installed, it will be configured with previous "user.timezone" and "user.locale" settings.
These values are typically "user.timezone=GMT" and "user.locale=en_US".
You can update these values for your required timezone and locale by running these SQL snippets against your Liferay database instance:
eg. update only default user timezones to Perth, Western Australia
update User_ set timezoneid = 'Australia/Perth' where defaultuser = 1;
eg. update all user timezones to Perth, Western Australia
update User_ set timezoneid = 'Australia/Perth';
eg. update only default user language ID to Perth, Western Australia
update User_ set languageid = 'en_AU' where defaultuser = 1;
eg. update all user language IDS to Australian English
update User_ set languageid = 'en_AU';
NOTE: Replace the timezone and language IDs to suit your locale timezone and language ID.
NOTE: It is best practice to set your required "systen-ext.properties" and "portal-ext.properties" before you first run Liferay so that the defaults are setup correctly. Otherwise some things are stored in the database and can't be changed without database manipulation.
JVM Locale and Time Zone Settings #
Note: Liferay will not pickup your JVM time zone and locale settings. See http://issues.liferay.com/browse/LEP-2584
Friendly URLs #
In some situations, you can end up with your new locale prepended to URLs in Liferay
i.e.
http://localhost:8080/en_AU/web/guest/home
This is a feature.
However, if you want to disable it you can set the following property in "portal-ext.properties".
eg.
locale.prepend.friendly.url.style=0
Add Non-Standard Timezones #
Note that the specified new timezone ids must match those from the class java.util.TimeZone, that may meet most of requires, but if you still want to add a non-standard timezone or want to show a different TimeZone name, then can follow these steps:
1. Add your TimezoneID in portal-ext.properties file:
For example: I add "Australia/WST'(+07:30)" in portal-ext.properties
time.zones=\ Asia/Saigon,\ Australia/WST,\ Asia/Shanghai,\
2. Update html\taglib\ui\input_time_zone\page.jsp in your ext environment:
<% for (int i = 0; i < timeZones.length; i++) { if(timeZones[i].equals("Australia/WST")){ %> <option <%= value.equals("Australia/WST") ? "selected" : "" %> value="Australia/WST">(UTC +07:30) <%= LanguageUtil.get(pageContext, "australia-wst") %></option> <% } else{ //original code here <option <%= value.equals(curTimeZone.getID()) ? "selected" : "" %> value="<%= curTimeZone.getID() %>">(UTC <%= offset %>) <%= curTimeZone.getDisplayName(daylight, displayStyle, locale) %></option> <% } } %>