Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

Save & Get Locale From Redis in Spring

$
0
0

I need to save user locale to a Redis, and use it after user sign in. Now I am using CookieLocaleResolver() and it works only in one browser. I want to save locale in my Redis database and then get it for user to display web site on his own language on all web browsers. I am saving user session in Redis now. Actually I am using PostgreSQL & Redis. I want to do it via Redis for high speed. Please give me an advice using Redis or at least Postgre(in the user column). Here is my configuration code for locale.

    @Bean
        public LocaleResolver localeResolver() {
            return new CookieLocaleResolver();
        }
        @Bean
        public LocaleChangeInterceptor localeChangeInterceptor() {
            LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
            lci.setParamName("lang");
            return lci;
        }

        @Bean
        public MessageSource messageSource() {
            ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
            messageSource.setBasename("classpath:locale/Language");
            messageSource.setDefaultEncoding("UTF-8");
            return messageSource;
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(localeChangeInterceptor());
        }
    }



<select id="locales" class="mr-2" onchange="languageSelector()">
       <option value="" th:text="#{lang.chooser}"/>
       <option value="en_US" th:text="#{lang.eng}"/>
       <option value="uk_UA" th:text="#{lang.ua}"/>
</select>


function languageSelector() {
        let selectedOption = $('#locales').val();
        if (selectedOption != ''){
            window.location.replace(location.pathname + '?lang=' + selectedOption);
    }
}

Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>