1

我之前在不同的项目中使用过 JMSTranslationBundle 没有任何问题。

然而,这是我第一个使用 jms/translation-bundle:dev-master 的 Symfony3.4 项目。

配置如下:

jms_translation:
configs:
    app:
        dirs: ["%kernel.root_dir%", "%kernel.root_dir%/../src"]
        output_dir: "%kernel.root_dir%/Resources/translations"
        excluded_names: ["*TestCase.php", "*Test.php"]
        excluded_dirs: [cache, data, logs, translations]
        output-format: yml

运行php bin/console translation:extract --config=app en 正常并创建正确的翻译文件。当我再次运行该命令时,出现以下错误:

The format "yml" does not exist.

不要误认为我以前在这里看到的“.yml~”不存在错误。

当我使用 xliff 格式时我没有问题,我可以多次提取文件,它会按预期工作。

任何帮助将不胜感激 我已经检查了以前项目的所有配置文件几个小时,但我无法查明问题的根源。

4

1 回答 1

0

好吧,我终于找到了这个。

当我将输出格式设置为“yaml”而不是“yml”时,多次提取翻译没有问题。但是格式都搞砸了(没有分组)。当文件开始变大时,这不是一个很好的解决方案。

所以问题不是来自翻译的提取,也不是来自“yml”文件的创建。它来自于我们尝试解析旧文件的时候。

通过添加行

$format = ($format=='yml') ? 'yaml' : $format;

在第 84 行的 JMSTranslationBundle 的 LoaderManager.php 文件中:

  protected function getLoader($format)
{
    $format = ($format=='yml') ? 'yaml' : $format;
    if (!isset($this->loaders[$format])) {
        throw new InvalidArgumentException(sprintf('The format "%s" does not exist.', $format));
    }

    return $this->loaders[$format];
}

一切都按预期工作。.yml 文件生成并正确格式化。任何后续提取都会保持格式不变,没有任何错误。

当然,将行添加到供应商捆绑包并不是真正的解决方案,因此当我找到一种优雅的解决方法时,我将对其进行更多研究并提交拉取请求。

于 2017-11-06T13:28:38.217 回答