Wim Deblauwe
Wim Deblauwe

Reputation: 26878

Plural forms in translations of Flex programs

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

Answers (2)

koldoon
koldoon

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

sorin
sorin

Reputation: 170846

It is good idea to use gettext format. You have two options:

Upvotes: 0

Related Questions