[ x ] Regression (a behavior that used to work and stopped working in a new release)
[ x ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:
Getting Missing translation for 'roles' while trying to retrieve an array/object from the translation.
Should return the expected object without triggering any error.
en.json:
{
"title": "It works",
"roles": ["But", "this", "does", "not", "work"]
}
template.component.html:
<ng-container *transloco="let t">
<h2>{{ t('title') }}</h2>
<pre>{{ t('roles').join(' ') }}</pre>
</ng-container>
Angular version: 9.0.0-next.9
Browser:
- [ x ] Chrome (desktop) version 77
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX 10.11.0
- Platform: win32 x64
Others:
When I updated the package without using the schematics,
I got the same error until I found out I had to change
to `selectTranslateObject` in my services, so my guess is that `t()` is
using `selectTranslate` event when it's an object.
Maybe you should internally determine if to use `selectTranslate` or `selectTranslateObject`.
Or at least throw a different error, since the value does exists :)
@Newbie012 Thanks for the report, I have fixed the issue and it will be up in the next couple of hours
@Newbie012
Fixed in #113.
Published in v2.0.3.
If you are using the messageformat plugin you will also need to upgrade to v1.1.1.
If you are using the optimize plugin you will also need to upgrade to v1.0.1.
I can confirm it has been solved for arrays, but not for objects.
`
"links2": [], // <-- Will work
"links": { <-- getting "Missing translation for 'app.footer.links'"
"key": "value",
"...": "...",
},
@Newbie012 the translations are being flattened in runtime, so if you need to select a translation key as object you will have to use selectTranslationObject or getTranslationObject from the service.
take a look at the docs:
https://app.gitbook.com/@netbasal/s/transloco/service-api/translation-api
@itayod thanks for the fast response.
I'm aware of the following methods you mentioned. Although, I was hoping to accomplish it using directives. Either way, I eventually solved it by using t('links.' + link.text).
Most helpful comment
@itayod thanks for the fast response.
I'm aware of the following methods you mentioned. Although, I was hoping to accomplish it using directives. Either way, I eventually solved it by using
t('links.' + link.text).