开源软件名称(OpenSource Name):rekomat/AS3-LocaleManager开源软件地址(OpenSource Url):https://github.com/rekomat/AS3-LocaleManager开源编程语言(OpenSource Language):ActionScript 100.0%开源软件介绍(OpenSource Introduction):AS3-LocaleManagerThe AS3-LocaleManager provides basic localization support for ActionScript apps. It takes care of loading/parsing resource bundle files (*.txt) and returns localized resources based on the precedence of the locales set in localeChain. For some reason, mx.flex.ResourceManager does not always work as expected [1]. I ran into this issue while working on a AS3 project for AIR 3.6 (using Flash Builder 4.7). This class is a quick workaround for the problem. [1] http://forums.adobe.com/message/5182578 Resource filesThe bundle files are stored in
The content format for bundle files is
The locales are returned by precedence given in localeChain. Mix-ins are supported. This allows to work with incomplete bundles (ie. separate bundles for different regions of the same language). Usage SampleResource files
The sample uses mix-ins and placeholders. Initialize LocaleManager and set localeChainI recommend to use the handy LocaleUtil to sort supported locales based on system preferences. var locales:LocaleManager = new LocaleManager();
locales.localeChain = LocaleUtil.sortLanguagesByPreference(
["de_CH", "de_DE", en_US], Capabilities.languages, "en_US"); Adding required bundlesUse locales.addRequiredBundles([
{locale:"de_DE", bundleName:"bundleName", useLinebreak:true},
{locale:"de_CH", bundleName:"bundleName", useLinebreak:true}
], onComplete);
// optional complete responder
function onComplete(success:Boolean):void
{
if ( success ) trace("Required bundles successfully added.");
else trace("Adding required bundles failed.");
} If you work with a single resource bundle per locale and you do not need mix-ins, this will do the job: locales.addRequiredBundles([
{locale:locales.localeChain[0], bundleName:"bundleName"}
], onComplete);
// complete responder (s. above) Adding additional bundlesWith locales.addBundle("en_US", "bundleName", false, onComplete);
// optional complete responder
function onComplete(locale:String, bundleName:String, success:Boolean):void
{
if ( success ) trace("Bundle " + locale + "/" + bundleName + " added.");
else trace("Adding bundle " + locale + "/" + bundleName + " failed.");
} Use locales.addBundle(locales.localeChain[0], "anotherBundleName", false, onComplete);
// complete responder (s. above) Retrieving resources
// given localeChain ["de_CH","de_DE"]
locales.getString("bundleName", "PRICE"); // Preis
locales.getString("bundleName", "CURRENCY_SHORT"); // CHF
locales.getString("bundleName", "USRMSG_UNLOCK", ["Superman", "Superkraft"]); // Gratulation Superman, du hast jetzt Superkraft! Make it betterSuggestions, improvements, feedback and whatever is welcome! @rekomat |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论