IT-PYX

payload auto translate

by IT-PYX
Translation
v3
^3.0.0
MIT

Overview

Summary generated from the README

Translates content from a source locale into target locales in the background whenever documents are created or updated. It keeps the Lexical rich text structure intact and can generate localized SEO slugs. It requires Payload 3.x, PostgreSQL via the Postgres adapter and a LibreTranslate server. A standalone CLI crawler backfills existing PostgreSQL data.

Features

  • Background translation queue with debouncing and configurable concurrency on create and update
  • Preserves Lexical rich text structure while translating text nodes
  • Localized SEO slugs with umlaut expansion and protection of manually edited slugs
  • Smart merging of arrays and blocks that keeps human-edited content
  • CLI bulk crawler with dry run and table filters for backfilling PostgreSQL data
  • REST endpoints for status and bulk migration progress

Use cases

  • Translate new and edited pages into several languages without manual copying
  • Backfill translations for a large existing catalog stored in PostgreSQL
  • Generate localized URL slugs for multi-language sites

From the author

High-performance auto-translation plugin for Payload CMS 3.x with LibreTranslate, Lexical Rich Text AST compression, debounced background worker queue, SEO slugification, and direct PostgreSQL bulk crawler.

Installation

npm i @itpyx/payload-auto-translate

2

Stars

0

Forks

0

Open Issues

1 months ago

Last Updated

48

Weekly Downloads

v1.3.3

npm Version

428.3 KB

Unpacked Size

2

Dependencies

GitHub stars

2+2 since Oct 4

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20262
Dec 5, 20262
Dec 4, 20262
Dec 3, 20262
Dec 2, 20262
Dec 1, 20262
Nov 30, 20262
Nov 29, 20262
Nov 28, 20262
Nov 27, 20262
Nov 26, 20262
Nov 25, 20262
Nov 24, 20262
Nov 23, 20262
Nov 22, 20262
Nov 21, 20262
Nov 20, 20262
Nov 19, 20262
Nov 18, 20262
Nov 17, 20262
Nov 16, 20262
Nov 15, 20262
Nov 14, 20262
Nov 13, 20262
Nov 12, 20262
Nov 11, 20262
Nov 10, 20262
Nov 9, 20262
Nov 8, 20262
Nov 7, 20262
Nov 6, 20262
Nov 5, 20262
Nov 4, 20262
Nov 3, 20262
Nov 2, 20262
Nov 1, 20262
Oct 31, 20262
Oct 30, 20262
Oct 29, 20262
Oct 28, 20262
Oct 27, 20262
Oct 26, 20262
Oct 25, 20262
Oct 24, 20262
Oct 23, 20262
Oct 22, 20262
Oct 21, 20262
Oct 20, 20262
Oct 19, 20262
Oct 18, 20262
Oct 17, 20262
Oct 16, 20262
Oct 15, 20262
Oct 14, 20262
Oct 13, 20262
Oct 12, 20262
Oct 11, 20262
Oct 10, 20262
Oct 9, 20262
Oct 8, 20262
Oct 7, 20262
Oct 6, 20262
Oct 5, 20262
Oct 4, 20260
npm weekly downloads

42−260 since Oct 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202642
Dec 5, 202640
Dec 4, 202644
Dec 3, 202662
Dec 2, 202660
Dec 1, 202647
Nov 30, 202642
Nov 29, 202638
Nov 28, 202638
Nov 27, 202651
Nov 26, 202647
Nov 25, 202655
Nov 24, 202664
Nov 23, 202667
Nov 22, 202668
Nov 21, 202684
Nov 20, 202688
Nov 19, 202687
Nov 18, 2026109
Nov 17, 2026156
Nov 16, 2026182
Nov 15, 2026206
Nov 14, 2026242
Nov 13, 2026826
Nov 12, 2026831
Nov 11, 2026806
Nov 10, 2026772
Nov 9, 2026749
Nov 8, 2026752
Nov 7, 20261,006
Nov 6, 2026400
Nov 5, 2026383
Nov 4, 2026374
Nov 3, 2026358
Nov 2, 2026355
Nov 1, 2026331
Oct 31, 202638
Oct 30, 202645
Oct 29, 202643
Oct 28, 202642
Oct 27, 202647
Oct 26, 202655
Oct 25, 202660
Oct 24, 202673
Oct 23, 202666
Oct 22, 202674
Oct 21, 202695
Oct 20, 202696
Oct 19, 2026121
Oct 18, 2026277
Oct 17, 2026272
Oct 16, 2026336
Oct 15, 2026638
Oct 14, 2026975
Oct 13, 20261,263
Oct 12, 20261,225
Oct 11, 20261,058
Oct 10, 20261,034
Oct 9, 2026970
Oct 8, 2026660
Oct 7, 2026302

Each point is npm's rolling 7-day download count.

Health Score

63/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1404441092-root.svg)](https://payloaddirectory.dev/plugins/1404441092-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1404441092-root"><img src="https://payloaddirectory.dev/badge/1404441092-root.svg" alt="Payload Directory"></a>
Updated Nov 4, 2026Created Oct 4, 2026Published Nov 4, 2026

README

payload-auto-translate

npm version License: MIT Payload CMS 3.x TypeScript


High-performance automated multi-language translation plugin for Payload CMS 3.x

Real-time background sync, Lexical Rich Text AST preservation, SEO slugification, and high-speed PostgreSQL bulk database crawler powered by LibreTranslate.


Overview

Payload CMS provides an excellent schema localization engine (localized: true), but it does not translate content out of the box—editors typically have to duplicate and translate content by hand.

@itpyx/payload-auto-translate automates the entire localization lifecycle:

  1. Real-Time Active Sync: Whenever an editor creates or edits content in the source locale (e.g., English), background workers automatically translate all target locales with debouncing.
  2. SEO-Grade Slug Localization: Automatically generates clean URL slugs (inverter-split-ac -> climatiseur-split-inverter in French, aire-acondicionado-split-inverter in Spanish) with German umlaut expansion and non-Latin character safety.
  3. Smart Array & Block Merging: Intelligently preserves existing human-edited blocks, updates modified copy, and appends newly added blocks without mashing mismatched blockTypes.
  4. Lexical Rich Text AST Preservation: Traverses Lexical JSON text leaves while keeping headings, links, tables, and custom blocks structurally intact.
  5. Direct PostgreSQL Bulk Crawler: Includes a standalone CLI tool that crawls PostgreSQL tables directly, backfilling millions of words across existing websites in minutes with zero API overhead.

📖 Full Guide: For a complete walkthrough of configuring environment variables, Next.js transpilation, CLI backfill, and production Docker setups, see the Comprehensive Integration Guide.


Requirements

  • Payload CMS: ^3.0.0
  • Database: PostgreSQL (via @payloadcms/db-postgres)
  • Node.js: >=18.20.0 or >=20.9.0
  • LibreTranslate: Self-hosted or dedicated LibreTranslate instance

Installation

pnpm add @itpyx/payload-auto-translate pg dotenv
# or
npm install @itpyx/payload-auto-translate pg dotenv
# or
yarn add @itpyx/payload-auto-translate pg dotenv

Quickstart

1. Register Plugin in payload.config.ts

import { buildConfig } from 'payload'
import { postgresAdapter } from '@payloadcms/db-postgres'
import { autoTranslatePlugin } from '@itpyx/payload-auto-translate'

export default buildConfig({
  localization: {
    locales: [
      { label: 'English', code: 'en' },
      { label: 'Español', code: 'es' },
      { label: 'Français', code: 'fr' },
      { label: 'Deutsch', code: 'de' },
      { label: 'العربية', code: 'ar' },
      { label: '日本語', code: 'ja' },
    ],
    defaultLocale: 'en',
    fallback: true,
  },
  db: postgresAdapter({
    pool: { connectionString: process.env.DATABASE_URL },
  }),
  plugins: [
    autoTranslatePlugin({
      engine: {
        url: process.env.LIBRETRANSLATE_URL || 'http://127.0.0.1:5000',
        apiKey: process.env.LIBRETRANSLATE_API_KEY,
      },
      sourceLocale: 'en',
      targetLocales: ['es', 'fr', 'de', 'ar', 'ja'],
      activeTranslation: {
        enabled: true,
        concurrency: 2,
        triggerOn: ['create', 'update'],
        translateDrafts: true, // Preserves draft status in collections with versions
      },
      // Optional: Automatic SEO slug translation
      slug: {
        enabled: true,         // Enable automatic translated slugs
        latinLocalesOnly: true // Preserves clean ASCII slugs for non-Latin (ar, ja)
      },
      // Optional: Configure specific collections
      collections: {
        pages: true,
        blog: {
          translateSlug: true,
          excludedFields: ['authorNotes', 'internalReview'],
        },
      },
    }),
  ],
})

2. Configure Environment Variables

Add to your .env:

LIBRETRANSLATE_URL=http://your-vps-ip:5000
LIBRETRANSLATE_API_KEY=your_optional_api_key

3. Next.js App Router (Payload 3.x)

If your CMS runs within Next.js, add the package to transpilePackages in next.config.mjs:

/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['@itpyx/payload-auto-translate'],
}
export default nextConfig

Configuration Reference

autoTranslatePlugin(options)

OptionTypeDefaultDescription
engine.urlstringprocess.env.LIBRETRANSLATE_URL || 'http://127.0.0.1:5000'Base URL of your LibreTranslate instance.
engine.apiKeystringprocess.env.LIBRETRANSLATE_API_KEYOptional API key if your LibreTranslate server requires authentication.
sourceLocalestringPayload defaultLocale || 'en'The master locale from which translations are generated.
targetLocalesstring[]All other configured localesArray of target language codes to translate into.
activeTranslation.enabledbooleantrueEnables real-time background translation on editorial save.
activeTranslation.concurrencynumber2Number of concurrent documents processed in the queue.
activeTranslation.triggerOn('create' | 'update')[]['create', 'update']Operations that trigger background translation.
activeTranslation.translateDraftsbooleantrueTranslates drafts without prematurely publishing them.
slug.enabledbooleanfalseEnable automatic SEO slug generation for localized documents.
slug.latinLocalesOnlybooleantrueIf true, only translates slugs for Latin locales (es, fr, de, it, pt) and preserves ASCII slugs for non-Latin (ar, ru, ja).
slug.sourceFieldstring'title'Field to derive slug from (falls back to 'name').
slug.slugifyfunctionBuilt-in SEO slugifierCustom function: (title, locale, currentSlug) => string.
customFieldExclusionsstring[][]Field names to exclude from translation globally.
customValueExclusionsstring[][]Specific text strings to skip during translation globally.
customValuePatterns(string | RegExp)[][]Custom regex patterns or strings to skip during translation (e.g. hardware specs like [/^IP\d+/, /^RS-?485/i]).
fallbackRetryFallbackRetryOptions{ enabled: false }Optional fallback retry for strings returning untranslated (e.g., Title Cased headlines).
collectionsRecord<string, boolean | CollectionConfigOptions>Auto-detectedSelectively enable, exclude fields, or toggle slug translation per collection.
globalsRecord<string, boolean | CollectionConfigOptions>Auto-detectedSelectively enable or exclude fields per global.
disabledbooleanfalseMaster kill-switch to temporarily disable the plugin.

Slug Translation Features

When slug.enabled: true is set (or translateSlug: true on a specific collection):

  1. German Umlaut Expansion: Automatically maps ä -> ae, ö -> oe, ü -> ue, ß -> ss (e.g. Lüftungstechnik Köln -> lueftungstechnik-koeln).
  2. Accents & Diacritics: Automatically strips accents across French, Spanish, Italian, and Portuguese (Climatisation Écologique -> climatisation-ecologique).
  3. Non-Latin Protection: When latinLocalesOnly: true (default), non-Latin languages (ar, ja, ru, zh) safely preserve the base ASCII slug, avoiding broken percent-encoded URLs (%D8%A7%D9%84%D...). When set to false, clean Unicode characters are preserved.
  4. Human Edit Protection: Only generates a translated slug if the target slug is empty or identical to the default source English slug. Manually customized slugs are never overwritten.

Bulk Database Crawler (CLI)

For initial migrations, importing large catalogs, or translating existing records, use the standalone Database Crawler. It connects directly to PostgreSQL via raw SQL, inspects all tables with a _locale column, and populates missing target rows in high-speed parallel batches.

CLI Usage

# 1. Dry run (inspect translatable tables and strings without writing to the database):
pnpm payload-auto-translate

# 2. Live migration (writes translated records directly to PostgreSQL):
pnpm payload-auto-translate --live

# 3. Limit translation to specific tables:
pnpm payload-auto-translate --live --tables=pages,products

# 4. Enable fallback retry for Title Case / Headline echoes:
pnpm payload-auto-translate --live --fallback-retry --fallback-strategy=sentence-case

# 5. Skip domain-specific tokens or hardware specs via patterns:
pnpm payload-auto-translate --live --value-patterns="/^IP\d+$/i,/^RS-?485$/i"

# 6. Custom .env file path:
pnpm payload-auto-translate --live --env=/path/to/.env

Add helper scripts to your CMS package.json:

{
  "scripts": {
    "translate:dry": "payload-auto-translate",
    "translate:bulk": "payload-auto-translate --live"
  }
}

Built-in REST Endpoints

The plugin exposes secure, authenticated endpoints under your Payload API router:

  • GET /api/auto-translate/status: Returns LibreTranslate connectivity, supported language codes, active queue stats, and bulk crawler progress.
  • POST /api/auto-translate/start-bulk: Asynchronously triggers a bulk migration across all localized tables.
  • GET /api/auto-translate/bulk-progress: Polls live migration progress (tables processed, total strings, translated strings, inserted/updated counts).

Self-Hosting LibreTranslate (Docker)

To run your own free, unlimited translation instance on your server using Docker:

docker run -d \
  --name libretranslate \
  -p 5000:5000 \
  --restart unless-stopped \
  libretranslate/libretranslate:latest \
  --load-only en,es,fr,de,ar,pt,ru,ja

License

MIT License. Copyright (c) 2026 IT-PYX.

Similar plugins