Question

I am using JMSTranslationBundle (v1.1.0) to extract translation keys from my source but for an unknown reason (I have been searching why for the past 4 hours - really), the script can't find the placeholder text. It finds: validation messages, translatable strings in templates, text in PHP Forms... well everything as it should EXCEPT placeholder texts. I checked the JMSTranslationBundle repository, and this is a feature that was added more than 9 months ago with no actual issues about this.

Here is an example:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('password', 'repeated', array(
       'first_name'  => 'password',
       'second_name' => 'confirm',
       'type'        => 'password',
       'invalid_message' => 'user.auth.password.invalidMessage',
       'first_options' => array(
           'label' => 'user.auth.password.password.label'
       ),
       'second_options' => array(
           'label' => 'user.auth.password.confirmation.label'
       ),
       'options' => array(
            'label_attr' => array(
                'class' => 'control-label'
            ),
            'attr' => array(
                'placeholder' => 'user.auth.password.password.placeholder'
            )),
    ));
}

The script will find:

  • user.auth.password.invalidMessage,
  • user.auth.password.password.label and
  • user.auth.password.confirmation.label

But it won't find user.auth.password.password.placeholder

I have no errors in the log files, nothing showing up with the verbose mode (-vvv) so I don't know where to look.

Here is the command line I'm using (just in case it comes from the command line):

php app/console translation:extract --env=dev --keep --bundle=AcmeMyBundle --output-dir=./src/Acme/MyBundle/Resources/translations/ en

If you need more info, please ask in the comments, I'll be happy to provide them.

Thank you so much for your help !

Was it helpful?

Solution

I finally found out !

I used the latest stable version which is v1.1.0 as advised in the Installation docs

Please replace dev-master in the snippet above with the latest stable branch, for example 1.0.*.

so I added the version ~1.1 into composer. Unfortunately this version is already 10 months old and doesn't include the latest merges which addresses the placeholder issue (that was 9 months ago) !

So if you need to extract placeholder elements, use the dev-master version instead of the recommended "latest stable" ~1.1 !

I hope this post will save you the urge of ripping your own head off after more than 8 hours of search ;-)

Happy coding !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top