Get a peek at our latest innovations at Sanity Product Day on Dec 8th โ†’

Document vs. Field Level Localization for Large Numbers of Languages

3 replies
Last updated: Aug 6, 2021

This way of doing localization works great when you have 2-3 languages. But let's say you have 10 different languages, this becomes really noisy to have all listed for every text field in a document. Is there any good alternative to solve this? Document level localization is not an option, as we might want to share some fields (e.g. images etc.).

Aug 6, 2021, 7:48 AM

Could you create a custom object input component that accept arbitrary fields, but split them into as many languages as necessary? i.e

import { createLocalizer } from 'sanity-localize'

const localize = createLocalizer({
  langs: ['en', 'ko', 'zh'],
})

export default {
  type: 'document',
  name: '..'
  fields: [
    localize({
      title: 'Title',
      name: 'title',
      type: 'string',
    })
  ]
}
would yield something like

{
  title: {
    en: 'Hello',
    ko: '์•ˆ๋…•',
    zh: 'Nihao'
  },
}
In the UI itโ€™d be a single input field, but with tabs:


Title

|*EN*| KO | ZH |
-----------------------------
| Hello                     |
-----------------------------
This is what I did with NetlifyCMS before it supports i18n natively, worked out pretty well

Aug 6, 2021, 8:55 AM
Aug 6, 2021, 9:01 AM

Thank you all for great feedback. I will go through them and take a look at each one. ๐Ÿ™‚

Aug 6, 2021, 2:30 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.