3

I need to programmatically get the default locale for a site. So I:

  • creata a new site with default language set to english (en_us)
  • create a second site with default languge set to german (de_DE)

In my code I've tried to do the following:

CompanyThreadLocal.setCompanyId(portletDataContext.getCompanyId());
final Locale locale = LocaleUtil.getDefault();

But I get "en_us" for both sites, which is the portal default locale.

I need this in my export/import functions of my PortletDataHandler implementation. Otherwise I will allways export my data with the wrong default language from staging to live.

I'm running Liferay 6.1.20 EE.

Thanks in advance, Fabi

FeinesFabi
  • 1,147
  • 2
  • 12
  • 25
  • when you mean site is it Liferay's sites in same portal instance or do you mean different portal instances altogether? – Sandeep Nair Aug 16 '13 at 17:05
  • In control panel, I opened the portlet "sites" and added the two sites mentioned in the question.I think they were called `communities` in Liferay 5. So they are in the same portal instance, I guess. You can tell them apart by their `groupId`. – FeinesFabi Aug 16 '13 at 21:35
  • 2
    And how did you set Locale for the Site from Control Panel? The reason I am asking is because I am not seeing a way to associate locale to Site from control panel in Liferay 6.1. I see I can set locale for a portal instance – Sandeep Nair Aug 16 '13 at 22:22
  • It was my fault. I'm using a custom template for the site which has a tab to set the default language. The solution to my problem was to get the language from this template. – FeinesFabi Aug 21 '13 at 11:16

1 Answers1

1

In Liferay 6.2 you can just do:

Locale defaultLocale = PortalUtil.getSiteDefaultLocale(groupId);
Reigo
  • 285
  • 2
  • 9