|
9 | 9 | import org.nutz.lang.util.Context; |
10 | 10 | import org.nutz.lang.util.NutMap; |
11 | 11 | import org.nutz.mvc.config.AtMap; |
| 12 | +import org.nutz.mvc.i18n.LocalizationManager; |
12 | 13 | import org.nutz.mvc.impl.NutMessageMap; |
13 | 14 | import org.nutz.mvc.ioc.SessionIocContext; |
14 | 15 |
|
@@ -51,14 +52,25 @@ public abstract class Mvcs { |
51 | 52 | public static boolean DISABLE_X_POWERED_BY = false; |
52 | 53 |
|
53 | 54 | public static String X_POWERED_BY = "nutz/"+Nutz.version()+" <nutzam.com>"; |
| 55 | + |
| 56 | + public static LocalizationManager localizationManager; |
| 57 | + |
| 58 | + public static void setLocalizationManager(LocalizationManager localizationManager) { |
| 59 | + Mvcs.localizationManager = localizationManager; |
| 60 | + } |
54 | 61 |
|
55 | 62 | // ==================================================================== |
56 | 63 |
|
57 | | - public static Map<String, Object> getLocaleMessage(String key) { |
58 | | - Map<String, Map<String, Object>> msgss = getMessageSet(); |
59 | | - if (null != msgss) |
60 | | - return msgss.get(key); |
61 | | - return null; |
| 64 | + public static Map<String, Object> getLocaleMessage(String local) { |
| 65 | + if (localizationManager != null) { |
| 66 | + return localizationManager.getMessageMap(local); |
| 67 | + } |
| 68 | + else { |
| 69 | + Map<String, Map<String, Object>> msgss = getMessageSet(); |
| 70 | + if (null != msgss) |
| 71 | + return msgss.get(local); |
| 72 | + return null; |
| 73 | + } |
62 | 74 | } |
63 | 75 |
|
64 | 76 | /** |
@@ -175,24 +187,30 @@ public static String getDefaultLocalizationKey() { |
175 | 187 | */ |
176 | 188 | public static void updateRequestAttributes(HttpServletRequest req) { |
177 | 189 | // 初始化本次请求的多国语言字符串 |
178 | | - Map<String, Map<String, Object>> msgss = getMessageSet(); |
179 | | - if (msgss == null && !ctx().localizations.isEmpty()) |
180 | | - msgss = ctx().localizations.values().iterator().next(); |
181 | | - if (null != msgss) { |
182 | | - Map<String, Object> msgs = null; |
183 | | - |
184 | | - String lKey = Strings.sBlank(Mvcs.getLocalizationKey(), getDefaultLocalizationKey()); |
185 | | - |
186 | | - if (!Strings.isBlank(lKey)) |
187 | | - msgs = msgss.get(lKey); |
188 | | - |
189 | | - // 没有设定特殊的 Local 名字,随便取一个 |
190 | | - if (null == msgs) { |
191 | | - if (msgss.size() > 0) |
192 | | - msgs = msgss.values().iterator().next(); |
| 190 | + if (localizationManager == null) { |
| 191 | + Map<String, Map<String, Object>> msgss = getMessageSet(); |
| 192 | + if (msgss == null && !ctx().localizations.isEmpty()) |
| 193 | + msgss = ctx().localizations.values().iterator().next(); |
| 194 | + if (null != msgss) { |
| 195 | + Map<String, Object> msgs = null; |
| 196 | + |
| 197 | + String lKey = Strings.sBlank(Mvcs.getLocalizationKey(), getDefaultLocalizationKey()); |
| 198 | + |
| 199 | + if (!Strings.isBlank(lKey)) |
| 200 | + msgs = msgss.get(lKey); |
| 201 | + |
| 202 | + // 没有设定特殊的 Local 名字,随便取一个 |
| 203 | + if (null == msgs) { |
| 204 | + if (msgss.size() > 0) |
| 205 | + msgs = msgss.values().iterator().next(); |
| 206 | + } |
| 207 | + // 记录到请求中 |
| 208 | + req.setAttribute(MSG, msgs); |
193 | 209 | } |
194 | | - // 记录到请求中 |
195 | | - req.setAttribute(MSG, msgs); |
| 210 | + } |
| 211 | + else { |
| 212 | + NutMessageMap msg = localizationManager.getMessageMap(Mvcs.getLocalizationKey()); |
| 213 | + req.setAttribute(MSG, msg); |
196 | 214 | } |
197 | 215 |
|
198 | 216 | // 记录一些数据到请求对象中 |
|
0 commit comments