G.Spansky
G.Spansky

Reputation: 902

Change site language programmatically

I need to change site language programmatically in Liferay and Im stuck. I thought that I can use LanguageUtil class, but I dont know how.

Is there any way, to change Liferay language programmatically? (I know I can do that in administration panel, but I need to have that feature in my code also).

Now my code looks like this:

@ResourceMapping("changeLanguageToEnglish")
public void changeLanguageToEnglish(){
        LanguageUtil langUtil = new LanguageUtil();
        //langUtil.setLanguage(language);
}

Upvotes: 1

Views: 1482

Answers (2)

JMF
JMF

Reputation: 1113

I can do this using the portal-ext.properties:

#
# Set the default locale used by Liferay. This locale is no longer set at
# the VM level. See LEP-2584.
#
user.country=US
user.language=en

Also by a hook

<hook>
     <language-properties>content/Language_en.properties</language-properties>
     <language-properties>content/Language_fa.properties</language-properties>
</hook>

And through a portlet

Change languaje portlet

Regards!

Upvotes: 1

fabballe
fabballe

Reputation: 771

I didn't try but I think you have to change the locale set is the user session:

String languageId = "en_US";
Locale locale = LocaleUtil.fromLanguageId(languageId);
session.setAttribute(org.apache.struts.Globals.LOCALE_KEY, locale);  

Upvotes: 2

Related Questions