Set a fallback locale

It would be nice to set a fallback locale that in case the other locales aren’t filled when you request the particular locale, it would be filled by the fallback locale.

And maybe there’s a switch on the field/model on whether the field is filled with the fallback locale or left as blank/null.

hello @hesedel.pajaron welcome :slight_smile:

Where would you like to see the fallback values? Directly in the APIs?

Currently we have implemented that logic in the Gatsby source plugin and in our Middleman extension, maybe you can already use those?

Hi @mat_jack1, thanks for the reply!
Well, I would’t first think of using plugins meant for other static site generators.
I also wrote my own logic to merge the missing fields.
I assume the plugin also uses DatoCMS Content Delivery API? And fetches both languages then merges?

It would be great if this was already returned by the API when querying.

Yes, I’m not sure what you are using yourself, I mentioned our plugins as examples.

We are using the REST API in the plugins at the moment, we want to switch to GraphQL but it’s not done yet. But yes, we merge the information in the plugin right now.

OK, we’ll consider returning the fallback already in the API, would be good for us too :slight_smile:

1 Like

I’m just using a deepmerge with another language and English.
This is fine at the moment as I’m doing this when building the project.
But I’ll soon be using it on the client side and would rather not have to do the double request and merging there.
Thanks!

definitely useful :+1:

Graphcms has this kind of fallback (https://graphcms.com/docs/reference/localization) that looks nice:

Defining a Fallback

   {
      messages(locales: [de_ch, de, en]) {
        subject
        locale
      }
    }

Locales will be served in the order they are requested, left to right (Swiss German, German, English).

1 Like