Registry / devops / babel-plugin-ttag

babel-plugin-ttag

JSON →
library1.8.16jsnpmunverified

babel-plugin-ttag (formerly babel-plugin-c-3po) is a Babel plugin for extracting and resolving gettext-like translations at compile time. Current stable version is 1.8.16, released periodically. It uses ES6 tagged template literals (e.g., t`hello`), works with GNU gettext .po files, and offers compile-time resolution with no runtime overhead in the browser. Key differentiators: native template syntax (no sprintf), intelligent extraction by Babel, fast feedback loop (warns on missing translations), and support for universal apps (Node.js and browser). It includes support for plurals (ngettext/msgid), contexts (tct), and JSX without additional configuration. Requires ttag runtime package as a peer dependency.

npm install babel-plugin-ttag
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TTAG
B
babel-plugin-ttag
devopsjavascriptv1.8.16
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.

t
import { t } from 'ttag'
import t from 'ttag'
t is a named export, not default.
ngettext
import { ngettext, msgid } from 'ttag'
import { ngettext } from 'babel-plugin-ttag'
ngettext is from the runtime package 'ttag', not the plugin.
tct
import { tct } from 'ttag'
import tct from 'ttag'
tct is a named export for context translation.
BabelPluginTtag (plugin configuration)
{ plugins: ['babel-plugin-ttag'] }
{ plugins: ['ttag'] }
Plugin name must be exactly 'babel-plugin-ttag' in .babelrc or babel config.

Installation, basic usage with t and ngettext, plus extraction and compilation commands.

npm install --save-dev babel-plugin-ttag && npm install --save ttag // .babelrc { "plugins": ["babel-plugin-ttag"] } // src/index.js import { t, ngettext, msgid } from 'ttag'; const name = 'World'; console.log(t`Hello ${name}!`); const count = 5; console.log(ngettext(msgid`${count} item`, `${count} items`, count)); // Extract translations: npx ttag extract src/**/*.js -o translations.pot // Compile translations: npx ttag po2json translations.po -o translations.json // Then configure plugin to use translations: // "plugins": [["babel-plugin-ttag", { "translations": "translations.json" }]]
Debug
Known issues
breakingPrior to version 1.0, the package was named babel-plugin-c-3po. The API and configuration may differ. Existing code using 'babel-plugin-c-3po' will not work with 'babel-plugin-ttag' without adjustments.
fix
Update package references and configuration to use 'babel-plugin-ttag' and ensure the runtime package 'ttag' is installed.
affects: >=0.x <1.0
deprecatedUsage of 'c-3po' as a plugin name is deprecated and not supported in this version.
fix
Use 'babel-plugin-ttag' instead of 'c-3po' in your Babel configuration.
affects: >=1.0
gotchaThe plugin extracts tagged template literals with the tag 't' only. If you alias or rename the import, extraction may fail unless you configure custom tags.
fix
Use the default 't' tag or configure custom tags via plugin options (e.g., { functions: ['t', 'myTag'] }).
affects: >=1.0
gotchaTranslations file must be in JSON format (e.g., from 'ttag po2json'). Using .po or .pot directly will not work for runtime resolution.
fix
Convert .po files to JSON using 'npx ttag po2json translations.po -o translations.json' before passing to the plugin.
affects: >=1.0
Errors
Common errors & fixes
Error: Could not find module 'ttag'
The runtime package 'ttag' is not installed or not in node_modules.
fix
Run 'npm install --save ttag' to install the runtime dependency.
BabelError: Cannot find module 'babel-plugin-ttag' from ...
The plugin is not installed or Babel cannot resolve it.
fix
Run 'npm install --save-dev babel-plugin-ttag' and ensure your Babel config is correct.
SyntaxError: Unexpected token (or similar parsing error) when using template literal with translation
The template literal uses a tag function (e.g., t) but the plugin is not enabled or configured.
fix
Add 'babel-plugin-ttag' to your Babel plugins array and ensure Babel is processing the file.
Upgrade
Version history
1.8.16latest on npm
Audit
Dependencies
ttagrequiredRuntime library providing tagged template functions (t, ngettext, msgid, etc.) used in source code.
Agent activity
23 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
babel-plugin-ttag — npm install babel-plugin-ttag · libregistry