1

当使用“@angular/localize/”中的 $localize 和“ ng serve --configuration=de ”时,我得到了这个: $localize 未定义

仅使用“ ng serve ”运行项目时,它可以完美运行。

在 app.component.ts

public product: TabDefinition = { name: $localize`Products`, route: "/products" };

在 Polyfills.ts 中

import "@angular/localize/init";
import { loadTranslations } from "@angular/localize";

loadTranslations({
    "6707361102856436710": "Produkte",
  });
4

2 回答 2

2

我所做的是制作一个TranslationComponent,只要您在模板中指定 id 并且在$localize调用中它会正确映射

<p i18n="@@pending-changes">You have unsaved changes are you sure you want to navigate?</p>
return confirm($localize`:@@pending-changes:You have unsaved changes are you sure you want to navigate?`);
   <trans-unit id="pending-changes" datatype="html">
        <source>You have unsaved changes are you sure you want to navigate?</source>
        <target state="translated">Vous avez des modifications non enregistrées, êtes-vous sûr de vouloir naviguer?</target>
        <context-group purpose="location">
          <context context-type="sourcefile">src/app/shared/component/translations/translations.component.html</context>
          <context context-type="linenumber">1</context>
        </context-group>
      </trans-unit>

干杯

在此处输入图像描述

于 2020-03-17T14:57:52.970 回答
1

你加了这个

import '@angular/localize/init'; 

到您的 polyfills.ts 文件?

可能路径有问题。尝试这个:

import '../node_modules/@angular/localize/init';
于 2020-02-11T11:12:44.000 回答