从密钥中获取来自不同语言环境中的所有资源文件的消息 [英] Getting Message from all resource files in different locale from a key

查看:110
本文介绍了从密钥中获取来自不同语言环境中的所有资源文件的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同的语言环境文件,用于在基于JSF的Project中向用户发送消息. 我想使用Key

I have different locale file for messages to user in JSF based Project. i want to retrieve messages from all locale available in my project using Key

我在托管bean中使用

I am using in managed bean

    String message=ResourceBundle.getBundle("com.tech.resources.messages",
              new Locale(loggedInUser.getLanguage())).getString("label.hostel.room.allocated"); 

我希望所有消息包(例如messages.properties,messages_hin.properties等)中的所有消息都以数组或列表的形式与此键相关联,而不是一个字符串.

Instead of one String i want all messages as a array or list assosiated with this key in all resource bundles like messages.properties, messages_hin.properties etc.

推荐答案

您已经了解了如何获取特定于语言环境的捆绑包,然后按键获取其消息,因此该部分无需回答,您唯一的问题基本上可以归结为:

As you've already figured how to get a locale-specific bundle and then get its message by key and that part thus doesn't need to be answered, your sole question basically boils down to:

如何获取JSF应用程序的所有受支持的语言环境?

您可以通过 Application#getSupportedLocales() .

You can get all supported locales by Application#getSupportedLocales().

Application application = FacesContext.getCurrentInstance().getApplication();
Iterator<Locale> supportedLocales = application.getSupportedLocales();

while (supportedLocales.hasNext()) {
    Locale supportedLocale = supportedLocales.next();
    // ...
}

这篇关于从密钥中获取来自不同语言环境中的所有资源文件的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆