thompsonsj / payload-crowdin-sync

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

feat(plugin): add ability to define a condition to globals/collections #143

Closed thompsonsj closed 10 months ago

thompsonsj commented 10 months ago

Add the ability to configure a collection to only translate documents through Crowdin that meet a condition based on the document data.

Includes:

Example

Add a checkbox field within your Payload CMS config such as:

{
  name: "translateWithCrowdin",
  type: "checkbox",
}

In your config, dictate that Crowdin translation should only occur if this checkbox is checked.

collections: [
  {
    slug: 'posts',
    condition: ({ doc }) => doc.translateWithCrowdin,
  },
]

Crowdin logic is run in an afterChange hook. The doc parameter is what is passed to this condition.