gt-sanity
v1.1.9
Published
General Translation integration with Sanity
Downloads
1,824
Readme
gt-sanity
This is a Sanity Studio v3 plugin.
Installation
npm install gt-sanityThen, create a GT project and get a production API key and project ID.
In your Studio folder, create a file called populateSecrets.js with the following content:
// ./populateSecrets.js
// Do not commit this file to your repository
import { getCliClient } from 'sanity/cli';
const client = getCliClient({ apiVersion: '2025-09-15' });
client.createOrReplace({
// The `.` in this _id will ensure the document is private
// even in a public dataset!
_id: 'generaltranslation.secrets',
_type: 'generaltranslationSettings',
// replace these with your values
project: '<GT_PROJECT_ID>',
secret: '<GT_API_KEY>',
});Run the script:
npx sanity exec populateSecrets.js --with-user-tokenVerify that the document was created using the Vision Tool in the Studio and query *[_id == 'generaltranslation.secrets']. Note: If you have multiple datasets, you'll have to do this across all of them.
If the document was found in your dataset(s), delete populateSecrets.js.
If you have concerns about this being exposed to authenticated users of your studio, you can control access to this path with role-based access control.
Usage
Add it as a plugin in sanity.config.ts (or .js):
import { defineConfig } from 'sanity';
import { gtPlugin } from 'gt-sanity';
export default defineConfig({
//...
plugins: [
gtPlugin({
sourceLocale: 'en',
// Specify your locales here
locales: ['es', 'fr'],
}),
],
});Add the Translation View to your document structure:
// ./structure.ts
import type { DefaultDocumentNodeResolver } from 'sanity/structure';
import { TranslationsTab } from 'gt-sanity';
import { defaultDocumentLevelConfig } from 'gt-sanity';
export const defaultDocumentNode: DefaultDocumentNodeResolver = (
S,
{ schemaType }
) => {
// Replace 'translatable' with your schema type(s)
if (schemaType === 'translatable') {
return S.document().views([
S.view.form(),
S.view
.component(TranslationsTab)
.title('General Translation')
.options(defaultDocumentLevelConfig),
]);
}
};License
FSL-1.1-ALv2 © General Translation, Inc.
Develop & test
This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.
See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.
