关于spring:Grails:阅读资源包 | 珊瑚贝

Grails: Reading the Resource Bundle


我试图从资源包中获取消息/翻译列表,但它失败了(抛出异常)。该应用程序正在 IDEA 的 Tomcat 上运行:

1
2
Locale locale = new Locale(“en”);
ResourceBundle bundle = ResourceBundle.getBundle(‘i18n/dictionary’, locale);

这里有什么问题。 i18n/dictionary 在类路径上。可能是 \\’i18n/dictionary\\’ 错误。

我可以得到消息源,但是我不能从这个(SPRING)对象中得到密钥:

1
def messageSource = grailsAttributes.getApplicationContext().getBean(“messageSource”);

资源路径不完整。如果您需要前端的转换表,也许以下控制器可能有用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class ClientMessagesController {

def index = {
    Locale locale = session.getAttribute(‘locale’) ?: new Locale(“en”);
    ResourceBundle bundle = ResourceBundle.getBundle(‘\\\\grails-app\\\\i18n\\\\clientMessages’, locale);

    def sep = ”;
    def sb = new StringBuilder();
    sb.append(‘<script type=”text/javascript”>\
‘);
    sb.append(‘_i18n = {\
‘);
    bundle.getKeys().each {key ->
        sb.append(sep);
        sb.append(key.replace(‘.’, ‘_’));
        sb.append(‘:”‘);
        sb.append(bundle.getString(key).replace(‘”‘, ‘”‘));
        sb.append(‘”\
‘);
        sep = ‘,’;
    }
    sb.append(‘};\
\
‘)
    render(text: sb.toString());
}

}

  • 不要自己构建 JSON,使用 JsonBuilder


来源:https://www.codenong.com/9072565/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8628.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?