Closed woylie closed 1 year ago
@woylie thanks for the report! Doesn't look like you're doing anything wrong, no. ja
already has plural=0
in the built-in Gettext locales, so this should work.
@maennchen do you have time to take a look at this? My cycles are busy for a few days 🙃
@whatyouhide I should have some time to have a look on monday 👍
@maennchen fantastic, thank you! 💟
@woylie I'm unable to reproduce that myself.
Are you sure that:
gettext
dependency is up-to-dateja
files have the header with nplurals=1
or no header at allGettext.Plural
implementationIf all are good, it would be very helpful if you could either:
dbg {locale, nplurals, message, file}
dbg {
locale,
plural_mod,
nplurals,
Messages.get_header(messages_struct, "Language"),
Messages.get_header(messages_struct, "Plural-Forms")
}
I just set up a pristine Phoenix 1.7-rc.2 application with Gettext 0.22.0.
I noticed two other issues.
mix gettext.merge priv/gettext --locale ja
and mix gettext.extract --merge
will create new .po
files without the plural=<rule>
, causing a warning..pot
files without messages
causes a FunctionClauseError (I noticed because I generated the Phoenix app
with the --no-ecto
flag, which produces an errors.pot
without messages).** (FunctionClauseError) no function clause matching in Expo.PO.Composer.dump_kw_and_strings/3
The following arguments were given to Expo.PO.Composer.dump_kw_and_strings/3:
# 1
"msgstr"
# 2
[]
# 3
[]
Attempted function clauses (showing 1 out of 1):
defp dump_kw_and_strings(keyword, [first | rest], line_prefix)
(expo 0.3.0) lib/expo/po/composer.ex:88: Expo.PO.Composer.dump_kw_and_strings/3
(expo 0.3.0) lib/expo/po/composer.ex:36: Expo.PO.Composer.dump_message/1
(elixir 1.14.2) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
(expo 0.3.0) lib/expo/po/composer.ex:21: Expo.PO.Composer.dump_messages/1
(gettext 0.22.0) lib/gettext/extractor.ex:240: Gettext.Extractor.merge_or_unchanged/3
(gettext 0.22.0) lib/gettext/extractor.ex:267: Gettext.Extractor.tag_files/2
(elixir 1.14.2) lib/enum.ex:1662: anonymous fn/3 in Enum.map/2
(stdlib 4.1.1) maps.erl:411: :maps.fold_1/3
I fixed both by updating the plural form headers as suggested and by deleting
errors.pot
.
What remains is the Gettext.PluralFormError
, which you can see by starting the
server and opening http://localhost:4000
. The error disappears after
downgrading Gettext to 0.21.0. Here's the demo.
@woylie Oh, that also shouldn’t happen. Thanks for the demo ❤️
FYI: I had a few things standing in the way of adressing this issue in the last few days. I'll have a look until the end of the week.
I identified the issue, one character missing :laughing:
diff --git a/lib/gettext/compiler.ex b/lib/gettext/compiler.ex
index d68e901..c0b1107 100644
--- a/lib/gettext/compiler.ex
+++ b/lib/gettext/compiler.ex
@@ -504,7 +504,7 @@ defmodule Gettext.Compiler do
%{locale: locale, domain: domain, path: path} = po_file
%Messages{messages: messages, file: file} = messages_struct = PO.parse_file!(path)
- plural_forms_fun = :"{locale}_#{domain}_plural"
+ plural_forms_fun = :"#{locale}_#{domain}_plural"
plural_forms = compile_plural_forms(locale, messages_struct, plural_mod, plural_forms_fun)
nplurals = nplurals(locale, messages_struct, plural_mod)
I'll write a test and open a PR.
I'm a bit confused about plural forms. According to the GNU Gettext documentation, the appropriate header for languages that don't distinguish between singular and plural is
Plural-Forms: nplurals=1; plural=0;
. So I added this to mypriv/gettext/ja/LC_MESSAGES/default.po
file:Now when I run
mix gettext.extract --merge
, it adds this to the.po
file for strings passed tongettext/3
:After I add a translation:
I'm getting this error:
Am I doing something wrong?
gettext 0.22.0