-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Add parameters to DataCollectorTranslator #15139
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
[Translation] Add parameters to DataCollectorTranslator #15139
Conversation
👌 |
👍 looks good, but for |
@@ -59,7 +59,7 @@ public function trans($id, array $parameters = array(), $domain = null, $locale | |||
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) | |||
{ | |||
$trans = $this->translator->transChoice($id, $number, $parameters, $domain, $locale); | |||
$this->collectMessage($locale, $domain, $id, $trans); | |||
$this->collectMessage($locale, $domain, $id, $trans, $parameters); |
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.
we need to pass the $number
too.
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.
Ok, didn't done it because the Twig extension copy the number to the parameters already (see here),
but when using the translator directly, this is going to be an issue. I will update my commit soon.
PR updated with the addition of It look like I must close this PR and re-open on 2.8? |
@damienalexandre we can rebase it on top of 2.8 at merging time with our merging tool (assuming there is no conflict), so it is not necessary. This would mark the PR as closed rather than merged though because of the rebase |
<code>{{ key }} = {{ value }}</code><br /> | ||
{% endfor %} | ||
{% if message.transChoiceNumber is not null %} | ||
<em><code>transChoice count = {{ message.transChoiceNumber }}</code></em> |
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.
I would rather say pluralization
than transchoice Count
How does it behave when the same key is translated several times but with different parameter values (and potentially even different parameters) and a different pluralization count ? |
This code: <p>{{ 'demo.homepage.introduction'|trans({'%username%': 'Damien'}) }}</p>
<p>{{ 'demo.homepage.introduction'|trans({'%username%': 'Toto'}) }}</p> produce this output: Only the first call is kept (see
What do you think? |
@damienalexandre I'm actually wondering whether the value of the parameter should really be kept here (same for the pluralization count). What we really care about IMO is which parameters are available, and whether it is pluralized or no. |
keeping all parameters values would also look confusing IMO |
Having the parameters values proved to be really helpful on the project I'm working on. So I'm in favor of @aitboudad idea, specially because the folding table allow to display lots of information's without breaking the display to much. Here is what I've just pushed. For this code: <p>{{ 'demo.homepage.hello'|trans }}</p>
<p>{{ 'demo.homepage.user_friends'|transchoice(5, {'%name%': 'Fabien'}) }}</p>
<p>{{ 'demo.homepage.user_friends'|transchoice(0, {'%name%': 'Fabien'}) }}</p>
<p>{{ 'demo.homepage.time'|trans({'%datetime%': 'now'|date}) }}</p>
<p>{{ 'demo.homepage.introduction'|trans({'%username%': 'Damien'}) }}</p>
<p>{{ 'demo.homepage.introduction'|trans({'%username%': 'Toto', '%foo%': 'bar'}) }}</p> It produce this in the translation panel: Expended it looks like this: As you can see I use the Let my know what you think, |
@damienalexandre Using |
{% if message.transChoiceNumber is not null %}<br><small style="color: gray;">(use pluralization)</small>{% endif %} | ||
|
||
<div> | ||
[<a href="#" onclick="return openParameters(this);" style="text-decoration: none;" |
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.
I think it's better to hide this link when parameters is empty
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.
message.parameters
is never empty, and reflect all the calls to the given translation key. So it's perfectly possible to have:
- one first call with params:
{"%foo%": "bar"}
- one second call without:
null
- one third with other params:
{"%bar%": "foo"}
If it's called 5 times without parameters, it will display 5 times null
.
using |
ping @symfony/deciders |
👍 |
Should we really include the parameters part if there were no parameters passed to |
I agree with @xabbuh: displaying |
Ok, I mentioned before why I made it this way, |
Maybe it's sufficient to just show a message telling "no parameters" or something similar. |
Here we go; I've change the way I store the parameters in the DataCollector to allow a better display. Here is an example where the first call does not have parameters, so we do not display the expend link, and where the last translation is called 3 times but only have parameters 2 times: Looks better 👍 Good feedback 😉 |
Thank you @damienalexandre. |
The new translation web profiler panel miss a important piece of information: the parameters that can be used for placeholders.
This PR add parameters in the collected translations and display them in the WebProfiler translation list.
Original idea by my team-mate @joelwurtz 🤘