🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Implementing GraphQL i18n support for document translations

16 replies
Last updated: Oct 10, 2022
Just read the documentation here for GraphQL i18n support.
https://github.com/sanity-io/document-internationalization/blob/main/docs/graphql-intl-doc.md
Where does this schema work need installing to get document level translations to work? It’s not clear from these examples.
Oct 10, 2022, 1:40 PM
Also the reference in the second block of code. What is that a reference too?
Thinking this documentation might need an update or two.
Oct 10, 2022, 2:34 PM
The first code example is referring to wherever you’re setting up configuration for the plugin. Most often that’s in a config file, but some put it in an
i18n
key right on a schema.
Imagine a
product
schema, the final setup should look like this:

{
  name: 'product',
  title: 'Product'
  type: 'document',
  i18n: {
    fieldNames: {
      lang: 'i18n_lang'
      baseReference: 'i18n_base',
      references: 'i18n_refs'
    }
  }
  fields: [
    {
      name: 'i18n_lang',
      type: 'string',
      hidden: true,
    },
    {
      name: 'i18n_base',
      type: 'reference',
      to: [{type: 'product'}],
      hidden: true,
    },
    {
      name: 'i18n_refs',
      type: 'array',
      hidden: true,
      of: [
        {
          type: 'reference',
          to: [{type: 'product'}],
        },
      ],
    },
  ],
}
Oct 10, 2022, 2:54 PM
(also you’re not wrong about that code example, LMK know how you get on with what I’ve posted above)
Oct 10, 2022, 2:54 PM
Thanks User! Giving that a test now.
Oct 10, 2022, 2:56 PM
All appears to work fine from the Sanity side looking at the first screenshot with the fields made visible.
Oct 10, 2022, 3:11 PM
I’ve then done a
sanity start
and also a
sanity graqhql deploy
but cannot see the localised content anywhere?
Oct 10, 2022, 3:11 PM
Is that doc on the right published?
Oct 10, 2022, 3:13 PM
It is, yes
Oct 10, 2022, 3:14 PM
Your new i18n fields aren’t present in the GraphQL schema either
Oct 10, 2022, 3:14 PM
Sure GraphiQL is updated?
Oct 10, 2022, 3:14 PM
Sorted it, I was in the wrong dataset on my Gatsby build.
Oct 10, 2022, 3:16 PM
facepalm
Oct 10, 2022, 3:16 PM
success
Oct 10, 2022, 3:17 PM
Can’t argue with results. Got there.
Oct 10, 2022, 3:17 PM
I was so close to just refactoring this project into NextJS just to use groq too!
Oct 10, 2022, 3:18 PM
😂
Oct 10, 2022, 3:19 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?