9 Replies Latest reply on Jun 30, 2008 3:18 PM by cheftimo

    Localized application glitch

    cheftimo Level 2
      OK, here is a little challenge for those who are into localization. I am re-doing one of the sections in my 'Timos' site in Flex, mainly because there is a cartoon collection you can browse and I don't like how it works in HTML. This is a bilingual (English-Spanish) ColdFusion site. To follow the issue here, it would be a good idea to look at it: http://www.timos.com/ - the section we are talking about is called 'Green Earth' - or 'Tierra Verde' for the Spanish-speaking.

      This site remembers the locale a visitor is using, so if you visit, say, in English, it will come up in English on a future visit within the next 90 days – the 'client.locale' variable. The flex app (Green Earth) gets the client.locale when it loads and uses the same locale; if you change the locale while in the Flex app, it is changed for the whole site. If you want to look into this, just go the site, enter and leave the 'Green Earth' section a couple of times and play with the language change, using the nav buttons at the top of every page.

      Here is the problem: when you are browsing the site in English and you go from any page to the Green Earth section, THE FLEX APP APPEARS, JUST FOR AN INSTANT, FIRST IN SPANISH, then it changes to English; that does NOT happen if you are browsing in Spanish. The reason is the compiler argument 'locale=es_CO,en_US', and, unless you are a magician, you can't change that locale order on the fly.

      I would like to get rid of that little glitch.

      There is also another problem with the selected item in the language change list (sometimes the wrong item is selected), but that one is not as important and should not be too hard to fix.

      I would appreciate any ideas about any of this.

      Carlos
        • 1. Re: Localized application glitch
          Gregory Lafrance Level 6
          You can switch the locales at runtime, but the example I have is a little complex, and there are some additional things to setup.

          I would check out this help topic:
          Localizing Flex Applications

          And this code might help. You will need to create a resource bundle named RunTimeLocalization.properties, saved as UTF-8, and compiled into a localized resource swf "Resources_es_CO.swf".

          The method "languageComboBox_changeHandler" is what loads the different localized resource swf at rumtime when the different locale is selected in the combo box.
          • 2. Re: Localized application glitch
            cheftimo Level 2
            Thank you very much, Greg, for your response. I have some translations to work on for the next 1 -2 days, then I'll go back to working on this project

            Although I may not use all the code you supplied, I think you are giving me enough ideas to figure this out. I'll let you know the final result.

            In the meantime, if anyone else has any ideas, I am all ears. Regards to all,

            Carlos
            • 3. Re: Localized application glitch
              cheftimo Level 2
              OK, Greg and whoever else may be watching this thread: the Flex app, when the site's language was set to English, was appearing in Spanish momentarily upon loading. I have eliminated that problem: all it took was writing 'private function clearLocaleVars()', which set a couple a variables and resourceManager.localeChain to "" right at the beginning.

              Greg, in looking at the code you were kind enough to provide, I was surprised at how similar it is to my code. But I am not using resource modules, I just compile both languages into the SWF because this thing is just not tat big, plus a lot of the resources (all the cartoon captions) come from a database. I did find one thing interesting: in your code, the var 'currLocale' is typed as Object and in mine it is a String. It's working, but if anyone wants to comment on which is better practice and why, I would like to hear. Source code is enabled at http://www.timos.com/timos/greenEarth/GreenEarth.html.

              THERE IS ONE MORE LITTLE PROBLEM I NEED HELP WITH: I am having a tough time with the language list showing the selectedItem for the starting language. It works fine once you switch languages one time, and it worked before I synchronized the locale of this app with the locale of the rest of the site, which is all ColdFusion pages.

              I might add that anyone interested in health and the environment, hot topics nowadays, would probably enjoy browsing through the collection of cartoons.

              Any ideas about dealing with the selectedItem issue would be appreciated.

              Good day,

              Carlos
              • 4. Re: Localized application glitch
                Gregory Lafrance Level 6
                For the initial locale, I put this in the wrapper HTML file:

                var currLocale = "fr_FR";

                "FlashVars", "resourceModuleURLs=Resources_" + currLocale + ".swf&localeChain=" + currLocale

                "FlashVars", "resourceModuleURLs=Resources_" + currLocale + ".swf&localeChain=" + currLocale + "",

                here is the entire wrapper file:

                <!-- saved from url=(0014)about:internet -->
                <html lang="en">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                <!-- BEGIN DeepLinking required section -->
                <link rel="stylesheet" type="text/css" href="deeplinking/deeplinking.css" />
                <!-- END DeepLinking required section -->

                <title></title>
                <script src="AC_OETags.js" language="javascript"></script>

                <!-- BEGIN DeepLinking required section -->
                <script src="deeplinking/deeplinking.js" language="javascript"></script>
                <!-- END DeepLinking required section -->

                <style>
                body { margin: 0px; overflow:hidden }
                </style>
                <script language="JavaScript" type="text/javascript">
                <!--
                // -----------------------------------------------------------------------------
                // Globals
                // Major version of Flash required
                var requiredMajorVersion = 9;
                // Minor version of Flash required
                var requiredMinorVersion = 0;
                // Minor version of Flash required
                var requiredRevision = 28;
                // -----------------------------------------------------------------------------
                // -->
                </script>
                </head>

                <body scroll="no">
                <script language="JavaScript" type="text/javascript">
                <!--
                var currLocale = "fr_FR";
                // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
                var hasProductInstall = DetectFlashVer(6, 0, 65);

                // Version check based upon the values defined in globals
                var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);


                // Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
                if ( hasProductInstall && !hasRequestedVersion ) {
                // MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
                // This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
                // DO NOT MODIFY THE FOLLOWING FOUR LINES
                // Location visited after installation is complete if installation is required
                var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
                var MMredirectURL = window.location;
                document.title = document.title.slice(0, 47) + " - Flash Player Installation";
                var MMdoctitle = document.title;

                AC_FL_RunContent(
                "src", "playerProductInstall",
                "FlashVars", "resourceModuleURLs=Resources_" + currLocale + ".swf&localeChain=" + currLocale + "&MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+" ",
                "width", "1000",
                "height", "520",
                "align", "middle",
                "id", "MoxieRuntimeLocalization1",
                "quality", "high",
                "bgcolor", "#869ca7",
                "name", "MoxieRuntimeLocalization1",
                "allowScriptAccess","sameDomain",
                "type", "application/x-shockwave-flash",
                "pluginspage", " http://www.adobe.com/go/getflashplayer"
                );
                } else if (hasRequestedVersion) {
                // if we've detected an acceptable version
                // embed the Flash Content SWF when all tests are passed
                AC_FL_RunContent(
                "src", "MoxieRuntimeLocalization1",
                "FlashVars", "resourceModuleURLs=Resources_" + currLocale + ".swf&localeChain=" + currLocale + "",
                "width", "1000",
                "height", "520",
                "align", "middle",
                "id", "MoxieRuntimeLocalization1",
                "quality", "high",
                "bgcolor", "#869ca7",
                "name", "MoxieRuntimeLocalization1",
                "allowScriptAccess","sameDomain",
                "type", "application/x-shockwave-flash",
                "pluginspage", " http://www.adobe.com/go/getflashplayer"
                );
                } else { // flash is too old or we can't detect the plugin
                var alternateContent = 'Alternate HTML content should be placed here. '
                + 'This content requires the Adobe Flash Player. '
                + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
                document.write(alternateContent); // insert non-flash content
                }
                // -->
                </script>
                <noscript>
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                id="MoxieRuntimeLocalization1" width="1000" height="520"
                codebase=" http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
                <param name="movie" value="MoxieRuntimeLocalization1.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#869ca7" />
                <param name="allowScriptAccess" value="sameDomain" />
                <embed src="MoxieRuntimeLocalization1.swf" quality="high" bgcolor="#869ca7"
                width="1000" height="520" name="MoxieRuntimeLocalization1" align="middle"
                play="true"
                loop="false"
                quality="high"
                allowScriptAccess="sameDomain"
                type="application/x-shockwave-flash"
                pluginspage=" http://www.adobe.com/go/getflashplayer">
                </embed>
                </object>
                </noscript>
                </body>
                </html>
                -----------------------------------------------------------------------

                Then within the app I have this in the <Application> tag:

                initialize="application_initializeHandler(event)"
                -----------------------------------------------------------------------
                And these relevant pieces in my mxml file:

                [Bindable]
                private var currLocale:Object = "";

                private function application_initializeHandler(event:Event):void {
                updateLanguageComboBox();

                languageComboBox.selectedItem = resourceManager.localeChain[0];

                currLocale = resourceManager.localeChain[0];
                }

                • 5. Re: Localized application glitch
                  Gregory Lafrance Level 6
                  And here is the whole mxml file:

                  • 6. Re: Localized application glitch
                    cheftimo Level 2
                    Greg Lafrance, thank you for providing all that code; it will be helpful as a reference and as a learning tool. However, none of it addresses the problem I am seeking help with, i.e. having the application open with the correct item selected in the language list.

                    I am working on a function to fix that. In the meantime, in the event anyone wants to suggest anything, there is a listener in place.

                    When I solve the issue, I'll report here.

                    Carlos
                    • 7. Re: Localized application glitch
                      Gregory Lafrance Level 6
                      Strange. The code I posted determines what will be initially selected in the ComboBox.
                      • 8. Re: Localized application glitch
                        cheftimo Level 2
                        Hi Greg, thanks for the reply again. There is really nothing strange about this. Let me quickly review how things have evolved:

                        Initially, when my application was just running on its own, there was no problem; the code was essentially the same as what you have provided, except that I use a List, not a ComboBox to select the languages.

                        But now, this app is just another "page" of the Timos site, and what I want is have it appear in whichever language a visitor has been browsing in. Try it: browse to http://www.timos.com, pick either language, then point to the link 'Green Earth' (if you are browsing in Spanish, it's 'Tierra Verde'). The Flex app will appear in the correct language, but none – or the wrong one – will be selected in the language list. It's not a major issue, and, within the app, you can switch languages as many times as you like and everything will work as expected.

                        The Flex app retrieves the ColdFusion 'client.locale' to determine which language to display. When I first implemented this, if you were browsing in Englisn, the Flex app would flicker in Spanish before showing the English. This was the primary reason for my starting this thread.

                        If you wish to take a little time to look, it’s easy: just view the source and concentrate on the first three functions after the var delarations. Naturally, anyone else wishing to join this discussion is welcome with open arms.

                        I took care of the aforementioned flicker with 'function clearLocaleChain()'. After that function is called in 'localeList_initializeHandler()' the 'svc' RemotObjec resets the locale chain in the ResultEvent 'getClientLocaleHandler()'.

                        The remaining problems is getting the selectedItem in the language list. What I think I need is for the last line of 'localeList_initializeHandler()' to wait for the previous line to finish – this would be some kind of event dispatched by 'getClientLocaleHandler()', but I am still pretty dumb about events in general.

                        Or maybe the problem lies somewhere else. I am hoping someone in this forum can at least come up with a hint.

                        Greeting to all,

                        Carlos
                        • 9. Re: Localized application glitch
                          cheftimo Level 2
                          I had visions of spending another day playing around with events, maybe even writing a custom event class. When I opened the project earlier, I decided to try one more simple change.

                          All it took was moving one line of code from one function to another. Everything is now working as I thought it should. For those who may run into a similar problem, the attached code shows exactly the change I made.

                          So, for now, I consider this issue resolved, although that doesn't mean I won't be back with more. Greg Lafrance, thank you for all your help with this issue.

                          Carlos