Angular i18,不会翻译文本

时间:2018-11-27 08:17:48

标签: angular internationalization

为了翻译页面,并按照本教程https://angular.io/guide/i18n的操作,我做了以下简单的操作,但看不到任何已翻译的文本。为什么?非常感谢你!

1)翻译定义。在新文件夹src / locale中,我使用以下代码创建了文件messages.en.xlf和messages.it.xlf(显然,它更改了每种语言的目标):

<trans-unit id="introductionHeader" datatype="html">
  <source>placeholder</source>
  <target>Ciao i18n! (it-IT)</target>
  <note priority="1" from="description">An introduction header for this sample</note>
  <note priority="1" from="meaning">User welcome</note>
  <target state="new">bye bye</target>
</trans-unit>

2)标签定义。在我的html页面中,插入以下带有占位符的标记:

<h1 i18n="@@introductionHeader">
    placeholder
</h1>

3)在angular.json文件中,插入以下行:

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/mobile-client",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "i18nFile": "src/locale/messages.it.xlf", //This
            "i18nLocale": "it",                       //This
            "i18nFormat": "xlf",                      // This
            "assets": [
(...)

然后,我尝试构建和服务,但看不到翻译后的文字“再见”。我该如何解决?非常感谢你!

0 个答案:

没有答案