I'm building an angular app with ngx-translate. It's working nicely. Now I'm starting to have data coming from my backend(firebase), for which I will have translations.
What is the correct way of displaying localized data from a model? I've not yet settled on the data format, so either it will be something like:
{
'title_fr': 'mon titre',
'title_en': 'my title',
'title_de': 'mein Titel',
'description_fr' : '....'
//...
}
either something like:
{
title: {'fr':'mon titre', 'en': 'my title', 'de': 'mein Titel'}
description: { 'fr': 'ma description', /*...*/}
}
and I'm not sure how to display them:
- I will have a lot of
ngFor
iterating on observable of those items, if I could avoid to having to map every data, it would be great - when the language change, I also need to have the correct translation displayed
What would you recommend me?
If you are able to define the data you can get from your backend then probably you can make the data structure as below,
Then you can find your locale by findIndex method in the array dataLocalization and use its title and description values