Search code examples
liferay

How to get programmatically Liferay default language or locale?


How get programmatically Liferay default language or locale?


Solution

  • Check the com.liferay.portal.kernel.util.LocaleUtil class methods: LocaleUtil.getDefault() - returns default locale, LocaleUtil.toLanguageId(locale) - to get language ID from locale.

    P.S. Note that LocaleUtil uses ThreadLocal to store defaul locale, so if you're doing this in new thread that you created, you should first call com.liferay.portal.security.auth.CompanyThreadLocal.setCompanyId(long companyId) method - this one will initialize LocaleThreadLocal and TimeZoneThreadLocal with default locale and timezlone.