VichUploaderBundle: vich_file_label create missing translations

Bug Report

Q A
BC Break no
Bundle version 1.14.0
Symfony version 4.4.9
PHP version 7.4

Summary

Hi @garak, thanks for this useful bundle.

The way VichUploader translate the form label seems buggy to me and report missing translations.

{%- block vich_file_label -%}
    {%- set label = label|trans|default(label) -%}
    {{- block('form_label') -}}
{%- endblock -%}

Firstly, when using 'label' => false, it use trans on false and report a missing translation for ''. Same when providing no label, it use trans on null. This leads to an error with Symfony 5. (Cf https://github.com/dustin10/VichUploaderBundle/issues/1066)

Secondly, when using 'label' => 'myLabel', it use obviously trans on myLabel. But the block form_label try to translate the label too with the option 'translation_domain'. This means that the profiler report a missing translation when trying the second translation.

Finally, when using 'translation_domain' => false, the label is still translated.

Solutions

The difficulty would be to determine what is BC and what is BC-break

Currently, If I have the following translations

#messages.yaml
myLabel: foo
myLabel2: bar

#VichUploaderBundle.yaml 
myLabel3: baz
bar: hello
  • myLabel will be translated to foo with the first trans. (and then foo will be a missing translation in VichUploaderBundle)
  • myLabel2 will be translated to bar with the first trans. And then it will be translated to hello by form_label.
  • myLabel3 will be reported as a missing translation and then will be translated to baz.

IMHO the best solution would be to

  • add a delete_translation_domain option and use it instead of translation_domain for delete_label.
  • add a download_translation_domain option and use it instead of translation_domain for download_label
  • change the default value of translation_domain to messages.
  • remove the {%- set label = label|trans|default(label) -%} code. But this would need to release a new major version.

I didn’t find a BC way to fix both the fact that false/null throw an error with Symfony 5 and the double translate calls which leads to missing translations.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Yes indeed.

I was just considering that was the purpose of the translation domains. Create a prefix for the download_label and the delete_label is similar to adding a action_translation_domain.

But the prefix solution could fix everything too, if it’s the solution you prefer.