public void updateUserLocale ( HttpServletRequest request , String localeString ) { IUserInstance ui = userInstanceManager . getUserInstance ( request ) ; IUserPreferencesManager upm = ui . getPreferencesManager ( ) ; final IUserProfile userProfile = upm . getUserProfile ( ) ; LocaleManager localeManager = userProfile . getLocaleManager ( ) ; if ( localeString != null ) { // build a new List<Locale> from the specified locale Locale userLocale = localeManagerFactory . parseLocale ( localeString ) ; List < Locale > locales = Collections . singletonList ( userLocale ) ; // set this locale in the session localeManager . setSessionLocales ( locales ) ; // if the current user is logged in, also update the persisted // user locale final IPerson person = ui . getPerson ( ) ; if ( ! person . isGuest ( ) ) { try { localeManager . setUserLocales ( Collections . singletonList ( userLocale ) ) ; localeStore . updateUserLocales ( person , new Locale [ ] { userLocale } ) ; // remove person layout framgent from session since it contains some of the data // in previous // translation and won't be cleared until next logout-login (applies when using // RDBMDistributedLayoutStore as user layout store). person . setAttribute ( Constants . PLF , null ) ; upm . getUserLayoutManager ( ) . loadUserLayout ( true ) ; } catch ( Exception e ) { throw new PortalException ( e ) ; } } } }
Update the current user s locale to match the selected locale . This implementation will update the session locale and if the user is not a guest will also update the locale in the user s persisted preferences .