7 Replies Latest reply on Mar 21, 2007 2:27 AM by grdzeli_kaci

    language resource bundle example

      is there any sample about it ? i can't find anything.

      i need language manipulation into seam,

      i tryed by myself but it is not working

      1.i have 2 properties file messages_en.properties and messages_ka.properties
      both of them contains the same propertie for example
      english
      _userName=UserName

      georgian
      _userName=????????????


      2. i have configured components.xml file

       <component name="org.jboss.seam.core.resourceBundle">
       <property name="bundleNames">
       <value>messages</value>
       </property>
       </component>
      



      3. add this tab into build.xml file

      <include name="messages_en.properties" />
      <include name="messages_ka.properties" />
      


      4. than into my login.xhtml file add language choose component
      <h:selectOneMenu styleClass="font_style">
       <f:selectItem itemLabel="English" itemValue="en"/>
       <f:selectItem itemLabel="Georgian" itemValue="ka"/>
       <f:selectItem itemLabel="Deutsch" itemValue="de"/>
       <f:selectItem itemLabel="Francais" itemValue="fr"/>
       </h:selectOneMenu>
      



      and after this page i tryed to use Georgian properties but it does not working i got only english properties


      is here anything wrong ?

      is there any sample application about it ?

        • 1. Re: language resource bundle example

          and i forget i have added this fragment into my faces-config.xml file

           <application>
           <locale-config>
           <default-locale>en</default-locale>
           <supported-locale>en</supported-locale>
           <supported-locale>ka</supported-locale>
           <supported-locale>de</supported-locale>
           <supported-locale>fr</supported-locale>
           </locale-config>
           <message-bundle>messages</message-bundle>
           </application>
          


          • 2. Re: language resource bundle example
            waynebagguley

            I don't have any of those configs and resource bundles work a treat.

            In your <h:selectOneMenu> tag, you don't specify where it is supposed to store the selected value.

            Here is the code taken from the Seam v1.2 documentation:

            <h:selectOneMenu value="#{localeSelector.language}">
             <f:selectItem itemLabel="English" itemValue="en"/>
             <f:selectItem itemLabel="Deutsch" itemValue="de"/>
             <f:selectItem itemLabel="Francais" itemValue="fr"/>
            </h:selectOneMenu>
            <h:commandButton action="#{localeSelector.select}" value="#{messages['ChangeLanguage']}"/>


            • 3. Re: language resource bundle example

              hi again,
              i think that it is a bug in seam or jsf :(

              i tryed this for three language : english (en) , german(de), francias (fr) and georegian(ka)

              georgian is not working :(

              code snippet

              <h:selectOneMenu value="#{localeSelector.language}">
               <f:selectItem itemLabel="English" itemValue="en"/>
               <f:selectItem itemLabel="Deutsch" itemValue="de"/>
               <f:selectItem itemLabel="Francais" itemValue="fr"/>
              </h:selectOneMenu>
              <h:commandButton action="#{localeSelector.select}" value="#{messages['ChangeLanguage']}"/>
              


              all works, but not ka(Georgian)

              and one another question how i can use both login event and local selector event on one command button ?



              • 4. Re: language resource bundle example

                 

                "grdzeli_kaci" wrote:
                i have added this fragment into my faces-config.xml file
                <locale-config>
                 :
                 <supported-locale>en</supported-locale>
                 :
                </locale-config>

                I think the supported-locale's are only needed when NOT explictely listing the available languages in the selectOneMenu. So, when using the list in faces-config.xml then your language selector could look like this:
                <h:selectOneMenu value="#{localeSelector.localeString}">
                 <f:selectItems value="#{localeSelector.supportedLocales}"/>
                </h:selectOneMenu>
                <h:commandButton action="#{localeSelector.select}" value="#{messages['ChangeLanguage']}"/>

                (taken from the Seam documentation)

                But this is not the cause of your problem; waynebagguley already explained what's wrong.

                If you want to change the language without a button then see HOWTO: override ThemeSelector (valueChangeListener, cookie name).

                • 5. Re: language resource bundle example
                  waynebagguley

                  The locale "ka(Georgian)" is not supported by Java.

                  • 6. Re: language resource bundle example

                     

                    "waynebagguley" wrote:
                    The locale "ka(Georgian)" is not supported by Java.


                    i think java supports ka(Georgian). I build example without seam, sample jsf project (or JSP project) and everithing works fine. here is my jsf example:

                    1. faces-config.xml
                     <application>
                     <locale-config>
                     <default-locale>en</default-locale>
                     <supported-locale>en</supported-locale>
                     <supported-locale>ka</supported-locale>
                     </locale-config>
                     </application>
                    


                    2. I created two Language property files:

                    LocalizationResources_en.properties
                    hello=HELLO WORLD EN!

                    LocalizationResources_ka.properties
                    hello=HELLO WORLD KA!


                    3. Login page:
                     <h:form id="loginForm">
                     <h:panelGrid columns="2">
                     <h:outputText value="Language: " />
                     <h:selectOneMenu value="#{loginBean.language}">
                     <f:selectItem itemValue="ka" itemLabel="Georgian"/>
                     <f:selectItem itemValue="en" itemLabel="English"/>
                     </h:selectOneMenu>
                     </h:panelGrid>
                     <h:commandButton action="#{loginBean.doLogin}" value="Log In" id="gbutton" />
                     </h:form>
                    



                    4. LoginBean.java
                    
                     private String language;
                    
                     ................................
                    
                     public String doLogin() {
                    
                     FacesContext facesContext = FacesContext.getCurrentInstance();
                     Locale locale = new Locale(language);
                     facesContext.getViewRoot().setLocale(locale);
                    
                     return "navigation";
                    
                     }
                    


                    5. and at last result page after language choose:
                    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
                    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
                    <f:loadBundle basename="LocalizationResources" var="bundle"/>
                    
                    <html>
                     <head>
                     <title></title>
                     </head>
                     <body>
                     <f:view locale="">
                     <h:outputText value="#{bundle.hello}" />
                     </f:view>
                     </body>
                    </html>
                    


                    all works fine, if i choose Georgian from select item componet on result page i saw georgian caption otherwise i saw english captions


                    i think that problem is in seam not java or jsf.




                    ooo yes avbentem, i forget i have this documentation and i did all what there is, all works fine, only georegian has problem.

                    my select item component looks like :

                     <h:selectOneMenu
                     value="#{localeSelector.localeString}"
                     onchange="submit();"
                     valueChangeListener="#{localeSelector.select}">
                     <f:selectItems value="#{localeSelector.supportedLocales}" />
                     </h:selectOneMenu>
                    


                    and faces-config.xml i wrote above.



                    • 7. Re: language resource bundle example

                      i don't understand what happend but it already working
                      Georgian also working
                      sorry,
                      great thanks for your helpfull posts :)
                      waynebagguley avbentem