elm-i18n
elm-i18n copied to clipboard
Missing support for plurals
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.
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
- Parser from C expression to Elm expression for
plural
function - Parser from Elm expression to C expression for
plural
function - Handling of
if then else
and extra number parameter for translations