Foros de discusión

Setting Preferred Language

thumbnail
Manish Kumar Jaiswal, modificado hace 11 años.

Setting Preferred Language

Regular Member Mensajes: 153 Fecha de incorporación: 25/11/08 Mensajes recientes
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
thumbnail
Vitaliy Koshelenko, modificado hace 11 años.

RE: Setting Preferred Language

Expert Mensajes: 319 Fecha de incorporación: 25/03/11 Mensajes recientes
Hi! You can just change languageId for user, for example:

user.setLanguageId(languageId);


Vitaliy
thumbnail
Manish Kumar Jaiswal, modificado hace 11 años.

RE: Setting Preferred Language

Regular Member Mensajes: 153 Fecha de incorporación: 25/11/08 Mensajes recientes
Thanks Vitaliy

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

Regards
Manish
thumbnail
Vitaliy Koshelenko, modificado hace 11 años.

RE: Setting Preferred Language

Expert Mensajes: 319 Fecha de incorporación: 25/03/11 Mensajes recientes
Yes, user will see the portal in that particular language.
thumbnail
Manish Kumar Jaiswal, modificado hace 11 años.

RE: Setting Preferred Language

Regular Member Mensajes: 153 Fecha de incorporación: 25/11/08 Mensajes recientes
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
thumbnail
Vitaliy Koshelenko, modificado hace 11 años.

RE: Setting Preferred Language

Expert Mensajes: 319 Fecha de incorporación: 25/03/11 Mensajes recientes
You can change the language for current user's session like this:

Locale locale = LocaleUtil.fromLanguageId(languageId);
session.setAttribute(org.apache.struts.Globals.LOCALE_KEY, locale);
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: Setting Preferred Language

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Vitaliy, thank you for the reply but the question is setting another users language from a portlet and not the current user.
MICHAIL MOUDATSOS, modificado hace 11 años.

RE: Setting Preferred Language

Regular Member Mensajes: 110 Fecha de incorporación: 4/10/11 Mensajes recientes
Vitaliy Koshelenko:
You can change the language for current user's session like this:

Locale locale = LocaleUtil.fromLanguageId(languageId);
session.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.
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: Setting Preferred Language

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
May have to do the following

PortletPreferences prefs = request.getPreferences();
prefs.setValue(...);
PortletPreferencesLocalServiceUtil.updatePreferences(prefs);
thumbnail
Manish Kumar Jaiswal, modificado hace 11 años.

RE: Setting Preferred Language

Regular Member Mensajes: 153 Fecha de incorporación: 25/11/08 Mensajes recientes
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