thompsonsj / payload-crowdin-sync

Upload and sync localized fields from the default locale to Crowdin.
7 stars 6 forks source link

Duplicated documents upload to the same folder #201

Open thompsonsj opened 1 month ago

thompsonsj commented 1 month ago

Consider how to resolve the issue of duplicated localized documents uploading to the same folder on Crowdin.

This is resolved in your Payload installation by adding an appropriate logic in a beforeDuplicate hook:

const beforeDuplicate: BeforeDuplicate<LandingPage> = ({ data }) => {
  return {
    ...data,
    // prevent this landing page from localizing to the same folder on Crowdin
    ...(data.crowdinArticleDirectory && {
      crowdinArticleDirectory: null,
    })
  }
}

Expecting the user to modify their configuration is not ideal. I can currently think of two better possibilities:

This could be resolved if we move to a version of this plugin that doesn't modify the original document (i.e. we store data in our own collections - we don't modify existing documents by adding a crowdinArticleDirectory relationship field). In this case, CrowdinArticleDirectorydocuments will link to a specific document. When duplicated, a document will have a new id so this will no longer be an issue.