{"id":13744885,"url":"https://github.com/rekomat/AS3-LocaleManager","last_synced_at":"2025-05-09T04:31:11.425Z","repository":{"id":7848488,"uuid":"9220325","full_name":"rekomat/AS3-LocaleManager","owner":"rekomat","description":"Basic localization support for ActionScript apps","archived":false,"fork":false,"pushed_at":"2014-08-18T15:42:05.000Z","size":181,"stargazers_count":27,"open_issues_count":0,"forks_count":12,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-04T05:05:19.113Z","etag":null,"topics":["actionscript","adobe-air","i18n","localization","starling-framework"],"latest_commit_sha":null,"homepage":null,"language":"ActionScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rekomat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-04T14:42:25.000Z","updated_at":"2023-02-07T12:57:19.000Z","dependencies_parsed_at":"2022-09-24T05:01:32.639Z","dependency_job_id":null,"html_url":"https://github.com/rekomat/AS3-LocaleManager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekomat%2FAS3-LocaleManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekomat%2FAS3-LocaleManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekomat%2FAS3-LocaleManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekomat%2FAS3-LocaleManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rekomat","download_url":"https://codeload.github.com/rekomat/AS3-LocaleManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224811299,"owners_count":17373939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actionscript","adobe-air","i18n","localization","starling-framework"],"created_at":"2024-08-03T05:01:17.829Z","updated_at":"2024-11-15T16:32:09.611Z","avatar_url":"https://github.com/rekomat.png","language":"ActionScript","readme":"# AS3-LocaleManager \n\nThe 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.\n\nFor 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. \n\n[1] http://forums.adobe.com/message/5182578\n\n## Resource files\n\nThe bundle files are stored in `app://locale/[locale]/[bundleName].txt`  (ie.: `app://locale/en_US/localizedStrings.txt`). Make sure the directory \"locale\" is copied to your build package:\n\n* Put the directory locale in your src directory.\n* Or add the directory containing 'locale' to your Source Path (Flash Builder: Project \u003e Properties \u003e ActionScript Build Path \u003e Source Path).\n\nThe content format for bundle files is `KEY = Value` followed by a line break. __You can use the \"=\" character within the value, but not for keys or comments.__\n\n    # Any line without the \"equals\" character is a comment. \n    A leading # does not harm.\n    LABEL_FIRSTNAME = Firstname\n    LABEL_LASTNAME  = Lastname\n\nThe 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). \n\n## Usage Sample\n\n### Resource files\n\n    // File: de_DE/bundleName.txt\n    // Complete resource file\n    CURRENCY_SHORT = EUR\n    PRICE          = Preis\n    USRMSG_UNLOCK  = Gratulation {0}, du hast jetzt {1}!\n\n    // File: de_CH/bundleName.txt\n    // Incomplete resource file (used as mix-in)\n    CURRENCY_SHORT = CHF\n    \nThe sample uses mix-ins and placeholders.\n\n### Initialize LocaleManager and set localeChain \nI recommend to use the handy [LocaleUtil](https://code.google.com/p/as3localelib/) to sort supported locales based on system preferences. \n\n```as3\nvar locales:LocaleManager = new LocaleManager();\nlocales.localeChain = LocaleUtil.sortLanguagesByPreference(\n    [\"de_CH\", \"de_DE\", en_US], Capabilities.languages, \"en_US\");\n```\n\n### Adding required bundles\n\nUse `addRequiredBundles` to add all required bundles. This is typically used on startup. The bundle files are loaded/parsed at runtime. Adding only the required bundles saves time. You can safely omit `useLinebreak:true` if you do not use line breaks (`\\n`) in your resource file (cmp. next example). \n\n\n```as3\nlocales.addRequiredBundles([\n    {locale:\"de_DE\", bundleName:\"bundleName\", useLinebreak:true},\n    {locale:\"de_CH\", bundleName:\"bundleName\", useLinebreak:true}\n], onComplete);\n\n// optional complete responder\nfunction onComplete(success:Boolean):void\n{\n    if ( success ) trace(\"Required bundles successfully added.\");\n    else trace(\"Adding required bundles failed.\");\n}\n```\n\nIf you work with a single resource bundle per locale and you do not need mix-ins, this will do the job: \n```as3\nlocales.addRequiredBundles([\n    {locale:locales.localeChain[0], bundleName:\"bundleName\"}\n], onComplete);\n\n// complete responder (s. above)\n```\n\n### Adding additional bundles\n\nWith `addBundle` you can add bundles later. If you have an app with many scenes/levels and many resources in your bundles it might be better to split the resources into several bundles and just load the ones really needed (ie. when switching levels). \n\n```as3\nlocales.addBundle(\"en_US\", \"bundleName\", false, onComplete);\n\n// optional complete responder\nfunction onComplete(locale:String, bundleName:String, success:Boolean):void\n{\n    if ( success ) trace(\"Bundle \" + locale + \"/\" + bundleName + \" added.\");\n    else trace(\"Adding bundle \" + locale + \"/\" + bundleName + \" failed.\");\n}\n```\nUse `locales.localeChain[0]` as parameter if you just need to add a single bundle for the primary locale.\n```as3\nlocales.addBundle(locales.localeChain[0], \"anotherBundleName\", false, onComplete);\n\n// complete responder (s. above)\n```\n\n### Retrieving resources \n\n`getString` returns a given resource of a given bundle. Localized of course. The third sample shows how to use placeholders and parameters. \n\n```as3\n// given localeChain [\"de_CH\",\"de_DE\"]\nlocales.getString(\"bundleName\", \"PRICE\"); // Preis\nlocales.getString(\"bundleName\", \"CURRENCY_SHORT\"); // CHF\nlocales.getString(\"bundleName\", \"USRMSG_UNLOCK\", [\"Superman\", \"Superkraft\"]); // Gratulation Superman, du hast jetzt Superkraft!\n```\n\n## Make it better\nSuggestions, improvements, feedback and whatever is welcome! \n[@rekomat](https://twitter.com/rekomat)\n","funding_links":[],"categories":["Unsorted"],"sub_categories":["Other API"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frekomat%2FAS3-LocaleManager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frekomat%2FAS3-LocaleManager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frekomat%2FAS3-LocaleManager/lists"}