Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Manish Kumar Jaiswal
Setting Preferred Language
September 7, 2012 5:49 AM
Answer

Manish Kumar Jaiswal

Rank: Regular Member

Posts: 133

Join Date: November 25, 2008

Recent Posts

How to set preferred Language of the user from a new plugin portlet .(setting the language as the preference to use the portal)

Regards
Manish
Vitaliy Koshelenko
RE: Setting Preferred Language
September 7, 2012 12:31 PM
Answer

Vitaliy Koshelenko

Rank: Regular Member

Posts: 222

Join Date: March 25, 2011

Recent Posts

Hi! You can just change languageId for user, for example:

1user.setLanguageId(languageId);


Vitaliy
Manish Kumar Jaiswal
RE: Setting Preferred Language
September 7, 2012 12:34 PM
Answer

Manish Kumar Jaiswal

Rank: Regular Member

Posts: 133

Join Date: November 25, 2008

Recent Posts

Thanks Vitaliy

will this also allow the user to see all the content into that particular language when he/she logins ?

Regards
Manish
Vitaliy Koshelenko
RE: Setting Preferred Language
September 7, 2012 12:36 PM
Answer

Vitaliy Koshelenko

Rank: Regular Member

Posts: 222

Join Date: March 25, 2011

Recent Posts

Yes, user will see the portal in that particular language.
Manish Kumar Jaiswal
RE: Setting Preferred Language
September 10, 2012 1:30 AM
Answer

Manish Kumar Jaiswal

Rank: Regular Member

Posts: 133

Join Date: November 25, 2008

Recent Posts

Vitaliy ,
It saves the language of the user and when he logins next time it shows him/her that language but within the same session he doesnt see the language changed is it we need to do something else ?

Regards
Manish
Vitaliy Koshelenko
RE: Setting Preferred Language
September 10, 2012 12:33 PM
Answer

Vitaliy Koshelenko

Rank: Regular Member

Posts: 222

Join Date: March 25, 2011

Recent Posts

You can change the language for current user's session like this:

1Locale locale = LocaleUtil.fromLanguageId(languageId);
2session.setAttribute(org.apache.struts.Globals.LOCALE_KEY, locale);
Hitoshi Ozawa
RE: Setting Preferred Language
September 11, 2012 4:36 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7954

Join Date: March 23, 2010

Recent Posts

Vitaliy, thank you for the reply but the question is setting another users language from a portlet and not the current user.
MICHAIL MOUDATSOS
RE: Setting Preferred Language
September 11, 2012 5:20 AM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

Vitaliy Koshelenko:
You can change the language for current user's session like this:

1Locale locale = LocaleUtil.fromLanguageId(languageId);
2session.setAttribute(org.apache.struts.Globals.LOCALE_KEY, locale);

Hitoshi Ozawa:
Vitaliy, thank you for the reply but the question is setting another users language from a portlet and not the current user.


Then, in order to use Vitaliy's way, you should keep track of user sessions. It is feasible but i don't know if it worths to maintain all that info just to have the ability to change a user's default language on the fly.
Hitoshi Ozawa
RE: Setting Preferred Language
September 8, 2012 8:23 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7954

Join Date: March 23, 2010

Recent Posts

May have to do the following

PortletPreferences prefs = request.getPreferences();
prefs.setValue(...);
PortletPreferencesLocalServiceUtil.updatePreferences(prefs);
Manish Kumar Jaiswal
RE: Setting Preferred Language
September 8, 2012 8:29 AM
Answer

Manish Kumar Jaiswal

Rank: Regular Member

Posts: 133

Join Date: November 25, 2008

Recent Posts

In portlet preferences we use to save like this
example
prefs.setValue("node-id", Long.toString(node.getNodeId()));

so i understand we will put languageid but wat will be the key is it languageId ?

T&R
Manish