掲示板

Setting Preferred Language

thumbnail
11年前 に Manish Kumar Jaiswal によって更新されました。

Setting Preferred Language

Regular Member 投稿: 153 参加年月日: 08/11/25 最新の投稿
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
11年前 に Vitaliy Koshelenko によって更新されました。

RE: Setting Preferred Language

Expert 投稿: 319 参加年月日: 11/03/25 最新の投稿
Hi! You can just change languageId for user, for example:

user.setLanguageId(languageId);


Vitaliy
thumbnail
11年前 に Manish Kumar Jaiswal によって更新されました。

RE: Setting Preferred Language

Regular Member 投稿: 153 参加年月日: 08/11/25 最新の投稿
Thanks Vitaliy

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

Regards
Manish
thumbnail
11年前 に Vitaliy Koshelenko によって更新されました。

RE: Setting Preferred Language

Expert 投稿: 319 参加年月日: 11/03/25 最新の投稿
Yes, user will see the portal in that particular language.
thumbnail
11年前 に Manish Kumar Jaiswal によって更新されました。

RE: Setting Preferred Language

Regular Member 投稿: 153 参加年月日: 08/11/25 最新の投稿
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
11年前 に Vitaliy Koshelenko によって更新されました。

RE: Setting Preferred Language

Expert 投稿: 319 参加年月日: 11/03/25 最新の投稿
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
11年前 に Hitoshi Ozawa によって更新されました。

RE: Setting Preferred Language

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
Vitaliy, thank you for the reply but the question is setting another users language from a portlet and not the current user.
11年前 に MICHAIL MOUDATSOS によって更新されました。

RE: Setting Preferred Language

Regular Member 投稿: 110 参加年月日: 11/10/04 最新の投稿
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
11年前 に Hitoshi Ozawa によって更新されました。

RE: Setting Preferred Language

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
May have to do the following

PortletPreferences prefs = request.getPreferences();
prefs.setValue(...);
PortletPreferencesLocalServiceUtil.updatePreferences(prefs);
thumbnail
11年前 に Manish Kumar Jaiswal によって更新されました。

RE: Setting Preferred Language

Regular Member 投稿: 153 参加年月日: 08/11/25 最新の投稿
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