Change the User Language Programatically

thumbnail
Syed Ali, modified 5 Years ago. New Member Posts: 15 Join Date: 5/28/14 Recent Posts
Hi Guys,Please let me know how can i change the User Language  Programatically in Portlet controller, in Liferay 7.2.
I tried with the below code snippet but its not working in Liferay 7.2,
session.setAttribute("org.apache.struts.action.LOCALE", locale);
thumbnail
krishna patel, modified 5 Years ago. New Member Posts: 14 Join Date: 5/21/18 Recent Posts
Hi Syed Ali,
Try to update cookie as well,

session.setAttribute(WebKeys.LOCALE, locale);
LanguageUtil.updateCookie(request, response, locale);


If you are trying to update language for signed user and want to persist that language for future then also update it in user profile. Please find reference here https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/action/UpdateLanguageAction.java line 87.