Issues with publishing and deleting documents using Sanity's Document Internationalization Plugin

8 replies
Last updated: Nov 7, 2022
Hi all! I’m having trouble with the Document Internationalization Plugin. When I create translations from an unpublished base document, I can no longer publish or delete the base document. The translated document can be published as per usual.
My company’s workflow is that our English and French pages need to be published at the same time. So we usually create and QA our pages in draft/unpublished mode until they get approved and then we publish.

The only workaround we have found is creating a duplicate of the base document (leaving the OG base document unpublished) but this is leaving us with a lot of documents that are stale and can’t be deleted. Looking for any advice on how to resolve this issue and any suggestions!

Here are some of errors that we have gotten:

When trying to publish the base document: 
An error occurred during publish Details Mutation(s) failed with 1 error(s)

When trying to delete the base document: 
An error occurred while attempting to delete this document. This usually means that there are other documents that refers to it. ClientError: Mutation(s) failed with 1 error(s)
Thank you!
AI Update

I understand you're experiencing a frustrating issue with the Document Internationalization plugin where creating translations from an unpublished base document prevents you from publishing or deleting that base document afterward. This is a known issue with how the plugin manages references between translation documents.

What's happening:

The plugin creates references between your base document and its translations through a separate translation.metadata document. When you create a translation from an unpublished base document, these references can prevent normal publish/delete operations because Sanity sees them as dependencies that need to be maintained.

The solution: Configure weak references

The key fix is to enable weakReferences in your plugin configuration. Add this to your sanity.config.ts:

documentInternationalization({
  supportedLanguages: [
    { id: "en", title: "English" },
    { id: "fr", title: "French" }
  ],
  schemaTypes: ['yourSchemaType'],
  weakReferences: true  // Add this line
})

Setting weakReferences: true tells the plugin to keep translation.metadata references weak, which allows you to publish and delete documents independently without Sanity blocking the operation due to reference constraints.

For your simultaneous publishing workflow:

Since you need to publish English and French pages at the same time, you have a couple of good options:

  1. If you're on a Growth plan or higher, Sanity Releases is purpose-built for exactly this use case. It lets you bundle multiple document changes (like your English and French pages) into a single release that can be previewed and published together atomically.

  2. If you're on a Team plan, you can use the Scheduling API's bulk publishing endpoint to publish both documents together in a coordinated way. You can even enable this in the plugin config with bulkPublish: true.

For existing documents:

If you already have documents created before adding weakReferences: true, you may need to republish both the base and translated documents to trigger the plugin to update the references properly. As noted in this GitHub issue comment, simply republishing both documents will trigger the "updating i18n fields" process, which appropriately updates the references to be weak.

Important note: The configuration option is weakReferences (not referenceBehavior as mentioned in some older discussions). This is the correct property name for the current version of the plugin.

This should resolve both your publishing and deletion issues while supporting your workflow requirement to publish both language versions simultaneously!

Hey Andrea! If you change your reference behavior in the plugin's config to
weak
, you'll be able to delete documents that have references to it. Note: you will have to run a mutation on existing data to add
_weak: true
to the fields, though.
Hi
user M
! Thanks for your help! I've had the reference behaviour set to weak since the beginning of the project 🤔 Here's my config file:
{
    "idStructure": "subpath",
    "referenceBehavior": "weak",
    "base": "en",
    "languages": ["en", "fr"]
}
I'm not sure I understand when you say to run a mutation. If there is any docs or resources that you could point me to that would be most appreciated!
Hmm, are there documents besides translations referencing the base document?
In terms of of mutations, there's some documentation on doing it
here (specifically patches). You can also do it with the JS client .
I don't think there are any other references. I've been debugging on a test base page and it works as expected until I try to add the translations.
Thank you for the docs!
This is an unfortunate quirk with the current plug-in, it writes references linking both docs meaning they need to both be published deleted in a single operation. Which the Delete action from the plug-in should be doing … if not you might want to create a new document action that can take the current id, it’s translations and delete them together.
Thanks
user T
for your response! Good to know there is some quirkiness. I will look into the document actions. Do you know if it would be possible to create a document action that would publish the docs at the same time? Or is only possible to delete?
Ah I misspoke above. I meant the plugin should provide an action that would delete them both in one mutation.
Unfortunately bulk “publishing” isn’t entirely supported either. A “publish” operation in the Studio is a few different actions (copying the draft contents to a new or existing published document and then deleting the draft). There’s the sanity react-hooks package that exposes a publish function, but it only takes a single document at a time.

There is a (relatively new) API endpoint for bulk publishing among the scheduled publishing API’s … and is available on Team plans or higher:

https://www.sanity.io/docs/scheduling-api#dcb47be520d0
Thanks for explaining,
user T
! Really helpful to have the context. We are actually using the scheduling API already so I will see if we can use it as a workaround. Thanks again!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?