简体   繁体   中英

Angular 9 $localize not working with --configuration=de

When using $localize from "@angular/localize/" with " ng serve --configuration=de " i get this: $localize 未定义

It works perfect when running the project with just " ng serve ".

in app.component.ts

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

in Polyfills.ts

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

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

What i have done is make a TranslationComponent , as long as you specify the id in the template and in the $localize call it will map correctly

<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>

Cheers

在此处输入图片说明

Did you add this

import '@angular/localize/init'; 

to your polyfills.ts file?

Maybe there is path problem. Try this:

import '../node_modules/@angular/localize/init';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM