extract-i18n --output-path 在根文件夹中提取

extract-i18n --output-path extracts in root folder

为了提取翻译,我将 i18n 与 xliffmerge 结合使用。 我在 package.json 中添加了 extract-i18n 命令,如下所示:

"extract-i18n": "ng extract-i18n project --i18n-format xlf --output-path src/locale --i18n-locale en-US && ng run project:xliffmerge"

angular.json中的xliffmergeOptions是:

"xliffmerge": {
          "builder": "@ngx-i18nsupport/tooling:xliffmerge",
          "options": {
            "xliffmergeOptions": {
              "format": "xlf",
              "srcDir": "src/locale",
              "genDir": "src/locale",
              "defaultLanguage": "en-US",
              "languages": [
                "en-US",
                "nl-NL"
              ]
            }
          }
        }

每当我 运行 extract-i18n 命令时,messages.xlf 文件仍会导出到根文件夹而不是 src/locale。

我不知道为什么它没有导出到 src/locale 文件夹。

更新

从 Angular 11 升级到 Angular 12 后,这个问题仍然存在。


请使用这个命令


extract-i18n --output-path src/locale
你没有定义路径,这就是你遇到问题的原因你必须定义生成 xml 文件的路径现在我也在工作 i18n 如果你对 i18n 有任何疑问让我知道我会帮你的。



我在 package.json 中的脚本中配置它时犯了 运行 ng extract-i18n 的错误。相反,我应该使用 npm run extract-i18n.

这只解决了部分问题,因为 --i18n-format--18n-locale 不再受支持(或者看起来如此)。

正确的命令应该是:

"extract-i18n": "ng extract-i18n [projectname] --format xlf --output-path src/locale && ng run [projectname]:xliffmerge"

由于 Angular 在架构中弃用关键字“id”以支持“$id”,我不确定 xliffmerge 将继续工作多长时间,因为 ngx-i18nsupport 的开发已经停止几年前。