質問編集履歴
2
ソースコード追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,6 +23,54 @@
|
|
23
23
|
//messages_en.properties
|
24
24
|
company = Company
|
25
25
|
```
|
26
|
+
|
27
|
+
```ここに言語を入力
|
28
|
+
package com.toray.controller;
|
29
|
+
|
30
|
+
import java.security.Principal;
|
31
|
+
import java.util.Locale;
|
32
|
+
|
33
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
34
|
+
import org.springframework.security.core.Authentication;
|
35
|
+
import org.springframework.ui.Model;
|
36
|
+
import org.springframework.web.bind.annotation.ControllerAdvice;
|
37
|
+
import org.springframework.web.bind.annotation.ModelAttribute;
|
38
|
+
|
39
|
+
import com.toray.entity.User;
|
40
|
+
import com.toray.repository.UserRepository;
|
41
|
+
|
42
|
+
@ControllerAdvice(basePackages = "com.xxx.controller")
|
43
|
+
public class AppController {
|
44
|
+
|
45
|
+
@Autowired
|
46
|
+
UserRepository userRepository;
|
47
|
+
|
48
|
+
@ModelAttribute("user")
|
49
|
+
public User addOneObject(Principal principal, Model model) {
|
50
|
+
Authentication authentication = (Authentication) principal;
|
51
|
+
User user = (User) authentication.getPrincipal();
|
52
|
+
User myuser = userRepository.findByIdEquals(user.getId());
|
53
|
+
Integer languageflg = myuser.getLanguageflg();
|
54
|
+
this.setLang(languageflg);
|
55
|
+
model.addAttribute("languageflg", languageflg);
|
56
|
+
return user;
|
57
|
+
}
|
58
|
+
|
59
|
+
public void setLang(Integer languageflg)
|
60
|
+
{
|
61
|
+
switch(languageflg) {
|
62
|
+
case 2:
|
63
|
+
Locale.setDefault(Locale.JAPANESE);
|
64
|
+
System.out.println(Locale.getDefault());
|
65
|
+
break;
|
66
|
+
default:
|
67
|
+
Locale.setDefault(Locale.ENGLISH);
|
68
|
+
System.out.println(Locale.getDefault());
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
```
|
26
74
|
各言語ごとの表示内容は、messages.propertiesに定義しています。
|
27
75
|
動いている場所が違うので不可能でしょうか?
|
28
76
|
ご教示頂けますと幸いです。
|
1
ソースコード追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,8 +11,18 @@
|
|
11
11
|
ViewはThymeleafを使用しています。
|
12
12
|
各項目は、下記のように表示しており、
|
13
13
|
```ここに言語を入力
|
14
|
+
//Thymeleaf
|
14
|
-
th:utext="#{
|
15
|
+
th:utext="#{company}";
|
15
16
|
```
|
17
|
+
```ここに言語を入力
|
18
|
+
//messages_ja.properties
|
19
|
+
company = 会社
|
20
|
+
```
|
21
|
+
|
22
|
+
```ここに言語を入力
|
23
|
+
//messages_en.properties
|
24
|
+
company = Company
|
25
|
+
```
|
16
26
|
各言語ごとの表示内容は、messages.propertiesに定義しています。
|
17
27
|
動いている場所が違うので不可能でしょうか?
|
18
28
|
ご教示頂けますと幸いです。
|