お世話になります。
SpringBootで開発しているプロジェクトで、多言語化をしています。
現在は、言語設定を選択した時に、AjaxでDBのLanguageFlagを更新して、
その後に、
location.reload();
で、ページリロードをして言語表示を更新しています。
言語表示の更新もAjaxで行いたいと思っているのですが、可能でしょうか?
ViewはThymeleafを使用しています。
各項目は、下記のように表示しており、
//Thymeleaf th:utext="#{company}";
//messages_ja.properties company = 会社
//messages_en.properties company = Company
package com.toray.controller; import java.security.Principal; import java.util.Locale; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ModelAttribute; import com.toray.entity.User; import com.toray.repository.UserRepository; @ControllerAdvice(basePackages = "com.xxx.controller") public class AppController { @Autowired UserRepository userRepository; @ModelAttribute("user") public User addOneObject(Principal principal, Model model) { Authentication authentication = (Authentication) principal; User user = (User) authentication.getPrincipal(); User myuser = userRepository.findByIdEquals(user.getId()); Integer languageflg = myuser.getLanguageflg(); this.setLang(languageflg); model.addAttribute("languageflg", languageflg); return user; } public void setLang(Integer languageflg) { switch(languageflg) { case 2: Locale.setDefault(Locale.JAPANESE); System.out.println(Locale.getDefault()); break; default: Locale.setDefault(Locale.ENGLISH); System.out.println(Locale.getDefault()); break; } } }
各言語ごとの表示内容は、messages.propertiesに定義しています。
動いている場所が違うので不可能でしょうか?
ご教示頂けますと幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/28 04:00
2018/03/28 04:01
2018/03/28 04:22 編集
2018/03/28 04:41
2018/03/28 04:51
2018/03/28 05:01
2018/03/28 05:19