a2lix / TranslationFormBundle

Ease translations with some dedicated Symfony form types
https://a2lix.fr/bundles/translation-form
MIT License
330 stars 138 forks source link

Add translatable locale labels (Should fix #262) #365

Closed tchapi closed 2 years ago

tchapi commented 2 years ago

Fixed

Tab labels are now translatable / can be tailored.

To do

Documentation

You may now set labels for each tab by adding a locale_labels array to the TranslationsType form type, like so:

$form = $this->factory->createBuilder(FormType::class, new Product())
    ->add('translations', TranslationsType::class, [
        'locale_labels' => [
            'fr' => 'Français',
            'en' => 'English',
        ],
    ])
    ->add('save', SubmitType::class)
    ->getForm()
;

If a label is not set here (in this examplen de for instance), its value will default to null and the previous behaviour will kick-in (the template with capitalize the locale name).

Hence, this does not introduce any breaking change and no change of defaults, and seems perfectly safe.

As the trans filter is used in the templates, you can also use translation keys directly here:

$form = $this->factory->createBuilder(FormType::class, new Product())
    ->add('translations', TranslationsType::class, [
        'locale_labels' => [
            'fr' => 'admin.language.fr.tab_title',
            'en' => 'admin.language.en.tab_title',
        ],
    ])
    ->add('save', SubmitType::class)
    ->getForm()
;
tchapi commented 2 years ago

I haven't found where the docs (from your website) get built, but we might want to update and add a paragraph about it there if you find the PR relevant.

webda2l commented 2 years ago

Sound good :) Documentation is https://github.com/a2lix/a2lix.github.com/blob/master/bundles/translation-form/3.x.html#L150-L169

tchapi commented 2 years ago

ok, I'll try to find time to update the docs then

tchapi commented 2 years ago

See https://github.com/a2lix/a2lix.github.com/pull/31 for the update to the docs

tchapi commented 2 years ago

(The branch is protected so I cannot merge, but this PR and the other one in the docs should be good to go :) )

webda2l commented 2 years ago

Thanks @tchapi, still something that I don't understand with the github rights to allow you to merge :/

tchapi commented 2 years ago

🎉