【问题标题】:Angular Ivy i18n: No translation found for <ID>Angular Ivy i18n:未找到 <ID> 的翻译
【发布时间】:2020-04-19 07:00:30
【问题描述】:

我已将使用 i18n 的现有 Angular 应用程序更新到版本 9。执行此操作后,它会在构建过程中引发错误,无法找到我的翻译:

No translation found for "6570363013146073520" ("Dashboard")

我注意到上面提供的 ID 在我的 messages.xlf 文件中不存在,并且看起来是完全不同的格式。

这是 Angular 9 之前的样子:

<trans-unit id="f65253954b66e929a8b4d5ecaf61f9129f8cec64" datatype="html">
  <source>Dashboard</source>
  <target state="final">The translated string</target>
</trans-unit>

我在 Github 上的 found this 谈到了这个问题,但我不明白它是如何解决的。我如何告诉 Angular 使用他们在该问题中讨论的“旧格式”?

或者有其他解决方案吗?

【问题讨论】:

    标签: angular internationalization


    【解决方案1】:

    我知道这是一个老问题,但我找到了一种传递错误的方法,你需要像这样给出 id :

    <h1 i18n="@@anyId">
      I don&apos;t output any element
    </h1> 
    

    而不是i18n="ba0cc104d3d69bf669f97b8d96a4c5d8d9559aa3",然后在你的.xlf文件中你需要像这样使用:

    <trans-unit id="anyId" datatype="html">
       <source>I don&apos;t output any element</source>
       <target>Je n'affiche aucun élément</target>
       <context-group purpose="location">
          <context context-type="sourcefile">app\app.component.ts</context>
          <context context-type="linenumber">10</context>
       </context-group>
    </trans-unit>
    

    这样,错误就会消失。

    【讨论】:

      【解决方案2】:

      您可能创建了一个有错误的翻译文件。确保它具有正确的翻译内容标签。您只需在标签&lt;source&gt;&lt;/source&gt;中的原始内容之后添加一个带有翻译内容&lt;target&gt;&lt;/target&gt;的新标签。例如:

      <trans-unit id="ba0cc104d3d69bf669f97b8d96a4c5d8d9559aa3" datatype="html">
         <source>I don&apos;t output any element</source>
         <target>Je n'affiche aucun élément</target>
         <context-group purpose="location">
            <context context-type="sourcefile">app\app.component.ts</context>
            <context context-type="linenumber">10</context>
         </context-group>
      </trans-unit>
      

      【讨论】:

        猜你喜欢
        • 2017-07-12
        • 1970-01-01
        • 2014-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多