5 Replies Latest reply on May 4, 2011 2:07 PM by Rafael de Carvalho

    How to load specific resource bundle

    Khosro Asgharifard Sharabiani Newbie
      Hello,
      Imagine we are in  French local and in a controller ,we want to load a message from English local.How we can do it?
      As far as i know we can load messages from bundle with this code :
      [code]
      @In
          private Map<String, String> messages;
          String s = messages.get("delete");
      [/code]
      but the problem is that "s" loads from the local where Seam is,if we are in English locale ,it loads from messages_en and if we are in French ,it loads from messages_fr.
      But in code i want to load a message from French and English simultaneously.How can i do it?

      Khosro.
        • 1. Re: How to load specific resource bundle
          bb bb Master

          You should try the following way:



          myLocale= new java.util.Locale("en");
          SeamResourceBundle.getBundle("messages",myLocale).getString("msg.text");




          • 3. Re: How to load specific resource bundle
            Rafael de Carvalho Newbie

            I'm trying to do the same thing, but I'm getting an exception for any tried locale :



            Exception during request processing:
            Caused by javax.el.ELException with message: java.util.MissingResourceException: Can't find bundle for base name messages, locale en

            Here's a sample code where it fails:
            Locale locale = new Locale("en");
            ResourceBundle bundle = SeamResourceBundle.getBundle("messages", locale);


            I don't know if it helps, but, here's my faces.config:




            <?xml version='1.0' encoding='UTF-8'?>
            <faces-config version="1.2"
                          xmlns="http://java.sun.com/xml/ns/javaee"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
            
                 <application>
                    <locale-config>
                       <default-locale>pt_BR</default-locale>
                       <supported-locale>pt_BR</supported-locale>
                       <supported-locale>en</supported-locale>
                       <supported-locale>es</supported-locale>
                    </locale-config>
                    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
                 </application>
            
            </faces-config>
            



            Thanks in advance!!

            • 4. Re: How to load specific resource bundle
              bb bb Master
              Does your components.xml file contain the following lines?

                   <core:resource-loader>
                        <core:bundle-names>
                             <value>messages</value>
                        </core:bundle-names>
                   </core:resource-loader>
              • 5. Re: How to load specific resource bundle
                Rafael de Carvalho Newbie

                Still getting the same error, even with the update in components.xml.


                Here's my faces config:




                <?xml version='1.0' encoding='UTF-8'?>
                <faces-config version="1.2"
                              xmlns="http://java.sun.com/xml/ns/javaee"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
                
                     <application>
                        <locale-config>
                           <default-locale>pt_BR</default-locale>
                           <supported-locale>pt_BR</supported-locale>
                           <supported-locale>en</supported-locale>
                           <supported-locale>es</supported-locale>
                        </locale-config>
                        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
                     </application>




                Thanks for the help.