International Pluralization Lib for Objective-C?

前端 未结 2 1435
野趣味
野趣味 2021-02-05 14:04

I am internationalizing my app and am looking for a solution to how to deal with plural forms. I ran across Mozilla\'s PluralForm project, which essentially abstracts away the i

2条回答
  •  爱一瞬间的悲伤
    2021-02-05 14:37

    From looking at Mozilla's implementation of PluralForm.jsm it should be quite easy to implement your own version of the PluralForm.get in Objective-C.

    First you retrieve the plural rule number from your localization and use it to select appropriate getter, that implements the rule. There are 16(1) expressions that return the index of proper plural form to use for given numeral. Luckily they appear to be written in JavaScript subset that is also valid C code... Boolean and ternary expressions with some modulo operations mixed in.

    Plural forms are supplied by your translators as semicolon separated list in the localized string for the given word. The order of the forms is described in the list of plural rules. You split them by the semicolon and using the index from the getter select the matching form.

    Technically, no problem. The only issue is that I don't know how to properly derive your code and respect the MPL license.

    (1) Implementation contains 17th rule for Breton, but its forms are not documented yet, so...

提交回复
热议问题