Hi,

I continue trying to setup Jewel for use with different locales. I still
need to complete and separate locales in its own SWC, but for now my mine
concern is about how to define localeChain in an App and make all classes
using bundles know about this.

For now I get it working, but want to ask here about the solution I put in
place:

1.- in my main App.mxml file I can put this in initialize Application event:

import org.apache.royale.jewel.beads.validators.Validator;

            public function setUp():void
            {
                // you can change language here
                Validator.locale = "es_ES";
            }

So as we have more and more classes using bundles, will be added here. This
could be ok, but maybe not the final way to get over this right?

2.- Validator implementation of bundles:

in CSS add the bead:

j|Validator
    ILocalizedValuesImpl: ClassReference(
"org.apache.royale.core.SimpleLocalizedValuesImpl")

defining a resource manager so we can retrieve from CSS or override it for
other implementation:

/**
         * @private
         */
        private var _resourceManager:ILocalizedValuesImpl;
        /**
         * The Validator's resource manager to get translations from
bundles
         *
         * @langversion 3.0
         * @playerversion Flash 10.2
         * @playerversion AIR 2.6
         * @productversion Royale 0.9.6
         * @royaleignorecoercion org.apache.royale.core.ILocalizedValuesImpl
         */
        public function get resourceManager():ILocalizedValuesImpl
        {
            if (_resourceManager == null) {
                var c:Class = ValuesManager.valuesImpl.getValue(this,
"iLocalizedValuesImpl");
                if (c) {
                    _resourceManager = new c() as ILocalizedValuesImpl;
                    _resourceManager.localeChain = locale;
                    addBead(_resourceManager);
                }
            }
            return _resourceManager;
        }
        /**
         * @royaleignorecoercion org.apache.royale.core.ILocalizedValuesImpl
         */
        public function set resourceManager(value:ILocalizedValuesImpl):void
        {
            _resourceManager = value;
        }

using is for requiredFieldError:

private var _requiredFieldError:String;
        /**
         * The string to use as the errorTip.
         *
         * @langversion 3.0
         * @playerversion Flash 10.2
         * @playerversion AIR 2.6
         * @productversion Royale 0.9.4
         */
        public function get requiredFieldError():String
        {
            if(_requiredFieldError == null) {
                _requiredFieldError = resourceManager.getValue("validator",
"requiredFieldError");
            }
            return _requiredFieldError;
        }
        public function set requiredFieldError(value:String):void
        {
_requiredFieldError = value;
        }


I'm happy with this but not with this line:

_resourceManager.localeChain = locale;

as we get the resourceManager from CSS. Maybe this could be done directly
in org.apache.royale.core.SimpleLocalizedValuesImpl ?


IOW,...should we have another way to say our App to directly configure with
"en_US", or "es_ES", or any other one? so we affect all at once? something
like an Aspect that affect all at once.

I already have this with the public static var in Validator, and could put
the same in any component that needs to use a bundle, then at App startup
asign this var to all static vars, but maybe you guys, have a better way to
do this.

Thanks

-- 
Carlos Rovira
http://about.me/carlosrovira

Reply via email to