Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
[2.2] [Translation] added support for translations depending on gender and number of variables #4884
Bug fix: no
This improvement adds to the translator component the possibility to pass variables specifying the gender and the number. This enables the translators to handle all the specificities of their own language. With an easy to understand but strict syntax, I've managed not to break the BC, while adding a very small footprint in the trans method (due to a single validation regexp which is anyways improvable).
This the syntax ref of a translated message:
%variable% [gender][plural_position]: String
You can specify (and it's highly reccomended) a generic translation as the first position (without using any specific syntax).
Some examples follow:
You are a very good boy! | %user% m1: You are very good boys! | %user% f0: You are a very good girl! | %user% 1f: You are very good girls!
I'd like to hear some feedbacks about this implementation so I can adjust what you think is wrong and then write the documentation.
@fabpot what do you think about this feature? I'm already using it heavely in my current installation and I personally think it's a far better approach compared to the transchoice method because that method has to be invoked by the programmer and not by the translator, as this one.
referenced this pull request
Sep 19, 2012
After some discussion with @sroddy, we throught it would be better if we strictly follow the pluralization rules defined by unicode.org: http://unicode.org/repos/cldr-tmp/trunk/charts/supplemental/language_plural_rules.html
That way, we could do something like:
$translation = implode("|", array( "aboutMyMatch[male][one]: About him", "aboutMyMatch[male][other]: About them", "aboutMyMatch[female][one]: About her", ));
We also consider defining only one or none of the elements, like only defining gender, but not pluralization, or defining only the pluralization (which would consider the gender as
As an ability to make it flexible, developers would be able to define anything except the plural rules names and the
@fabpot @stof we would love to hear some feedbacks before starting to implement these changes. If we are totally out of scope, it's better not to start either. The idea is to change this PR according to the unicode plural rules and the a-bit more-verbose-but-much-clearer 'var[gender][pluralization]:' syntax. I'd love to hear a feedback from @schmittjoh too, because his really useful JMSTranslationBundle will be even more useful to help translators with this kind of syntax.