sanity-io / assist

Sanity AI Assist: A plugin for Sanity Studio
MIT License
13 stars 5 forks source link

Ability to specify string, async function or resolve reference path for document translate language option #32

Open spacedawwwg opened 5 months ago

spacedawwwg commented 5 months ago

Is your feature request related to a problem? Please describe. Currently, the translate requires a language field to work.

Describe the solution you'd like It would be great to be able to 1) define a simple string in the settings if one language is only ever used 2) an async function incase the language code comes from elsewhere 3) languageField can be a reference value (like previews) as the language could be a document itself.

e.g.

assist({
  translate: {
    document: {
      // basic, easy setting for ALL documents using one language
      language: 'fr',
      documentTypes: ['newsArticle', 'page']
    }
  }
})
assist({
  translate: {
    document: {
      // fetch the language from somewhere
      language: async () => client.fetch(/* LANGUAGE QUERY */),
      documentTypes: ['newsArticle', 'page']
    }
  }
})
assist({
  translate: {
    document: {
      // myReferenceField is a document with a language field set on it
      languageField: 'myReferenceField.language',
      documentTypes: ['newsArticle', 'page']
    }
  }
})

Describe alternatives you've considered I have considered adding a hidden field, but we want the language value set outside the individual documents