Rollup Plugin Drupal Interface Translations

raw JSON →
1.1.9 verified Mon Apr 27 auth: no javascript

A Rollup and Vite plugin that extracts Drupal interface translation strings from JavaScript files into .pot (Portable Object Template) files. Currently v1.1.9, stable, with periodic releases. Key differentiator: it integrates Drupal's translation API into modern JavaScript build pipelines, supporting both Rollup and Vite. Unlike manual extraction, it automates generation of translation templates from Drupal's t() and Drupal.t() calls. Based on DrupalTranslationsWebpackPlugin but adapted for Rollup ecosystem.

error TypeError: drupalInterfaceTranslations is not a function
cause Using require() on ESM-only package.
fix
Change to import drupalInterfaceTranslations from 'rollup-plugin-drupal-interface-translations'
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
cause Same as above, require() on ESM package.
fix
Use import syntax or upgrade Node to newer version with --experimental-require-module.
error The plugin is not compatible with Vite if placed in root plugins array
cause Plugin works as Rollup plugin and must be placed under build.rollupOptions.plugins in Vite config.
fix
Move plugin to build.rollupOptions.plugins array.
breaking Package is ESM-only. Using CommonJS require() will throw an error.
fix Use import or configure Node.js to use ESM (e.g., "type": "module" in package.json).
gotcha Must be added to Vite's rollupOptions.plugins, not root plugins array, or it won't execute correctly.
fix When using Vite, define plugin inside build.rollupOptions.plugins, not in the top-level plugins array.
deprecated No known deprecated features in current version.
npm install rollup-plugin-drupal-interface-translations
yarn add rollup-plugin-drupal-interface-translations
pnpm add rollup-plugin-drupal-interface-translations

Minimal Rollup configuration to extract Drupal interface translations from main.js, generating a .pot file in translations/ folder.

import drupalInterfaceTranslations from 'rollup-plugin-drupal-interface-translations';

// https://rollupjs.org/configuration-options/
export default {
  input: 'main.js',
  plugins: [drupalInterfaceTranslations()],
};