-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2] [Translation] added support for translations depending on gender and number of variables #4884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* | ||
* @throws InvalidArgumentException | ||
* | ||
* @api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not tag is as @api
as it is not part of the stable api (it is not even part of the codebase yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, it was a wrong copy-paste :) fixed
@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. |
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. |
Closing in favor of #6009 |
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
References: #4797
Fixes the following tickets: -
License of the code: MIT
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
Where
%variable% is any kind of string (all characters except spaces and |),
[gender] is one of the following: m n f (male, female, neuter)
[plural_position] is an integer that follows the same convetions of the pluralization rules that you can find in Symfony\Component\Translation\PluralizationRules
String is any kind of string (except the | sign)
You can specify (and it's highly reccomended) a generic translation as the first position (without using any specific syntax).
This will be returned in case no other translation matches the given parameters.
Some examples follow:
%user% wrote on %friend%'s wall for his/her birthday | %friend% f: %user% wrote on %friend%'s wall for her birthday | %friend% m: %user% wrote on %friend%'s wall for his birthday
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.