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

[Form] Labels' translation with pluralization #10108

Closed
kniziol opened this Issue Jan 22, 2014 · 9 comments

Comments

Projects
None yet
6 participants
@kniziol

kniziol commented Jan 22, 2014

Cannot translate properly labels which translation strings are available in "singular | plural" form.
Take a look at this example.

Translations
simple:
    translation:
        image: '{1} Image | [2,Inf] Images'
Form's Type class
public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder->add('image', null, array(
        'label' => 'simple.translation.image',
        'translation_domain' => 'messages'
    ));
}

There is no possibility to say into add() method to translate given translation key in plural form. In the example above I expect the "Images" label, but it's impossible. Reason of this situation is that texts of labels, buttons etc. are always translated with trans instead of transchoice filter:

# vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
<label (...)>{{ label|trans({}, translation_domain) }}</label>

Could you, please, add support for the plural translation?

@stof

This comment has been minimized.

Show comment
Hide comment
@stof

stof Jan 22, 2014

Member

what would you use to decide whether it is a singular or plural ? you need to have some number involved in this choice

Member

stof commented Jan 22, 2014

what would you use to decide whether it is a singular or plural ? you need to have some number involved in this choice

@kniziol

This comment has been minimized.

Show comment
Hide comment
@kniziol

kniziol Jan 22, 2014

Yes, I know and that's the main problem, I think. Maybe should be a special / additional option for a label? Maybe this option should be defined when form is created, e.g. in the $myOptions array: $this->createForm(new MyType(), $entity, $myOptions)?

kniziol commented Jan 22, 2014

Yes, I know and that's the main problem, I think. Maybe should be a special / additional option for a label? Maybe this option should be defined when form is created, e.g. in the $myOptions array: $this->createForm(new MyType(), $entity, $myOptions)?

@lavoiesl

This comment has been minimized.

Show comment
Hide comment
@lavoiesl

lavoiesl Jan 24, 2014

Contributor

It seems to me that an option like label_transchoice => \d+ would do the trick.

The default value could be provided by the field type. For example, the choice type would return $multiple ? 2 : 1

Contributor

lavoiesl commented Jan 24, 2014

It seems to me that an option like label_transchoice => \d+ would do the trick.

The default value could be provided by the field type. For example, the choice type would return $multiple ? 2 : 1

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Jan 24, 2014

@lavoiesl

This comment has been minimized.

Show comment
Hide comment
@lavoiesl

lavoiesl Jan 24, 2014

Contributor

Seemed simple enough, so I tried my hand at it and I decided to go with translation_choice for similarity with translation_domain.

Let me know what you think.

Contributor

lavoiesl commented Jan 24, 2014

Seemed simple enough, so I tried my hand at it and I decided to go with translation_choice for similarity with translation_domain.

Let me know what you think.

@kniziol

This comment has been minimized.

Show comment
Hide comment
@kniziol

kniziol Jan 24, 2014

Looks good, for me. Specially with the default value determined by field type.

kniziol commented Jan 24, 2014

Looks good, for me. Specially with the default value determined by field type.

@lavoiesl lavoiesl referenced this issue Jan 24, 2014

Closed

[Form] Added pluralization support for labels #10125

2 of 2 tasks complete

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Jan 26, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 25, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 25, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 26, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 26, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 27, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 27, 2014

[Form] Tests for #10108, label pluralization
This commit introduce a rewritten of multiple tests concerning form
labels. The StubTranslator now outputs [trans number=N] instead of
[trans] when transchoice is used. This is necessary to recognize the use
of transchoice. Unfortunately, it changes the output of all tests, so
they must be adapted even if they are not concerned.

I tought about changing [trans] for a fake <trans> element, which would
have given XPath flexibility, but since the output of the translator gets
encoded, it is not possible.

/cc @webmozart

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 27, 2014

[Form] Tests for #10108, label pluralization
This commit introduce a rewritten of multiple tests concerning form
labels. The StubTranslator now outputs [trans number=N] instead of
[trans] when transchoice is used. This is necessary to recognize the use
of transchoice. Unfortunately, it changes the output of all tests, so
they must be adapted even if they are not concerned.

I tought about changing [trans] for a fake <trans> element, which would
have given XPath flexibility, but since the output of the translator gets
encoded, it is not possible.

/cc @webmozart

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Sep 27, 2014

[Form] Tests for #10108, label pluralization
This commit introduce a rewritten of multiple tests concerning form
labels. The StubTranslator now outputs [trans number=N] instead of
[trans] when transchoice is used. This is necessary to recognize the use
of transchoice. Unfortunately, it changes the output of all tests, so
they must be adapted even if they are not concerned.

I tought about changing [trans] for a fake <trans> element, which would
have given XPath flexibility, but since the output of the translator gets
encoded, it is not possible.

/cc @webmozart

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Oct 3, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Oct 3, 2014

lavoiesl added a commit to lavoiesl/symfony that referenced this issue Oct 3, 2014

@abdeltiflouardi

This comment has been minimized.

Show comment
Hide comment
@aitboudad

This comment has been minimized.

Show comment
Hide comment
@aitboudad

aitboudad Oct 10, 2015

Contributor

Closing as the related PR was closed.

Contributor

aitboudad commented Oct 10, 2015

Closing as the related PR was closed.

@aitboudad aitboudad closed this Oct 10, 2015

@yanict

This comment has been minimized.

Show comment
Hide comment
@yanict

yanict Aug 3, 2016

Hi,
even after investigating during hours, I don't see a correct solution to this.
could @lavoiesl or @aitboudad give some inputs ?

I'm working on symfony 2.7.
I have a choice field and its labels need to be translated in plural.
I was thinking to use the %count% parameter but still, I don't understand how I can pass a parameter to the translation there.

Thanks a lot for your help.

yanict commented Aug 3, 2016

Hi,
even after investigating during hours, I don't see a correct solution to this.
could @lavoiesl or @aitboudad give some inputs ?

I'm working on symfony 2.7.
I have a choice field and its labels need to be translated in plural.
I was thinking to use the %count% parameter but still, I don't understand how I can pass a parameter to the translation there.

Thanks a lot for your help.

@kniziol

This comment has been minimized.

Show comment
Hide comment
@kniziol

kniziol Sep 25, 2016

@yanict solution is here: #10125 (comment). You should override block of label that has translation with pluralization.

kniziol commented Sep 25, 2016

@yanict solution is here: #10125 (comment). You should override block of label that has translation with pluralization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment