locale message fix
This commit is contained in:
@@ -356,11 +356,37 @@ public final class WebContext {
|
||||
* @return
|
||||
*/
|
||||
public static String getI18nValue(String code) {
|
||||
return code;
|
||||
String message = code;
|
||||
try {
|
||||
message = getApplicationContext().getMessage(
|
||||
code.toString(),
|
||||
null,
|
||||
getLocale());
|
||||
} catch (Exception e) {
|
||||
//
|
||||
e.printStackTrace();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* getI18nValue.
|
||||
* @param code String
|
||||
* @param filedValues Object
|
||||
* @return
|
||||
*/
|
||||
public static String getI18nValue(String code, Object[] filedValues) {
|
||||
return code;
|
||||
String message = code;
|
||||
try {
|
||||
message = getApplicationContext().getMessage(
|
||||
code.toString(),
|
||||
filedValues,
|
||||
getLocale());
|
||||
} catch (Exception e) {
|
||||
//
|
||||
e.printStackTrace();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
//TODO:
|
||||
|
||||
@@ -14,35 +14,41 @@ import freemarker.template.TemplateDirectiveBody;
|
||||
import freemarker.template.TemplateDirectiveModel;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateModel;
|
||||
|
||||
/**
|
||||
* 获取应用上下文标签
|
||||
* <@locale/>
|
||||
* 获取应用上下文标签 <@locale/>
|
||||
*
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
|
||||
@FreemarkerTag("locale")
|
||||
public class LocaleTagDirective implements TemplateDirectiveModel {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(LocaleTagDirective.class);
|
||||
@Autowired
|
||||
private static final Logger _logger = LoggerFactory.getLogger(LocaleTagDirective.class);
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||
throws TemplateException, IOException {
|
||||
WebApplicationContext webApplicationContext =RequestContextUtils.findWebApplicationContext(request);
|
||||
if(params.get("code")==null) {
|
||||
env.getOut().append(RequestContextUtils.getLocale(request).getLanguage());
|
||||
}else {
|
||||
_logger.trace("message code "+params.get("code"));
|
||||
try {
|
||||
env.getOut().append(webApplicationContext.getMessage(params.get("code").toString(), null, RequestContextUtils.getLocale(request)));
|
||||
|
||||
}catch(Exception e) {
|
||||
_logger.error("message code "+params.get("code"),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void execute(Environment env,
|
||||
Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||
throws TemplateException, IOException {
|
||||
WebApplicationContext webApplicationContext =
|
||||
RequestContextUtils.findWebApplicationContext(request);
|
||||
if (params.get("code") == null) {
|
||||
env.getOut().append(RequestContextUtils.getLocale(request).getLanguage());
|
||||
} else {
|
||||
_logger.trace("message code " + params.get("code"));
|
||||
try {
|
||||
env.getOut().append(
|
||||
webApplicationContext.getMessage(
|
||||
params.get("code").toString(),
|
||||
null,
|
||||
RequestContextUtils.getLocale(request)));
|
||||
|
||||
} catch (Exception e) {
|
||||
_logger.error("message code " + params.get("code"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user