5 Replies Latest reply on Jan 13, 2010 10:04 AM by cheftimo

    Error formatter when change language by resourceManager.

    The_Milky_Way

      I had a problem when use resourceManager to change another language (no english); It causes errors for validating number, datetime; it can't format data correctly; so I can't format and validate data correctly when use Formatter( NumberFormatter, DateFormatter)

      Here the error I found with DateFormatter

      "Cannot access a property or method of a null object reference.

      at mx.formatters::DateBase$/get http://www.adobe.com/2006/flex/mx/internal::defaultStringKey()[C:\autobuild\3.2.0\framewor ks\projects\framework\src\mx\formatters\DateBase.as:173]

      at mx.formatters::DateFormatter$/parseDateString()[C:\autobuild\3.2.0\frameworks\projects\fr amework\src\mx\formatters\DateFormatter.as:156]
      at mx.formatters::DateFormatter/format()[C:\autobuild\3.2.0\frameworks\projects\framework\sr c\mx\formatters\DateFormatter.as:544]"

       

      Please help me!Thanks.

        • 1. Re: Error formatter when change language by resourceManager.
          cheftimo Level 2

          Do you have the appropriate 'sdks\3.1.0\frameworks\locale' folder for whatever locale/language you are working with?

           

          Carlos

          1 person found this helpful
          • 2. Re: Error formatter when change language by resourceManager.
            The_Milky_Way Level 1

            Thanks for your help!

            I created my language folder the same place with english folder(en_US) and It showed language correctly for label, button, alert.... when I change locale; But It caused errors when I validate and format data using DateValidation, DateFormatter, NumberValidation, NumberValidator.

            I have written the following test:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application
               
            creationComplete="{init()}"
               
            xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
               
            viewSourceURL="srcview/index.html">
               
            <mx:NumberValidator source="{testInput}"
                                           
            property="text" minValue="0" domain="real"
                                           
            trigger="{testInput}" triggerEvent="change"
                                           
            valid="testValid=true;"
                                           
            invalid="testValid=false;"
                                           
            />
               
            <mx:Script>
                    <![CDATA[
                    private var testValid : Boolean = true;

                        private function init():void{

                            Languages.setResources(resourceManager);
                        }
                        private function changeLocale(locale:String):void{
                            resourceManager.localeChain=[locale];
                        }
                    ]]>
               
            </mx:Script>
               
            <mx:ApplicationControlBar width="400">
                   
            <mx:Label text="{resourceManager.getString('myResources','TITLE')}"  width="100%"/>
                   
            <mx:Button label="eng" click="changeLocale('en_US')" />
                   
            <mx:Button label="ita" click="changeLocale('it_IT')" />
                   
            <mx:TextInput text="" id="testInput" width="40" />
               
            </mx:ApplicationControlBar>
            </mx:Application>

            //with the following resources


            package 
            {
               
            /**
                 * ...
                 * @author Sebastian Müller
                 */

               
            public class Languages
               
            {
                   
            import mx.resources.IResourceManager;
               
            import mx.resources.ResourceBundle;

                   
            public function Languages() {}
                   
            public static function setResources(resourceManager:IResourceManager):void{


                           
            var myResources:ResourceBundle=new ResourceBundle("en_US","myResources");
                            myResources
            .content['TITLE']="Test";
                            resourceManager
            .addResourceBundle(myResources);


                            myResources
            =new ResourceBundle("it_IT","myResources");
                            myResources
            .content['TITLE']="TestItalian";
                            resourceManager
            .addResourceBundle(myResources);

                            resourceManager
            .update();

                   
            }              
               
            }

            }

            Now the following error occurs. When I start the application my number validation works as expected. When I afterwards switch to italian the number validator don't work anymore.

             

            Do the following steps

             

            1. Type in a number in the text field
            2. Switch to italian
            3. Type in a letter => the text field does not turn into red

             

            Any ideas?

            • 4. Re: Error formatter when change language by resourceManager.
              JabbyPandaUA Level 3

              Hi The Milky way,

               

              Why have not you tried to "google" your runtime exception data, sometimes it is helpful

               

              Here is answer to your problem:

              http://old.nabble.com/DateFormatter-and-dynamic-resource-management-errror-td23070922.html

               

              I've created an related issue at Adobe JIRA 4 months ago, if you consider this issue to be important, please go to JIRA and vote

               

              "dateFormat" value from "SharedResources.properties" should not be shared between DateFields and DateFormatters

              https://bugs.adobe.com/jira/browse/SDK-23104

              • 5. Re: Error formatter when change language by resourceManager.
                cheftimo Level 2

                Hello,Milky Way:

                 

                This thing is not as complicated as it looks. You need to do 2 things:

                 

                1. Read this: http://livedocs.adobe.com/flex/3/html/help.html?content=l10n_7.html.

                 

                2. It would be good if you have a real 'it_IT' locale folder (not just one made by copying 'en_US' and renaming the copy). I do some work with Spanish and a couple of problems I had disappeared when I got a real es_CO resource.

                 

                HTH,

                 

                Carlos

                1 person found this helpful