1 2 Previous Next 22 Replies Latest reply on Jun 26, 2011 11:48 PM by roliveira.ricardo.martinelli.oliveira.gmail.com

    Seam International Module

    elfuhrer

      The documentation in seam international is confusing, the snapshots docs and the seam-3.0.0.Final release docs are very different.


      I'm trying to localize a sample application to support three languages and I can't get it done, for some reason changing the locale doesn't update the messages.


      I have the following in beans.xml




      <beans xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:s="urn:java:seam:core" 
              xmlns:lc="urn:java:org.jboss.seam.international.locale"
              xsi:schemaLocation="
                  http://java.sun.com/xml/ns/javaee 
                  http://docs.jboss.org/cdi/beans_1_0.xsd">
      
          <lc:AvailableLocales>
              <s:specializes/>
              <lc:supportedLocaleKeys>
                  <s:value>en</s:value>
                  <s:value>fr</s:value>
              </lc:supportedLocaleKeys>
          </lc:AvailableLocales>
      </beans>
      



      I have in the webapp resource's folder the properties files, resources.properties and resources_fr_FR.properties


      The following is my faces-config.xml configuration




      <?xml version="1.0"?>
      <faces-config 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_2_0.xsd"
                    version="2.0">
          <application>
              <resource-bundle>
                  <base-name>resources</base-name>
                  <var>resources</var>
              </resource-bundle>
          </application>    
      </faces-config>



      the following bean handles switching the locales:




      @Named
      public class LocaleManager extends LocaleConfiguration {
      
          @Inject
          List<java.util.Locale> locales;
      
          @Inject
          @Alter
          @Client
          private Event<java.util.Locale> localeEvent;
      
          @Inject
          private java.util.Locale locale;
      
          @PostConstruct
          public void initLocales() {
              addSupportedLocaleKey("en");
              addSupportedLocaleKey("fr");
          }
      
          public void updateLanguage() {
              locale = Locale.FRANCE;
              localeEvent.fire(locale);
          }
      }



      and finally i'm firing the event from a jsf form



      <h:form>
          <h:commandButton value="Update Locale" action="#{localeManager.updateDefaultLocale}" />
      </h:form>




      When I click on the button the messages are not changed, what am I missing in here?


        • 1. Re: Seam International Module
          elfuhrer

          A minor typo



          <h:form>
              <h:commandButton value="Update Locale" action="#{localeManager.updateDefaultLocale}" />
          </h:form>



          • 2. Re: Seam International Module
            elfuhrer

            Grrrr


            <h:form>
                <h:commandButton value="Update Locale" action="#{localeManager.updateLanguage}" />
            </h:form>
            



            • 3. Re: Seam International Module
              spinner.joserodolfo.freitas.gawab.com
              Fady,




              if you're sure that the action has been called, try to rename your resource to resources_fr.property, have you tried that?
              • 4. Re: Seam International Module
                juergen.zimmermann

                IMHO, the following lines (in the first posting)
                    @Inject
                    private java.util.Locale locale;


                have to be changed to:
                    @Inject
                    @Client
                    private java.util.Locale locale;

                • 5. Re: Seam International Module
                  elfuhrer

                  Already tried that and it didn't work out, the action is being called I can debug it and perform other stuff within it.

                  • 6. Re: Seam International Module
                    elfuhrer

                    Moreover I have tried annotating the locale with @Client, that didn't change a thing. I can see the messages defaulting to the default locale, switching locales is still not working

                    • 7. Re: Seam International Module
                      elfuhrer

                      I took my tests even further, I have modified my system's OS locale to french and the message bundles are loading perfectly, yet I still can't set the locale to any language. I have no clue if this is a bug in the module or some stupid detail I have missed...

                      • 8. Re: Seam International Module
                        spinner.joserodolfo.freitas.gawab.com

                        Fady,


                        Do you have a simple testCase for your problem?

                        • 9. Re: Seam International Module
                          kenfinni

                          I can't think of anything that would cause this not to work.


                          Is the updateLanguage() method always meant to set the Locale to French?


                          Ken

                          • 10. Re: Seam International Module
                            elfuhrer

                            Same here Ken, I'm totally puzzled.


                            The update language is explicitly setting the language to French.


                            public void updateLanguage() {
                                locale = Locale.FRANCE;
                                localeEvent.fire(locale);
                            }



                            • 11. Re: Seam International Module
                              spinner.joserodolfo.freitas.gawab.com

                              Fady,


                              would you please fire a jira issue and attach a little application with the problem so we could dig through it?


                              https://issues.jboss.org/browse/SEAMINTL

                              • 12. Re: Seam International Module
                                kenfinni

                                Good idea Jose.


                                Fady, have you tried running the Booking example app at all?  Should have the same functionality that you want to use.


                                From looking at the code the only difference I've found so far is Booking called their properties files messages instead of resources, though that should not make an iota of a difference.


                                Ken

                                • 13. Re: Seam International Module
                                  ssachtleben.ssachtleben.gmail.com

                                  Not sure whats going wrong there but this worked for me in CR1 (I have no multi-lang application with final version now):


                                  /**
                                  * The locale selector allows the user to change the locale for displaying messages in faclet.
                                  *
                                  * @author <a href="http://community.jboss.org/people/ssachtleben">Sebastian
                                  * Sachtleben</a>
                                  */
                                  @Stateful
                                  @Named
                                  @SessionScoped
                                  public class LocaleSelector {
                                            
                                       @Inject
                                       @Client
                                       private Locale locale;
                                  
                                       @Inject
                                       @Alter
                                       @Client
                                       private Event<Locale> event;     
                                       
                                       @Inject 
                                       private List<Locale> supportedLocales;
                                       
                                       public List<Locale> getSupportedLocales() {
                                            return supportedLocales;
                                       }          
                                       
                                       public Locale getLocale() {
                                            return locale;
                                       }     
                                       
                                       public void setLocale(Locale locale) {
                                            this.locale = locale;
                                            event.fire(locale);
                                       }
                                       
                                  }



                                  Btw you should get the full available languages by using this:


                                       @Inject 
                                       private List<Locale> supportedLocales;



                                  I think your problem is that you have set up locales in the configuration and also add additional languages in your bean so maybe the equals function fails and the locale selection doesnt work.


                                  Check out my test webapp here: https://issues.jboss.org/browse/SEAMINTL-29
                                  You have to switch from seam CR1 to Final in pom.xml and the lanuage selection should work fine :)


                                  Good luck!

                                  • 14. Re: Seam International Module
                                    elfuhrer

                                    I downloaded the seam-i18n.zip archive and it wouldn't run, there's an exception indicating that the message bundle is null,



                                    at org.jboss.seam.international.examples.i18n.MessageBundle.get(MessageBundle.java:38) [:]



                                    I guess it's a problem with the internationalization module in here.


                                    1 2 Previous Next