【问题标题】:JMSTranslationBundle not extracting 'placeholder' elementsJMSTranslationBundle 未提取“占位符”元素
【发布时间】:2014-04-10 17:42:44
【问题描述】:

我正在使用 JMSTranslationBundle (v1.1.0) 从我的源代码中提取翻译密钥,但由于未知原因(过去 4 小时我一直在寻找原因 - 真的),脚本找不到placeholder 文字。它会发现:验证消息、模板中的可翻译字符串、PHP 表单中的文本......以及它应该的所有内容 EXCEPT placeholder 文本。我检查了 JMSTranslationBundle 存储库,这是 9 个多月前添加的功能,没有任何实际问题。

这是一个例子:

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'
            )),
    ));
}

脚本会找到:

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

但它找不到 user.auth.password.password.placeholder

我在日志文件中没有错误,详细模式 (-vvv) 没有显示任何内容,所以我不知道在哪里查看。

这是我正在使用的命令行(以防它来自命令行):

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

如果您需要更多信息,请在 cmets 中询问,我很乐意为您提供。

非常感谢您的帮助!

【问题讨论】:

    标签: php symfony internationalization


    【解决方案1】:

    终于发现了!

    按照Installation 文档中的建议,我使用了最新的稳定 版本,即v1.1.0

    请将上面 sn-p 中的 dev-master 替换为最新的 stable 分支,例如 1.0.*。

    所以我将版本~1.1 添加到作曲家中。不幸的是,这个版本已经 10 个月大,并且不包括解决 placeholder 问题的最新合并(那是 9 个月前)!

    因此,如果您需要提取placeholder 元素,请使用dev-master 版本,而不是推荐的“最新稳定版”~1.1

    我希望这篇文章能帮助您避免在搜索了 8 多个小时后撕掉自己的脑袋的冲动 ;-)

    编码愉快!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 2015-04-20
      • 2016-12-12
      • 2016-09-14
      • 1970-01-01
      相关资源
      最近更新 更多