-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.7][Form][choice] added choice_translation_domain to avoid trans options. #13651
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
43ce6b9
to
a5fb3ec
Compare
@@ -79,7 +79,7 @@ | |||
{{- block('choice_widget_options') -}} | |||
</optgroup> | |||
{%- else -%} | |||
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option> | |||
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ trans_options is sameas(false) ? choice.label:choice.label|trans({}, translation_domain) }}</option> |
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.
missing space around :
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.
a5fb3ec
to
b0b0792
Compare
I think this change makes sense because database entries are unlikely to be translated. And if they you would translate them, then not with the translator component but instead also read them from the database when fetching. |
+1 |
👍 @Tobion, my thoughts exactly |
@@ -231,6 +232,7 @@ public function configureOptions(OptionsResolver $resolver) | |||
// is manually set to an object. | |||
// See https://github.com/symfony/symfony/pull/5582 | |||
'data_class' => null, | |||
'trans_options' => true, |
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 should be named translate_choices
- we don't abbreviate option names AFAIK, e.g. preferred
choices
is also the term in the related option
As the default for the Doctrine type changed to not translating, it's a bc break. As such it should be documented in the upgrade file. |
b0b0792
to
06082b2
Compare
+1 |
06082b2
to
3eff033
Compare
@Tobion changes has been made. |
FYI the CountryType, CurrencyType, LanguageType and LocaleType use Intl component so I changed to not use trans. |
@@ -4,6 +4,7 @@ CHANGELOG | |||
2.7.0 | |||
----- | |||
|
|||
* added options "translate_choices" to ChoiceType. |
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.
option singular
df5fcf2
to
4b42447
Compare
I think the TimezoneType should disable translation as well. You don't want to manually translate all the timezone identifiers. Actually it probably should translate internally with http://php.net/manual/en/intltimezone.getdisplayname.php but that's a different story. Created: #13662 |
64d38f1
to
7904f74
Compare
Actually, I just found #7611 and #12148 (comment) |
7904f74
to
0a90cf8
Compare
Is this one ready to be merged? |
In theory it would be ready because it works and implementation is ok. But I think the idea expressed in #12148 (comment) is the better solution. But this would require @webmozart or someone else to finish #12148. |
@Tobion What's about renaming this option to choice_translation_domain (bool) ? so this won't involve a BC when adding (closure) feature ? |
ping @symfony/deciders |
|
||
if ($view->parent) { | ||
if (null === $choiceTranslationDomain) { | ||
$choiceTranslationDomain = $view->parent->vars['translation_domain']; |
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.
it should use the translation domain of the current form when set to null, not of the parent one (the parent value is read for the translation_domain
inheritance
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.
that is already done in the lazy option. but if both translation_domain and choice_translation_domain is null, it must read it from the parent. otherwise it would be a bc break.
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.
No, it is not done if the user is passing null
in the option
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.
if you pass null
, you need to read it from translation_domain
(and do it after it has itself be inherited eventually)
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.
agreed
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.
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'm not saying it should be removed entirely. I'm sayign the current implementation is buggy.
Try to set the choice_translation_domain
explicitly with a non-inherited translation domain.
you should not inherit the choice_translation_domain from the parent translation_domain. you should inherit it from the current translation domain (be it inherited or no)
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 see, the problem is when passing null explicitly.
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.
fixed
a514d4f
to
6c8f624
Compare
Doc issue: symfony/symfony-docs#5134 |
6c8f624
to
0a4f1be
Compare
ping @fabpot |
Is it intended that the Twig template uses the label while the PHP templates uses the index in the |
if (null === $choiceTranslationDomain) { | ||
$choiceTranslationDomain = $view->vars['translation_domain']; | ||
} | ||
} |
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 can use one if
here:
if ($view->parent && null === $choiceTranslationDomain) {
// ...
}
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.
fixed
And should we also document in the upgrade file that you need to update your custom form themes too? |
8086358
to
ddfa468
Compare
ddfa468
to
5a33c2c
Compare
|
👍 |
… avoid trans options. (aitboudad) This PR was merged into the 2.7 branch. Discussion ---------- [2.7][Form][choice] added choice_translation_domain to avoid trans options. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Fixed tickets | ~ | Tests pass? | yes | License | MIT see #12941 (comment) Commits ------- 5a33c2c [Form][choice] added choice_translation_domain to avoid trans options.
I merged this PR as I think it's part of translation. |
lol I guess I could have merged it as well then because it uses the Options Resolver. ;) |
I really appreciate your help on this PR :) |
@@ -74,13 +74,13 @@ | |||
{%- block choice_widget_options -%} | |||
{% for group_label, choice in options %} | |||
{%- if choice is iterable -%} | |||
<optgroup label="{{ group_label|trans({}, translation_domain) }}"> | |||
<optgroup label="{{ choice_translation_domain is sameas(false) ? group_label : group_label|trans({}, choice_translation_domain) }}"> |
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.
just for the record .. this change breaks things for users of earlier Form component versions. maybe we should therefore adjust the composer dependency when we do such changes in the future
see #12941 (comment)