Search code examples
actionscript-3apache-flexlocalizationtabnavigator

Localizing component labels at run-time


I have a few different tabs in a navigator defined like this : (removed client specific domain)

<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" 
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    xmlns:container="com.*****.shop.admin.container.*"
                    width="100%" height="100%"
                    implements="com.*****.common.container.IScreen"
                    xmlns:services="com.****.shop.admin.services.*"
                    label="Service Types">

I have resource bundles for different locales, en_US looks like this :

ServicesScreen.label=Service Types

When I try to do this, it doesn't work :

...    
... 
label="{resourceManager.getString('resources','ServicesScreen.label')}"

Instead of getting my resource bundle entry, I get something weird looking in my GUI like :

Shop0.ShopSkin9._ShopSkin_Group1.contentScroller.ScrollerSkin13.contentGroup.vsMain.AdminView154.SkinnableContainerSkin159.contentGroup.subNavItems.opCodeScreen

My resource bundles work in other cases, for instance labels next to form input fields, etc... The code compiles, however, and no errors are actually thrown (compile or run-time). I tried assigning the value to a variable and using that variable in the label field, however that caused a compile error.

I tried calling a setter method on creation complete of the component, but that didn't resolve the issue either.

How do I localize my tab labels, and can I do so dynamically at run-time?

Thanks for your time!


Solution

  • I guess I'll self-answer this one, although credit goes to Sunil D. I don't know why it didn't work earlier while I was testing, I must've missed something the first time, but here goes. first I added:

    creationComplete="init(event)">
    

    And then in that method body I did :

        protected function init(event:FlexEvent):void
        {
            this.label = resourceManager.getString('resources','opCodeScreen.title');
        }
    

    And it works like a charm. honestly I'm pretty sure I did this exact same test this morning, but I guess not. Sunil If you want to make your comment an answer I'll go ahead and accept it.

    EDIT: change the text at run-time, add currentStateChange that calls aforementionned method

    Cheers!