usr-local-ΕΨΗΕΛΩΝ
usr-local-ΕΨΗΕΛΩΝ

Reputation: 26874

Ngx-translate not translating anything

I am in the process of internationalizing my current Angular 12 prototype application. Prototype means there is only the skeleton and a bunch of administrative features, and the developer(s) are in the process of coding vertical features in their working branch.

I have done the following, mostly following this tutorial

Running the application, I expected text to appear in English, but was still localized. I have checked the Network tab and, indeed, the English JSON file is loaded

But none of the stings is localized in English

Localized page

The console shows no error.

What is wrong in this setup and what should I do next to display English text?

By using ngx-translate-extract, I am now using the third approach provided by the tutorial:

  • translation directive — id as a child <element translate>id</element>

so everything should work fine.

Following the GitHub tutorial, I moved the TranslationModule.forRoot import from the SharedModule to the AppModule. Same result as before.

Upvotes: 1

Views: 6374

Answers (1)

Jammer
Jammer

Reputation: 562

I fell into this trap, too, but finally figured it out.

A lot of angular elements create wrapper elements, so for example a:

<button translate>My message</button>

actually turns into

<button><span class="mat-button-wrapper">My message</span></button>

in which case the translation attribute lands on the wrong element.

I ended up having to do:

<button><span translate>My message</span></button>

to work around it.

Upvotes: 1

Related Questions