Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Manish Kumar Jaiswal
Setting Preferred Language
7 de Setembro de 2012 05:49
Resposta

Manish Kumar Jaiswal

Ranking: Regular Member

Mensagens: 133

Data de entrada: 25 de Novembro de 2008

Mensagens recentes

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 de Setembro de 2012 12:31
Resposta

Vitaliy Koshelenko

Ranking: Expert

Mensagens: 284

Data de entrada: 25 de Março de 2011

Mensagens recentes

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

1user.setLanguageId(languageId);


Vitaliy
Manish Kumar Jaiswal
RE: Setting Preferred Language
7 de Setembro de 2012 12:34
Resposta

Manish Kumar Jaiswal

Ranking: Regular Member

Mensagens: 133

Data de entrada: 25 de Novembro de 2008

Mensagens recentes

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 de Setembro de 2012 12:36
Resposta

Vitaliy Koshelenko

Ranking: Expert

Mensagens: 284

Data de entrada: 25 de Março de 2011

Mensagens recentes

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

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens recentes

May have to do the following

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

Manish Kumar Jaiswal

Ranking: Regular Member

Mensagens: 133

Data de entrada: 25 de Novembro de 2008

Mensagens recentes

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 de Setembro de 2012 01:30
Resposta

Manish Kumar Jaiswal

Ranking: Regular Member

Mensagens: 133

Data de entrada: 25 de Novembro de 2008

Mensagens recentes

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 de Setembro de 2012 12:33
Resposta

Vitaliy Koshelenko

Ranking: Expert

Mensagens: 284

Data de entrada: 25 de Março de 2011

Mensagens recentes

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 de Setembro de 2012 04:36
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens recentes

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 de Setembro de 2012 05:20
Resposta

MICHAIL MOUDATSOS

Ranking: Regular Member

Mensagens: 110

Data de entrada: 4 de Outubro de 2011

Mensagens recentes

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.