【问题标题】:Untranslated messages/entries list in Symfony2Symfony2 中未翻译的消息/条目列表
【发布时间】:2011-12-28 04:26:45
【问题描述】:

我发现我忘记在翻译文件中添加一些翻译(我在我的项目中使用 yaml)。不知何故需要找出那些并添加他们的翻译,但是手动这样做很麻烦。我想知道是否有更简单快捷的方法来完成这项任务。

【问题讨论】:

    标签: symfony translation yaml


    【解决方案1】:

    你应该安装JMSTranslationBundle:

    概述

    这个包让 Symfony 翻译组件更加强大。虽然翻译组件经过高度优化以减少代码的运行时开销,但它缺少一些翻译器功能。此捆绑包的目的是使网站的翻译更容易,同时仍保留当前实施的所有性能优化。

    主要特点包括:

    1. 允许开发人员向翻译 ID 添加额外的上下文,以帮助翻译人员找到可能的最佳翻译
    2. 优化的转储命令(更好的格式,为翻译人员提供更多信息,标记新消息)
    3. 优化的搜索算法(更快、更可靠地找到消息)
    4. 可以为捆绑包提取消息,并且可以通过设置您的应用程序(捆绑包)提取配置
    5. 配置以避免重新键入许多命令行参数/选项
    6. 基于 Web 的 UI,更容易翻译消息

    【讨论】:

    • 似乎这个可能会有所帮助:“基于 Web 的 UI 可以更轻松地翻译消息”。 ..但似乎 UI 仅用于添加和修改翻译。我想知道是否也可以通过使用它来查看未翻译消息的列表(因为这是我的实际问题)?
    • 您可以从您的应用程序中提取消息(功能 #4)。然后您可以使用基于 Web 的 UI,正如您所提到的。
    【解决方案2】:

    您无法使用 JMSTranslationBundle 找到所有未翻译的消息。它使用标准的 Symfony 方法来查找它们。要查找所有内容,您需要将服务附加到记录器。这样您就可以将未翻译的密钥写入数据库。

    我认为,这只适用于开发环境。

    <?php
    
    namespace AppBundle\Service;
    
    use AppBundle\Entity\Translation;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    use Monolog\Handler\AbstractProcessingHandler;
    
    class TranslationLogger extends AbstractProcessingHandler
    {
        protected $container;
    
        public function __construct (ContainerInterface $container)
        {
    
            $this->container = $container;
        }
    
        protected function write (array $record)
        {
            if ($record['channel'] === 'translation')
            {
                $em = $this->container->get('doctrine.orm.default_entity_manager');
                $check = $em->getRepository('AppBundle:Translation')->findBy([ 'transKey' => $record['context']['id'] ]);
    
                if (!$check)
                {
                    $new = new Translation;
                    $new->setTransKey($record['context']['id']);
                    $em->persist($new);
                    $em->flush();
                }
            }
    
        }
    }
    

    services.yml:

    services:
        appbundle.translation_logger:
            class: AppBundle\Service\TranslationLogger
            arguments: [ "@service_container" ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 2015-03-09
      • 1970-01-01
      • 2012-05-10
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多