Registry / devops / babel-gettext-plugin

babel-gettext-plugin

JSON →
library3.0.0jsnpmunverified

A Babel plugin (v3.0.0) that extracts gettext translation strings (msgid, msgctxt, etc.) from JavaScript files, supporting JSX, ES6, and other syntax via Babel. Built on node-gettext. It replaces older extractors like xgettext which lack modern syntax support. Maintenance is sparse; last release 2019.

npm install babel-gettext-plugin
INSTALL
IMPORT
SIG · BABEL-GETTEXT-PLUG
B
babel-gettext-plugin
devopsjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel
const babel = require('babel'); babel.transform(code, { plugins: ['babel-gettext-plugin'] })
import babel from 'babel'; // ESM import not supported; Babel 7's API is CJS
Plugin is used via Babel's transform API; not imported directly. Must be required in CommonJS context.
plugin config
plugins: [['babel-gettext-plugin', { headers: {}, functionNames: {} }]]
plugins: ['babel-gettext-plugin', { headers: {} }] // wrong: array nesting
Options must be passed as the second element of an array, not as separate arguments.
CLI usage
babel --plugins babel-gettext-plugin input.js -o output.js
babel --plugin babel-gettext-plugin code.js // wrong: '--plugin' should be '--plugins'
Use --plugins, not --plugin. Options can be appended with colon, e.g. --plugins babel-gettext-plugin:{"fileName":"test.po"}

Demonstrates plugin setup with Babel 7, custom function names for extraction, and .pot file output.

const babel = require('@babel/core'); const code = ` const _ = require('gettext'); const msg = _('Hello world'); console.log(_('Goodbye', 'context')); `; babel.transform(code, { plugins: [ ['babel-gettext-plugin', { headers: { 'content-type': 'text/plain; charset=UTF-8', 'plural-forms': 'nplurals=2; plural=(n!=1);' }, functionNames: { mygettext: ['msgid'], myngettext: ['msgid', 'msgid_plural', 'count'] }, fileName: './locales/messages.pot', defaultTranslate: false }] ] }).then(result => { console.log('Extraction complete, check .pot file.'); }).catch(err => console.error(err));
Debug
Known issues
breakingPlugin requires Babel 7; incompatible with Babel 6 or older. Use v2.x for Babel 6.
fix
Install babel-gettext-plugin@2.x for Babel 6 projects.
affects: >=3.0.0
deprecatedLast release in 2019; no updates for newer Babel versions (8.x) or modern ECMAScript features.
fix
Consider alternatives like 'babel-plugin-gettext-extractor' or manual extraction with xgettext.
affects: <3.0.0
gotchaPlugin does not support parsing dynamic strings or template literals; only string literals extracted.
fix
Ensure all your translatable strings are string literals, e.g., _('Hello') not _(textVar).
affects: *
gotchaOutput encoding: Generated .po/.pot files may have incorrect charset if headers not provided; default is UTF-8.
fix
Always specify headers with 'content-type' charset to avoid encoding issues.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'babel'
Incorrect Babel package: babel 6 vs @babel/core 7 naming.
fix
Use '@babel/core' instead of 'babel': npm install @babel/core and const babel = require('@babel/core');
TypeError: Cannot read property 'traverse' of undefined
Plugin used with Babel 6 but installed v3.0.0 (requires Babel 7).
fix
Install v2.x: npm install babel-gettext-plugin@2.x --save-dev
Warning: No strings extracted.
Plugin cannot find gettext call syntax (default function name '_'). No custom functionNames set.
fix
Define functionNames matching your gettext wrapper names, e.g., 'mygettext': ['msgid']
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
babelrequiredRequires Babel 7 to transform code and apply the plugin
node-gettextrequiredCore library used for gettext parsing and .po file generation
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
babel-gettext-plugin — npm install babel-gettext-plugin · libregistry