Language fallback when language not yet maintained
m
mnuernberger
Summary
Currently, when requesting a locale from Strapi not yet maintained, an empty response is being returned. It would be great if one could configure a fallback language.
Why is it needed?
It is needed in order to dynamically pull data from CMS and not having issues when a certain language is not available.
Suggested solution(s)
Possibility to configure a fallback language for requests on non-existent locals.
Evge K.
That would be cool.
Derrick Mehaffy
I believe this might be planned for Strapi 5 but I'm asking internally to confirm
Pedro Torres (Peze)
You can put a filter on locale that looks like
{
filters: { locale: [ctx.query.locale, "en"] }
}
So, if it no finds the content on the first language, this will find it in the default language that in this case is English.
Noel Rocher
No news for this more than welcome feature request ?
Laurence Cope
Until this is available I am using an alias to fetch the content in the default lang as follows (not just leaving out ${locale} on the default fetches the default):
const fetchContent = await request(
process.env.STRAPI_GRAPHQL,
gql`
query fetchContentBySlug {
pagesLang: pages(filters: {slug: {eq: "${slug}"}}, locale: "${locale}")
{
...pageFields
}
pagesDefault: pages(filters: {slug: {eq: "${slug}"}})
{
...pageFields
}
}`
)
And then I do a check if the pagesLang exists, and if not, then fetch the Default pages:
if(fetchedContent.pagesLang.data.length > 0)
{
content = fetchedContent.pagesLang.data;
}
else if(fetchedContent.pagesDefault.data.length > 0)
{
content = fetchedContent.pagesDefault.data;
}
Adriaan
This would help us a lot. We now have to download all entries in every locale and find the fallback locale ourselves. This query already takes between 30-60 seconds, so it's not really great.
Sorting doesn't work anymore when not having a fallback locale.
Another related issue: https://github.com/strapi/strapi/issues/12799
Rortan
Any updates on this?
Mar El
As Pointed out in a response, using accept language header to achieve that would be neat.
Max Mathys
I find this feature really important. Would appreciate if someone could come up with a workaround.
Adriaan
Max Mathys: at the moment we get all locales and find the right one in our front end. But that request takes sometimes 60 seconds. So not really a great solution.