Transloco: Can't retrieve from the translation arrays and objects

Created on 3 Oct 2019  路  5Comments  路  Source: ngneat/transloco

I'm submitting a...


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

Current behavior

Getting Missing translation for 'roles' while trying to retrieve an array/object from the translation.

Expected behavior

Should return the expected object without triggering any error.

Minimal reproduction of the problem with instructions

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>

Environment


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

bug

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

All 5 comments

@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).

Was this page helpful?
0 / 5 - 0 ratings