Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Paul Schmidt
Changing user language instantly
2. November 2012 00:19
Antwort

Paul Schmidt

Rang: Junior Member

Nachrichten: 34

Eintrittsdatum: 28. Juli 2010

Neue Beiträge

Hello Community,

there are two ways to change users display language.
Control Panel --> My Account --> Display Settings
If I change the language there, it's instantly changed and everything has the selected language.

Programmatically with:
1
2user = UserServiceUtil.getUserById(Long.parseLong(request.getUserPrincipal().getName()));
3user.setLanguageId(selectedLanguage);
4UserLocalServiceUtil.updateUser(user);


This method works fine and persists the new user language. You can check it, when you have a look at control panel

The problem is: The portal is displayed with the selected language only after relogin! How can I achieve a portal reload with the new language settings?

LR 6.1.0 GA1 bundled with TomCat

BR Paul
Gaurav Jain
RE: Changing user language instantly
2. November 2012 03:21
Antwort

Gaurav Jain

Rang: Regular Member

Nachrichten: 146

Eintrittsdatum: 31. Januar 2011

Neue Beiträge

Have you also tried method:
updateUser(User user, boolean merge)

http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/service/UserLocalServiceUtil.html#updateUser(com.liferay.portal.model.User, boolean)
Parameters:
user - the user
merge - whether to merge the user with the current session. See BatchSession.update(com.liferay.portal.kernel.dao.orm.Session, com.liferay.portal.model.BaseModel, boolean) for an explanation.
Hitoshi Ozawa
RE: Changing user language instantly
2. November 2012 05:58
Antwort

Hitoshi Ozawa

Rang: Liferay Legend

Nachrichten: 7949

Eintrittsdatum: 23. März 2010

Neue Beiträge

That's because you're changing the language saved to the user and not changing the current language variable in the themeDisplay.setLanguageId(String languageId)
Paul Schmidt
RE: Changing user language instantly
5. November 2012 08:33
Antwort

Paul Schmidt

Rang: Junior Member

Nachrichten: 34

Eintrittsdatum: 28. Juli 2010

Neue Beiträge

Thank you for the answers,

unfortunately both solutions didn't made the trick.

I debugged into my sources.
On first request
themeDisplay.getLanguageId() is en_US

I change the Language:
themeDisplay.setLanguageId(de_DE);

but on next click in portal
themeDisplay.getLanguageId() is en_US again

Why?
Vitaliy Koshelenko
RE: Changing user language instantly
5. November 2012 13:57
Antwort

Vitaliy Koshelenko

Rang: Expert

Nachrichten: 286

Eintrittsdatum: 25. März 2011

Neue Beiträge

Hi!
You can also change the current language programmatically by changing the locale:

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


This should change the current language immediately.

Vitaliy