tos-plugin-sanity
This is a Sanity Studio v3 plugin.
Installation
npm install sanity-plugin-tos
Usage
Please note that this plugin requires the document-internationalization plugin to be enabled in your Sanity Studio.
Add it as a plugin in sanity.config.ts
(or .js):
import {defineConfig} from 'sanity'
import {StructureBuilder} from "sanity/structure";
import {tosPlugin} from 'sanity-plugin-tos'
const languages = [
{id: 'es-ES', title: 'Spanish'},
{id: 'en-US', title: 'English'},
{id: 'de-DE', title: 'German'},
{id: 'fr-FR', title: 'French'}
];
export default defineConfig({
plugins: [
documentInternationalization({
supportedLanguages: languages,
schemaTypes: ['eventType'],
weakReferences: true,
}),
structureTool({
defaultDocumentNode: (S: StructureBuilder) => {
return S.document()
.views([
S.view.form(),
tosPlugin(S, {
env: 'staging' | 'sandbox' | 'production',
apiKey: TOS_API_TOKEN,
sourceLanguage: 'en-US',
supportedLanguages: languages
})
])
}
})
],
})
TOS plugin options in Sanity Studio's schema
TOS plugin options can be set in the schema definition of a field. The following options are available, both optional:
defineField({
name: 'eventTitle',
type: 'string',
title: 'Event title',
options: {
tosProperties: {
exclude: true,
charLimit: 100,
}
}
})
You can exclude
the field from being translated by the TOS plugin, or set a charLimit
for the field's translation (currently charLimit
is not available).
What is translated by default
The plugin will translate all fields of the document that are of type string
, array
or block
.
For sure, the plugin will not translate fields that are set to exclude
in the schema definition and fields that are not of the mentioned types, like boolean
, date
, reference
, image
, etc.