core icon indicating copy to clipboard operation
core copied to clipboard

Translate objects recursively when key points to object in translations

Open bolemeus opened this issue 3 years ago • 2 comments
trafficstars

fix for #946

Motivation: I want to be able to use the translate pipe in combination with the *ngFor keyword in my angular components

With this Pull Request the following now works...

translations.json

{
  OBJECT: {
    TEST: 'this is a test {{key}}',
    ANOTHER_TEST: 'this is another test {{key}}'
  }
}

any view

<ul>
  <li *ngFor="let translation of 'OBJECT' | translate: { key: 'value' } | keyvalue">{ translation.value }</li>
</ul>

result

<ul>
  <li>this is a test value</li>
  <li>this is another test value</li>
</ul>

previously the interpolation would fail, resulting in

<ul>
  <li>this is a test {{key}}</li>
  <li>this is another test {{key}}</li>
</ul>

bolemeus avatar Apr 08 '22 15:04 bolemeus

Integrated in upcoming ngx-transalte 16 https://github.com/CodeAndWeb/ngx-translate/commit/f304f9ba2098678788145f834bc34d271ce3e918

CodeAndWeb avatar Sep 25 '24 10:09 CodeAndWeb

In your fork v16, please do not make people confused

ocombe avatar Sep 26 '24 04:09 ocombe

Fixed in @ngx-translate/core@16

CodeAndWeb avatar Nov 03 '24 11:11 CodeAndWeb