开发者

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 handl开发者_开发知识库es this for Flex?


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.


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

  • AsGettext is licensed as LGPL so it should be ok for any project.

  • as3-gettext

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜