Search code examples
elixirphoenix-frameworkgettext

Phoenix Gettext error: ** (CaseClauseError) no case clause matching: 2


In my Phoenix project I have the following translations in my priv/gettext/pl/error.po file:

msgid "should be at least %{count} character(s)"
msgid_plural "should be at least %{count} character(s)"
msgstr[0] "Ma nieprawidłową długość (powinna wynośić co najmniej %{count})."
msgstr[1] "Ma nieprawidłową długość (powinna wynośić co najmniej %{count})."

Now I'm trying to use Gettext in console with following line:

Gettext.dngettext(TattooBackend.Web.Gettext, "errors", "should be at least %{count} character(s)", "should be at least %{count} character(s)", 6)

This returns me following error:

** (CaseClauseError) no case clause matching: 2
    (tattoo_backend) lib/tattoo_backend/web/gettext.ex:1: TattooBackend.Web.Gettext.lngettext/6
           (gettext) lib/gettext.ex:616: Gettext.dngettext/6

Solution

  • I believe that's caused by the fact that Polish has 3 plural forms, so you need three msgstr forms.

    For example: jeden stół, dwa stoły, pięć stołów.