iosphere / elm-i18n

Localization for Elm apps as a pre-build phase with import and export between elm code and CSV/PO
MIT License
73 stars 6 forks source link

Missing support for plurals #1

Open felixLam opened 7 years ago

felixLam commented 7 years ago

PO supports plurals officially: https://www.gnu.org/software/gettext/manual/html_node/Translating-plural-forms.html

We would need to come up with a custom "encoding" for CSV formats.

norpan commented 7 years ago

We have the need for plural forms in a not so distant future. Only po file support is relevant for us so I'm leaving the CVS format out of my comment for now.

Let's take the example from the po documentation and translate into Elm.

module Translation.Main exposing (..)

{-
   "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
   "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
-}

nplurals =
    3

plural : Int -> Int
plural n =
    if n % 10 == 1 && n % 100 /= 11 then
        0
    else if n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) then
        1
    else
        2

{-
   #, c-format
   msgid "One file removed"
   msgid_plural "%d files removed"
   msgstr[0] "%d slika je uklonjena"
   msgstr[1] "%d datoteke uklonjenih"
   msgstr[2] "%d slika uklonjenih"
-}

nFilesRemoved : Int -> String
nFilesRemoved n =
    if plural n == 0 then
        toString n ++ " slika je uklonjena"
    else if plural n == 1 then
        toString n ++ " datoteke uklonjenih"
    else
        toString n ++ " slika uklonjenih"

So, what we need is