sveltekit-i18n / lib

Internationalization library built for SvelteKit.
MIT License
492 stars 32 forks source link

Can Arrays be translated? #92

Closed eikaramba closed 1 year ago

eikaramba commented 2 years ago

I have a list of FAQ entries as an array of objects like

[
  {
  title:"can i do xxxxxx?"
  text:"yes you can"
  },
  .....
]

I wasn't able to translate this, is this possible? it would be nice if i can just create a faq.json put the array there and use it via $t('faqs').

jarda-svoboda commented 2 years ago

Hi.) Currently it works like:

// faqs.json
{
  faqs: [
    {
      title:"can i do xxxxxx?",
      text:"yes you can"
    }
  ]
}
// page.svelte
$t('faqs.0.title');
eikaramba commented 2 years ago

yes that works, but the problem is that i am not able to get ALL Faq entries with that approach. basically i just want to retrieve all FAQ entries and filter them based on some query. doing $t('faqs') did not work for me. should it?

jarda-svoboda commented 2 years ago

Ok, it’s currently not designed to work this way.. However it can be useful so I’m adding it.

eikaramba commented 2 years ago

wow thanks, yeah that would be great. just had another case were this would be super helpful

Suyashtnt commented 1 year ago

Any updates on this? I would really like to be able to do this

CannonPhelps commented 1 year ago

I would really love to see this happen! I need it in projects!

Anastasia199129 commented 1 year ago

Tell me please, has not yet appeared a function for enumeration of arrays?