Prerequisites:
Basic knowledge of Gatsby and Sanity.io
tl;dr
You can find the starter source here and the demo here
Gatsby is a great tool for...
For further actions, you may consider blocking this person and/or reporting abuse
I did a similar setup but didn't know about the GraphQL resolver to filter the Sanity data. That's such a smart solution!
One thing that I realised however is that there is no real reason to separate translations in two separate data source: Sanity and json files. This complicates the setup and also editors won't be able to change whatever is in your source code json. You could just put everything in Sanity and have a single source of content and editable!
Hi Adrien, thanks! In that project I wanted to use i18next because it's used in some components I reused from a different project. It also makes the translation of snippets available with hooks / hocs and avoids prop-drilling snippets. You could of course load the i18next translations from sanity, but for me just using json files was a bit easier.
In what way did you end up putting all the content to Sanity? Using translation keys the same way as using json files and loading them to i18n-next or some other way? Did you manage translation interpolation this way?
Absolutely. I didn't need translation interpolation on that specific website but it should just work fine since Sanity API data is normal json, you can inject that as a ressource in i18n-next.
I might setup a fork of this repo soon (since I'm starting a new project really soon) so I'll try to remember and post it here as well.
But here is a snippet of how I did it:
I only used this for global "commons" data but you could probably just inject all your Sanity data in i18n-next and then your component all use the i18n-next hooks to display CMS data.
Hey Adrien could you setup up a fork or upload any example of your approach :)
Have a look there github.com/grsmto/gatsby-starter-i...
Thanks a lot I have checked it :) I think you continue updating this project?
Any idea how should resolver for SanityLocaleBlock look like? I would be thankful for any recommendation. Thanks!
Mine looks something like this:
Can you provide us with your setup plet
Hi I've been using this starter and it's working amazingly. Very simple. One thing that I am not getting is fallback - If the language I'm translating does not have a corresponding key in the json files then it just displays the key instead of falling back to my default language (english.) I tried to debug this but could not make it work. Do you know what is causing this?
I figured it out - the fall back settings need to be set in the wrapper component instead of the SSR i18next instance during createPages. That confused me. Thank you!
Is there a way to share your Gatsby + Sanity project here ?
This is so good. Wow. Thank you sir. Im trying the same, but with directus.io instead of sanity. Lets see how it goes... :D
Sir can you share your sanity sanityShop document object or schema from sanity ? I wanted to explore how you have created scheme from sanity side.