Back

gt-sanity@3.1.0

Fernando Aviles avatarFernando Aviles
gt-sanityv3.1.0sanitycmstranslationminor

Overview

Translated content rarely stays exactly as it arrives. Editors fix a term, tighten a headline, adjust the tone for a market — and until now, the next translation run regenerated all of it.

gt-sanity v3.1 adds Save local edits: the translations Sanity already holds are uploaded to General Translation before a translation run, so content whose source text has not changed keeps its existing wording. It is off by default and opt-in per Studio session.

The release also adds a Save Local Edits action for uploading existing translations without starting a run, and a Retranslate from scratch option for deliberately regenerating everything.


What's new

Save local edits

Switch on the Save local edits toggle in the Translations tool or the General Translation document tab. When enabled, each translation run starts by sending the translations currently in Sanity to General Translation. These become the stored translations for the source version, so the next run reuses them instead of translating that content again.

Both localisation strategies are supported: document-level translations are read through translation.metadata (preferring drafts over published documents, so unpublished edits count), and internationalised-array locale values are read from the source document. Locales with no existing content are skipped rather than uploaded as empty translations.

Set the toggle's initial state in your plugin config:

import { defineConfig } from 'sanity';
import { gtPlugin } from 'gt-sanity';

export default defineConfig({
  plugins: [
    gtPlugin({
      sourceLocale: 'en',
      locales: ['es', 'fr', 'ja'],
      translateDocuments: [{ type: 'post' }],
      preserveExistingTranslations: true,
    }),
  ],
});

preserveExistingTranslations initialises the toggle when the Studio loads. Editors can change it for their session in the UI.

Sanity becomes the source of truth

Turning the toggle on displays an explanation first, because the trade-off is real: what is in Sanity replaces whatever General Translation holds for that version of the document — including a translation that has finished but has not yet been imported. Import any pending translations before turning it on.

The capture step runs before the source upload and is best-effort. If it fails, the translation run still proceeds and the Studio warns that edits may be overwritten.

Save Local Edits

The Save Local Edits action uploads translations already in Sanity without queueing a translation, seeding source files as needed. Use it when adopting the plugin for a project previously translated elsewhere, so General Translation starts with the content you already have.

It is available in the Translations tool and on the document tab.

Retranslate from scratch

Translate All now includes a Retranslate from scratch tick box. Selecting it discards existing translations and regenerates them, including edits made to translated documents in the Studio. Leave it unticked to reuse existing translations.

The plugin previously provided no way to force retranslation.