Foren

Changing user language instantly

thumbnail
Paul Schmidt, geändert vor 11 Jahren.

Changing user language instantly

Junior Member Beiträge: 34 Beitrittsdatum: 28.07.10 Neueste 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:

user = UserServiceUtil.getUserById(Long.parseLong(request.getUserPrincipal().getName()));
user.setLanguageId(selectedLanguage);
UserLocalServiceUtil.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
thumbnail
Gaurav Jain, geändert vor 11 Jahren.

RE: Changing user language instantly

Regular Member Beiträge: 145 Beitrittsdatum: 31.01.11 Neueste 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.
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Changing user language instantly

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste 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)
thumbnail
Paul Schmidt, geändert vor 11 Jahren.

RE: Changing user language instantly

Junior Member Beiträge: 34 Beitrittsdatum: 28.07.10 Neueste 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?
thumbnail
Vitaliy Koshelenko, geändert vor 11 Jahren.

RE: Changing user language instantly

Expert Beiträge: 319 Beitrittsdatum: 25.03.11 Neueste Beiträge
Hi!
You can also change the current language programmatically by changing the locale:

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


This should change the current language immediately.

Vitaliy