Understanding problem

I want to create a Multilanguage Collection. I make the Api request according to the documentation.

fetch('/api/collections/get/posts?token=xxtokenxx', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
    filter: {published:true},
    fields: {fieldA: 1, fieldB: 1},
    limit: 10,
    skip: 5,
    sort: {_created:-1},
    populate: 1, // resolve linked collection items

    lang: 'de' // return normalized language fields (fieldA_de => fieldA)
}))
.then(res=>res.json())
.then(res => console.log(res));

But how do I have to create my collection in the backend?

Thank you!

  1. Make sure, that you enabled languages via config file.
i18n: en              # default language, if "en", you can skip this one
languages:
    default: English  # change "default" option in language switch to "English"
    de: Deutsch       # second language
  1. enable the “Localized” button in the field options on the collection settings page
  2. Don’t forget to translate your collection items
  3. There is a bug if you use the fields projection. You have to select the fields with language suffix, too.

This should work:

fetch('/api/collections/get/posts?token=xxtokenxx', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
    filter: {published:true},
    fields: {fieldA: 1, fieldA_de: 1 fieldB: 1, fieldB_de: 1}, // I added the fields lang suffix
    limit: 10,
    skip: 5,
    sort: {_created:-1},
    populate: 1, // resolve linked collection items

    lang: 'de' // return normalized language fields (fieldA_de => fieldA)
}))
.then(res=>res.json())
.then(res => console.log(res));
1 Like

Thank you very much!

Had it then found out myself.

Important perhaps to mention, default field without “_lang” all others with.

  1. I could not reproduce. Here is my call with Nuxt, works great.

    async asyncData({ app }) {
    const { data } = await app.$axios.post(process.env.POSTS_URL,
    JSON.stringify({
    filter: { published: true },
    sort: { _created: -1 },
    populate: 1,
    lang: app.i18n.locale
    }),
    {
    headers: { ‘Content-Type’: ‘application/json’ }
    })

return { posts: data.entries }

This time, you fetched the whole entry. The bug is present if you use the fields projection.