ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

Support for @sanity/document-internationalization #292

Open sorokin-energi opened 1 year ago

sorokin-energi commented 1 year ago

Hi,

@sanity/document-internationalization can add __i18n_lang, __i18n_refs and __i18n_base fields to schemas with i18n flag.

But it's also possible to use custom names on both global or schema level:

image

Two options are in my mind

  1. try to support specifically this official plugin
  2. try to support dynamic type extension (for instance with codegen option and something similar to openapi spec syntax)

Like

const type = defineType({
    name: 'myType'
    i18n: true,
    codegen: {
        extend: {
           __i18n_lang: { type: [String] },
           ...
        }  
    } 
})
ochicf commented 1 year ago

Ideas to handle this in v1:

Then the generator would add the configured/default field names for schemas with i18n: true.