Extend internationalization code to support different argument order and plurarization
NOTE: In the examples I'm supposing we still have the issue with the percent %
character that might or not already have been fixed on #179 (closed).
Currently we can translate strings using a format like this:
"The IP address %v is listed by %v RBLs"
Where the second %v
is replaced by a number. In case the number is more than one
, "RBLs" in the plural form is correct, but otherwise, when the value is one
, "RBL" should be used in the singular form.
Supporting it will consist on three separated steps:
- how to represent it in the
go
andhtml
code. - how to represent it in the
.po
files. Gettext has support for represent them, as in:
msgid "One file removed"
msgid_plural "%d files removed"
msgstr[0] ""
msgstr[1] ""
- How to load and show such translations, selecting the proper form. Luckily the library we use (go-text) is very powerful and will be helpful supporting such use cases.
It's important to notice that some languages have different forms depending on the words gender, number and case. We should analyze and decide how to deal with them.
Another issue we face is on supporting languages where the order of the arguments (elements with %
) is different from English.
For instance, in the expression "The IP address %v is listed by %v RBLs"
and arguments 127.0.0.1
and 2
will yield "The IP address 127.0.0.2 is listed by 2 RBLs"
in English, but some languages might require something roughly translated as "2 RBLs have blocked the IP address 127.0.0.2"
, where the order of the placeholders is different of the ones stated in the code.
This is an old issue on software i18n and both gettext
and go-text
have support for it, but we need to implement the "glue" between those two libraries.
The page https://fedoraproject.org/wiki/L10N_Tips_for_translators has some help on how to approach the issue.