Reputation: 26878
I want to support plural forms in translations of my Flex program properly like is possible with Qt, GWT and gettext.
Is there a (open source) library that handles this for Flex?
Upvotes: 2
Views: 257
Reputation: 191
You don't need any additional libraries. Use standard Flex ResourceManager. In text resources define plural forms like that:
minute=minute, minutes
In this case, when you later ask for a such resource as
resourceManager.getStringArray('BundleName', 'minute')
you get the array of plural values like
[ 'minute', 'minutes' ]
Then use smth like
function getPlural(value:Number, plurals:Array):String
{
if (ResourceManager.getInstance().localeChain[0] == 'en_US')
if (value == 1) return plurals[0] else return plurals[1];
}
to select the right text for current locale. You can define this function directly in some package to be common for all classes. Unfortunately, you can not avoid such function because the plural rules of many languages are differ. For Russian, for example, the expression will be much more complicated and will take three plural word forms.
By the way, this method is very similar to how gettext works.
Upvotes: 4