-
Notifications
You must be signed in to change notification settings - Fork 7
Question and Answers
1) How do I use external, compiled resource bundles with BabelFx?
When I embed my localized resource bundles into the application, my application startup time is too long. How can I use external resources bundles?
Answer:
Localized resources bundles can be huge; especially when you embed fonts and images. Embedding the bundles means your application footprint is huge and thus the startup time is excessive. In such cases, developers should consider using external resource bundles (compiled into .swf files). And if you are embedding fonts, you should also consider specifying Unicode font-ranges in your css. [Non-roman languages such as Chinese, Japanese, etc. display words using glyphs; glyph sets can be 5-20 Mbytes in size…]
The BabelFx has a new feature that makes using external bundles trivial: ExternalLocaleCommand!
The BabelFx Sample FlexStore Revisited uses a new BabelFx class called ExternalLocaleCommand. This class is used by the LocaleMap in a Command Factory pattern [see lines 74-80]. The LocalizationMap (auto-instantiates an instance of that factory class and uses it to auto-load the resource bundles asynchronously from externally compiled resource bundles. Best of all, Line 77 shows how developers can provide custom path options to the ExternalLocaleCommand processing.
2) Can BabelFx be used without ResourceBundles?
Can the LocalizationMap and the IoC principles described here be used WITHOUT ResourceBundles? My localized strings (only strings) come from a database backend (not a bundle), but I’d still like to use the injection mechanism.
Answer:
If you want to load your localized strings from a remote text file of a database backend – instead of using embedded or external, compiled bundles – simply create a new LocaleCommand subclass and use that as the generator instead of ExternalLocaleCommand.
For example, DatabaseLocaleCommand [which should extend LocaleCommand] could make either a HTTPService or RemoteObject async call to load the remote information from your database. Once the RPC call responds, build an in-memory resource bundle and then update the ResourceManager with the new locale chain. This last action of changing the locale chaing will then auto-trigger the LocalizationMap to run and inject your latest localized strings.
3) How do I enable logging with the BabelFx engine?
Review the source code, I see that logging features are now available within the BabelFx engine. But how do I turn it on and use it?
Answer:
To active logging to the console you simply create a TraceTarget instance in your custom LocalizationMap. e.g.
<LocaleMap logTarget=“{ new TraceTarget() }” xmlns=“http://com.asfusion.mate/l10n” >
…
</LocaleMap >
Note: if you do not custom the settings of the TraceTarget instance then LogEventLevent.DEBUG, includeTime=true, includeLevel=true, and includeCategory=true are used. To override the defaults, you can do something like below:
<LocaleMap logTarget=“{ loggingTarget }” xmlns=“http://com.asfusion.mate/l10n” >
<mx:Script>
<![CDATA[
[Bindable(“loggingTargetChanged”)]
private function get loggingTarget ():TraceTarget {
var tracer : TraceTarget = new TraceTarget();
tracer.level = LogEventLevel.ERROR;
return tracer;
}
]]>
</mx:Script>
…
</LocaleMap >
or use this condensed solution:
<LocaleMap logTarget=“{ new StaticClassFactory(TraceTarget, {level:LogEventLevel.WARN} ) }”
xmlns=“http://com.asfusion.mate/l10n” >
…
</LocaleMap >