掲示板
Changing user language instantly
11年前 に Paul Schmidt によって更新されました。
Changing user language instantly
Junior Member 投稿: 34 参加年月日: 10/07/28 最新の投稿
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:
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
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
11年前 に Gaurav Jain によって更新されました。
RE: Changing user language instantly
Regular Member 投稿: 145 参加年月日: 11/01/31 最新の投稿
Have you also tried method:
updateUser(User user, boolean merge)
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.
11年前 に Hitoshi Ozawa によって更新されました。
RE: Changing user language instantly
Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
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)
11年前 に Paul Schmidt によって更新されました。
RE: Changing user language instantly
Junior Member 投稿: 34 参加年月日: 10/07/28 最新の投稿
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?
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?
11年前 に Vitaliy Koshelenko によって更新されました。
RE: Changing user language instantly
Expert 投稿: 319 参加年月日: 11/03/25 最新の投稿
Hi!
You can also change the current language programmatically by changing the locale:
This should change the current language immediately.
Vitaliy
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