Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Manish Kumar Jaiswal
Setting Preferred Language
7. September 2012 05:49
Antwort

Manish Kumar Jaiswal

Rang: Regular Member

Nachrichten: 133

Eintrittsdatum: 25. November 2008

Neue Beiträge

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
7. September 2012 12:31
Antwort

Vitaliy Koshelenko

Rang: Expert

Nachrichten: 263

Eintrittsdatum: 25. März 2011

Neue Beiträge

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

1user.setLanguageId(languageId);


Vitaliy
Manish Kumar Jaiswal
RE: Setting Preferred Language
7. September 2012 12:34
Antwort

Manish Kumar Jaiswal

Rang: Regular Member

Nachrichten: 133

Eintrittsdatum: 25. November 2008

Neue Beiträge

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
7. September 2012 12:36
Antwort

Vitaliy Koshelenko

Rang: Expert

Nachrichten: 263

Eintrittsdatum: 25. März 2011

Neue Beiträge

Yes, user will see the portal in that particular language.
Hitoshi Ozawa
RE: Setting Preferred Language
8. September 2012 08:23
Antwort

Hitoshi Ozawa

Rang: Liferay Legend

Nachrichten: 7952

Eintrittsdatum: 23. März 2010

Neue Beiträge

May have to do the following

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

Manish Kumar Jaiswal

Rang: Regular Member

Nachrichten: 133

Eintrittsdatum: 25. November 2008

Neue Beiträge

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
Manish Kumar Jaiswal
RE: Setting Preferred Language
10. September 2012 01:30
Antwort

Manish Kumar Jaiswal

Rang: Regular Member

Nachrichten: 133

Eintrittsdatum: 25. November 2008

Neue Beiträge

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
10. September 2012 12:33
Antwort

Vitaliy Koshelenko

Rang: Expert

Nachrichten: 263

Eintrittsdatum: 25. März 2011

Neue Beiträge

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
11. September 2012 04:36
Antwort

Hitoshi Ozawa

Rang: Liferay Legend

Nachrichten: 7952

Eintrittsdatum: 23. März 2010

Neue Beiträge

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
11. September 2012 05:20
Antwort

MICHAIL MOUDATSOS

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 4. Oktober 2011

Neue Beiträge

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.