8000 [2.7][Form][choice] added choice_translation_domain to avoid trans options. by aitboudad · Pull Request #13651 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Merged
merged 1 commit into from
Apr 4, 2015

Conversation

aitboudad
Copy link
Contributor
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets ~
Tests pass? yes
License MIT

see #12941 (comment)

@aitboudad
Copy link
Contributor Author

@@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space around :

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion
Copy link
Contributor
Tobion commented Feb 10, 2015

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.

@tadcka
Copy link
Contributor
tadcka commented Feb 11, 2015

+1

@egils
Copy link
egils commented Feb 11, 2015

👍 @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,
Copy link
Contributor

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

  1. we don't abbreviate option names AFAIK, e.g. preferred
  2. choices is also the term in the related option

@Tobion
Copy link
Contributor
Tobion commented Feb 11, 2015

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.

@raziel057
Copy link
Contributor

+1

@aitboudad
Copy link
Contributor Author

@Tobion changes has been made.

@aitboudad
Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option singular

@Tobion
Copy link
Contributor
Tobion commented Feb 11, 2015

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

@aitboudad aitboudad force-pushed the form_entity_trans branch 5 times, most recently from 64d38f1 to 7904f74 Compare February 14, 2015 07:32
@Tobion
Copy link
Contributor
Tobion commented Feb 16, 2015

Actually, I just found #7611 and #12148 (comment)
So I think it makes more sense to implement this as part of choice_translation_domain (bool|closure) which when false or the closure returns false, then does not translate the given choice.

@fabpot fabpot added the Form label Feb 25, 2015
@fabpot
Copy link
Member
fabpot commented Mar 24, 2015

Is this one ready to be merged?

@Tobion
Copy link
Contributor
Tobion commented Mar 24, 2015

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.
So if we would merge this PR here, there is a high chance that we would deprecate the new option again as soon as #12148 is finished. And thus involve maiting BC and documentation confusion. So I'd prefer to wait for #12148 and then rebase this one.

@aitboudad
Copy link
Contributor Author

@Tobion What's about renaming this option to choice_translation_domain (bool) ? so this won't involve a BC when adding (closure) feature ?

@aitboudad aitboudad changed the title [Form][choice] avoid trans options for entity type. [2.7][Form][choice] added choice_translation_domain to avoid trans options. Apr 1, 2015
@aitboudad
Copy link
Contributor Author

ping @symfony/deciders


if ($view->parent) {
if (null === $choiceTranslationDomain) {
$choiceTranslationDomain = $view->parent->vars['translation_domain'];
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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)

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@aitboudad
Copy link
Contributor Author

Doc issue: symfony/symfony-docs#5134

@aitboudad aitboudad force-pushed the form_entity_trans branch from 6c8f624 to 0a4f1be Compare April 3, 2015 18:48
@aitboudad
Copy link
Contributor Author

ping @fabpot

@xabbuh
Copy link
Member
xabbuh commented Apr 3, 2015

Is it intended that the Twig template uses the label while the PHP templates uses the index in the optgroup element (it has been this way before, but it looks odd to me)?

if (null === $choiceTranslationDomain) {
$choiceTranslationDomain = $view->vars['translation_domain'];
}
}
Copy link
Member

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) {
    // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@xabbuh
Copy link
Member
xabbuh commented Apr 3, 2015

And should we also document in the upgrade file that you need to update your custom form themes too?

@aitboudad aitboudad force-pushed the form_entity_trans branch 2 times, most recently from 8086358 to ddfa468 Compare April 3, 2015 22:12
@aitboudad aitboudad force-pushed the form_entity_trans branch from ddfa468 to 5a33c2c Compare April 3, 2015 22:14
@aitboudad
Copy link
Contributor Author

@xabbuh

  • upgrade done
  • for optgroup I renamed $index --> $group_label

@fabpot
Copy link
Member
fabpot commented Apr 4, 2015

👍

@aitboudad aitboudad merged commit 5a33c2c into symfony:2.7 Apr 4, 2015
aitboudad added a commit that referenced this pull request Apr 4, 2015
… 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.
@aitboudad
Copy link
Contributor Author

I merged this PR as I think it's part of translation.

@Tobion
Copy link
Contributor
Tobion commented Apr 4, 2015

lol I guess I could have merged it as well then because it uses the Options Resolver. ;)

@aitboudad
Copy link
Contributor Author

I really appreciate your help on this PR :)
Thank you @Tobion

@@ -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) }}">
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants
0