Symfony: Profiler/Twig Problem - Translation Messages Missing

Created on 1 Nov 2017  路  1Comment  路  Source: symfony/symfony

| Q | A
| ---------------- | -----
| Bug report? | yes
| Feature request? | no
| BC Break report? | no
| RFC? | no
| Symfony version | 3.3.10

Here is bug in web profiler? When I use form_label in twig, profiler not recognize translation. All others translations are ok. On web page all translations are ok inc. title.username and title.password but only profiler show translation missing error.

XLF Style

...
            <trans-unit id="title_username">
                <source>title.username</source>
                <target>Username</target>
            </trans-unit>
            <trans-unit id="title_password">
                <source>title.password</source>
                <target>Password</target>
            </trans-unit>
            <trans-unit id="title_new_registration">
                <source>title.new_registration</source>
                <target>Registration</target>
            </trans-unit>
...

Debug translation

$ bin/console debug:translation cs
 ------- ---------- ------------------------ ----------------------- ------------------------------- 
  State   Domain     Id                       Message Preview (cs)    Fallback Message Preview (en)  
 ------- ---------- ------------------------ ----------------------- ------------------------------- 
          messages   title.username           U啪ivatelsk茅 jm茅no       Username                       
          messages   title.password           Heslo                   Password                       
          messages   button.login             P艡ihl谩sit               Login                          
          messages   title.new_registration   Nov谩 registrace         Registration                   
          messages   title.renew_password     Zapomenut茅 heslo ?      Lost password ?                
 ------- ---------- ------------------------ ----------------------- ------------------------------- 

$ bin/console debug:translation en
 ------- ---------- ------------------------ ---------------------- 
  State   Domain     Id                       Message Preview (en)  
 ------- ---------- ------------------------ ---------------------- 
          messages   title.username           Username              
          messages   title.password           Password              
          messages   button.login             Login                 
          messages   title.new_registration   Registration          
          messages   title.renew_password     Lost password ?       
 ------- ---------- ------------------------ ---------------------- 

Profiler Bug - Translation Messages Missing (2x)


cs | messages | 1 | U啪ivatelsk茅 jm茅no | U啪ivatelsk茅 jm茅no
-- | -- | -- | -- | --
cs | messages | 1 | Heslo | Heslo


Twig

...
                        {{ form_widget(form._username) }}
                        {{ form_label(form._username, 'title.username'|trans) }}
                        {{ form_widget(form._password) }}
                        {{ form_label(form._password, 'title.password'|trans) }}
...
Bug Needs Review WebProfilerBundle

Most helpful comment

If you use one of the built-in form themes, the label will be passed to the translator by the theme. Thus, passing an already translated string to form_label() means that the translated value will be translated again leading to the behaviour you observe.

The following code should produce the result you expect:

{{ form_widget(form._username) }}
{{ form_label(form._username, 'title.username') }}
{{ form_widget(form._password) }}
{{ form_label(form._password, 'title.password') }}

Closing here as there is no bug.

>All comments

If you use one of the built-in form themes, the label will be passed to the translator by the theme. Thus, passing an already translated string to form_label() means that the translated value will be translated again leading to the behaviour you observe.

The following code should produce the result you expect:

{{ form_widget(form._username) }}
{{ form_label(form._username, 'title.username') }}
{{ form_widget(form._password) }}
{{ form_label(form._password, 'title.password') }}

Closing here as there is no bug.

Was this page helpful?
0 / 5 - 0 ratings