#Got stuck on something stupidly simple,, I have be...

19 messages · Page 1 of 1 (latest)

zealous socketBOT
#

Got stuck on something stupidly simple,, I have been looking at this code for an hour, and I can't get it right. I have a global collection in Directus, that is translated to a bunch of languages, when trying to get the content in an example next.js app I only get the default text, not the translated one, this one in french...):

async function getGlobals() {
    const languageCode = 'fr-FR';
    const { data } = await directus.items('global').readByQuery({
        fields: ['*'],
        deep: {
            translation: {
                _filter: {
                    languages_code: {
                        _eq: languageCode,
                    },
                }
            }
        }
    });
    return data;
}
```.

Just so you know, we have moved your message here, @abstract saffron. In future, please ask questions in one of the help channels as per the server rules.

@stone sorrel was the person who moved it, so if there's aditional context, they will add it here for you. Your original post has been deleted.
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

stone sorrel
#

Looks like you're missing translations.<translated_fields> in your fields list

#

Oh, yeah, thanks... but still nothing, do I do something wrong with the filters maybe?

async function getGlobals() {
const languageCode = 'fr-FR';
const { data } = await directus.items('global').readByQuery({
fields: ['', 'translations.'],
deep: {
translation: {
_filter: {
languages_code: {
_eq: languageCode,
},
}
}
}
});
return data;
}

#

@abstract saffron What is the actual result you're getting versus what you expect?

abstract saffron
#

I am getting the "original" content (en-UK), instead of the translated one.

stone sorrel
#

Do you have some result snippets with that? can't see any naming errors by description (perhaps your field isnt called languages_code or something)

abstract saffron
#

It looks like this:

abstract saffron
#

Is the reference on the translatiuons wrong?

stone sorrel
abstract saffron
#

Adding the filter it looks like this:

#

I am sure doing something wrong here 😄

stone sorrel
abstract saffron
#

Sorry, now following that...

stone sorrel
abstract saffron
#

Oh wait... I am stupid. Sorry.

abstract saffron
#
async function getGlobals() {
    const languageCode = 'fr-FR';
    const { data } = await directus.items('global').readByQuery({
        deep: {
            translations: {
                _filter: {
                    languages_code: {
                        _eq: languageCode,
                    },
                }
            }
        },
        fields: ['translations.*']
    });
    return data.translations[0];
}