Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate objects recursively when key points to object in translations #1368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bolemeus
Copy link

@bolemeus bolemeus commented Apr 8, 2022

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>

…ns. (ngx-translate#946)

The following now works...

translations.json
```json
{
  OBJECT: {
    TEST: 'this is a test {{key}}',
    ANOTHER_TEST: 'this is another test {{key}}'
  }
}
```

any view
```html
<ul>
  <li *ngFor="let translation of 'OBJECT' | translate: { key: 'value' }">{ translation }</li>
</ul>
```

result
```html
<ul>
  <li>this is a test value</li>
  <li>this is another test value</li>
</ul>
```

previously the interpolation would fail, resulting in
```html
<ul>
  <li>this is a test {{key}}</li>
  <li>this is another test {{key}}</li>
</ul>
```
@@ -25,7 +25,7 @@
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"target": "es2019",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't sure about this one. I'm sure the code can be tweaked to avoid using Object.fromEntries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant