批量操作中的奏鸣曲管理员翻译

时间:2017-11-10 09:23:08

标签: symfony translation sonata-admin

我在sonata admin中有一些翻译问题。我以下一种方式配置了批处理操作:

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

    return $actions;
}

以这种方式在应用程序中工作,但问题是当我尝试从控制台获取翻译时:

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

我收到此错误:

[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 */".

所以,我发现这个错误并且在stackoverflow一个答案中说你只需要用字符串填充标签并且它有意义(文档解释that),所以我做了但是问题是这个翻译在管理界面中不起作用。

我也尝试填写翻译域但是不起作用,使用翻译的唯一方法是使用下面的示例,但这样做我无法从控制台中提取变量。

任何提示?

1 个答案:

答案 0 :(得分:0)

使用translation_domain指定自定义翻译域

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

在你的ApplicationNewsBundle。[lang] .xliff中,你必须有这样的东西:

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