Grails:读取资源包
我尝试从资源包获取消息/翻译列表,但失败(引发异常)。该应用程序正在 IDEA 的 Tomcat 上运行:
Locale locale = new Locale("en");
ResourceBundle bundle = ResourceBundle.getBundle('i18n/dictionary', locale);
这里出了什么问题。 i18n/dictionary 在类路径上。可能是“i18n/dictionary”是错误的。
我能够获取消息源,但无法从此(SPRING)对象获取密钥:
def messageSource = grailsAttributes.getApplicationContext().getBean("messageSource");
I tried to get list of message/translations from resource bundle but it fails (throws exception). The app is running on Tomcat from IDEA:
Locale locale = new Locale("en");
ResourceBundle bundle = ResourceBundle.getBundle('i18n/dictionary', locale);
What is wrong here. i18n/dictionary is on class path. Could be 'i18n/dictionary' is wrong.
I'm able to get message source, but I can't get keys from this (SPRING) object:
def messageSource = grailsAttributes.getApplicationContext().getBean("messageSource");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
资源路径不完整。如果您需要前端的转换表,也许以下控制器可能有用:
}
The resource path was incomplete. If you need the translation table on the front-end, maybe the following controller could be useful:
}
这对我有用。
this works for me.