0.25.0 • Published 3 months ago

payload-crowdin-sync v0.25.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Payload Crowdin Sync Plugin

Automatically upload/sync localized fields from the default locale to Crowdin. Make these fields read-only in other locales and update them using Crowdin translations.

Note: This plugin is still in development. A todo list is maintained at docs/development.md.

Requirements

  • Payload version 1.0.19 or higher is required

Usage

#npm
npm install payload-crowdin-sync

# yarn
yarn add payload-crowdin-sync

Add the plugin to your Payload configuration.

import { crowdinSync } from "payload-crowdin-sync";

export default buildConfig({
  plugins: [
    crowdinSync({
      projectId: 323731,
      token: process.env.CROWDIN_TOKEN,
      localeMap: {
        de_DE: {
          crowdinId: "de",
        },
        fr_FR: {
          crowdinId: "fr",
        },
      },
      sourceLocale: "en",
    }),
  ],
  // The rest of your config goes here
});

Options

Required

OptionExampleDescription
projectId323731Your Crowdin project ID.
localeMap{ de_DE: { crowdinId: "de" } }Map your Payload locales to Crowdin locale ids.
sourceLocaleenThe Payload locale that syncs to source translations (files) on Crowdin.

Optional

OptionExampleDescription
tokenxxxxxxxYour Crowdin API token. If empty, changes to files are disabled.
directoryId1169Crowdin directory ID to store translations. To get the directory ID without making an API call, inspect the page source of your folder in Sources > Files.
collectionsundefined[]['posts', 'categories']['posts', { slug: 'categories', condition: ({doc}) => doc.translateWithCrowdin]Define an array of collection slugs for which the plugin is active.If undefined, the plugin will detect localized fields on all collections.Use an empty array to disable all collections.Use an object to define a condition that activates Crowdin based on the document data.
globalsundefined[]['nav'][{ slug: 'nav', condition: ({doc}) => doc.translateWithCrowdin]Define an array of global slugs for which the plugin is active.If undefined, the plugin will detect localized fields on all globals.Use an empty array to disable all globals.Use an object to define a condition that activates Crowdin based on the document data.
slateToHtmlConfigundefinedPass a custom config for the slateToHtml serializer used to convert Payload CMS Slate JSON to HTML for Crowdin translation. See Serializer configuration.
htmlToSlateConfigundefinedPass a custom config for the htmlToSlate serializer used to conver HTML to Payload CMS Slate JSON when retrieving Crowdin translation. See Serializer configuration.
pluginCollectionAccessundefinedaccess collection config to pass to all the Crowdin collections created by this plugin.
pluginCollectionAdminundefined{ hidden: ({ user }) => !userIsAdmin({ user }) }admin collection config to pass to all the Crowdin collections created by this plugin.
tabbedUIundefinedtrueAppends Crowdin tab onto your config using Payload's Tabs Field. If your collection is not already tab-enabled, meaning the first field in your config is not of type tabs, then one will be created for you called Content.

Environment variables

Set PAYLOAD_CROWDIN_SYNC_ALWAYS_UPDATE=true to update all localized fields in Crowdin when an article is created/updated.

By default, updates will only be sent to Crowdin in the following scenarios.

  • At least one of the localized text fields has changed: any change to a localized text field updates the compiled fields.json that is sent to Crowdin.
  • A richText field is changed. Individual richText fields will only be updated on Crowdin if the content has changed - each field has its own file on Crowdin.

It is useful to have a convenient way of forcing all localized fields to update at once. For example, if the plugin is activated on an existing install, it is convenient to trigger all updates on Crowdin for a given article without having to change every richText field or one of the text fields.

Details

Sync translations

Translation synchronisation refers to the process of loading translations from Crowdin into Payload CMS. If drafts are enabled, this will create a new version in Payload CMS for each locale. The source locale (e.g. en) is not affected.

A UI has not been developed for this feature yet. To perform updates now, use custom REST API endpoints that are made available by this plugin.

If supplied translations do not contain required fields, translation updates will not be applied and validation errors will be returned in the API response.

Sync global translations

To sync global translations, add a new article in Crowdin Translations that contains the global slug. Each article contains an excludeLocales field that can be used to prevent some locales from being included in the update operation.

Dry run

To review translations, visit:

<payload-base-url>/api/crowdin-article-directories/<article-id>/review

e.g. https://my-payload-app.com/api/crowdin-article-directories/64a880bb87ef685285a4d9dc/update

A JSON object is returned that allows you to review what will be updated in the database. The JSON object will contain the following keys:

  • draft indicates that on update, a draft will be created rather than a published version. See Drafts | Payload CMS.
  • source review the source document. e.g. for the en locale.
  • translations
    • <locale> e.g. es_ES
      • currentTranslations all current localized fields and values.
      • currentTranslations localized fields populated with values from Crowdin.
      • changed boolean to indicate whether any changes have been made in Crowdin.

Update

To update translations, visit:

<payload-base-url>/api/crowdin-article-directories/<article-id>/review

e.g. https://my-payload-app.com/api/crowdin-article-directories/64a880bb87ef685285a4d9dc/update

Pass the draft=true query parameter to update as a draft rather than a published version.

The document will be updated and the same report will be generated as for a review.

0.25.0

3 months ago

0.24.3

4 months ago

0.24.2

4 months ago

0.24.1

5 months ago

0.24.0

5 months ago

0.23.0

5 months ago

0.22.1

5 months ago

0.22.0

5 months ago

0.20.0

5 months ago

0.19.0

6 months ago

0.18.1

6 months ago

0.17.0

7 months ago

0.18.0

6 months ago

0.16.0

8 months ago

0.16.2

8 months ago

0.11.0

10 months ago

0.13.0

10 months ago

0.12.1

10 months ago

0.14.0

9 months ago

0.13.1

10 months ago

0.15.0

9 months ago

0.13.2

9 months ago

0.13.3

9 months ago

0.10.0

10 months ago

0.3.0

12 months ago

0.2.1

12 months ago

0.2.0

12 months ago

0.9.0

11 months ago

0.8.1

11 months ago

0.8.0

11 months ago

0.7.1

11 months ago

0.9.1

10 months ago

0.8.2

11 months ago

0.5.0

11 months ago

0.4.1

12 months ago

0.2.3

12 months ago

0.4.0

12 months ago

0.2.2

12 months ago

0.7.0

11 months ago

0.5.2

11 months ago

0.2.5

12 months ago

0.6.0

11 months ago

0.5.1

11 months ago

0.2.4

12 months ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago