0
votes

I have some problems with translations in sonata admin. I configured the batch action in the next way:

/**
 * {@inheritdoc}
 */
public function getBatchActions()
{
    $actions = parent::getBatchActions();
    $actions['import'] = array(
        'ask_confirmation' => false,
        'label' => $this->trans('app.admin.import', array(), 'ApplicationNewsBundle')
    );

    return $actions;
}

And in this way is working in the app but the problem is when I try to get the translation from the console:

php app/console translation:extract en nl  --bundle=ApplicationBy433NewsBundle --keep

I get this error:

[JMS\TranslationBundle\Exception\RuntimeException]
  Unable to extract translation id for form label from non-string values, but got "PHPParser_Node_Expr_MethodCall" in /var/www/symfony/src/Applicati
  on/NewsBundle/Admin/ArticleEnglishAdmin.php on line 32. Please refactor your code to pass a string, or add "/** @Ignore */".

So, I find this error and in stackoverflow one answer says that you need to fill the label only with the string and It make senses (documentation explain that), so I did it but the problem is that this translation is not working in admin interface.

I also try to fill translator domain but is not working, the only way to work with translations is with the below example, but doing that I can't extract vars from console.

Any tip?

1

1 Answers

0
votes

Use the translation_domain to specify custom translation domain

/**
* {@inheritdoc}
*/
public function getBatchActions()
{
    $actions = parent::getBatchActions();
    $actions['import'] = array(
        'ask_confirmation' => false,
        'label' => 'import',
        'translation_domain' => 'ApplicationNewsBundle'
    );
    return $actions;
}

In your ApplicationNewsBundle.[lang].xliff, you must have something like this :

        <trans-unit id="import">
            <source>import</source>
            <target>[your translation]</target>
        </trans-unit>