【问题标题】:Getting Message from all resource files in different locale from a key从一个键的​​不同语言环境中的所有资源文件中获取消息
【发布时间】:2014-09-09 11:29:44
【问题描述】:

在基于 JSF 的项目中,我有不同的语言环境文件用于向用户发送消息。 我想使用 Key 从我的项目中可用的所有语言环境中检索消息

我在托管 bean 中使用

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

我希望所有消息作为一个数组或列表与所有资源包中的此键相关联,而不是一个字符串,例如 messages.properties、messages_hin.properties 等。

【问题讨论】:

    标签: jsf properties locale


    【解决方案1】:

    由于您已经知道如何获取特定于语言环境的捆绑包,然后通过密钥获取其消息,因此不需要回答该部分,您唯一的问题基本上可以归结为:

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

    您可以通过Application#getSupportedLocales() 获取所有支持的语言环境。

    Application application = FacesContext.getCurrentInstance().getApplication();
    Iterator<Locale> supportedLocales = application.getSupportedLocales();
    
    while (supportedLocales.hasNext()) {
        Locale supportedLocale = supportedLocales.next();
        // ...
    }
    

    【讨论】:

    • 非常感谢您的完美回答:)
    猜你喜欢
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2012-06-08
    相关资源
    最近更新 更多