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-ttagVerified import paths — ran on the pinned version, not inferred.
Installation, basic usage with t and ngettext, plus extraction and compilation commands.
Update package references and configuration to use 'babel-plugin-ttag' and ensure the runtime package 'ttag' is installed.
Use 'babel-plugin-ttag' instead of 'c-3po' in your Babel configuration.
Use the default 't' tag or configure custom tags via plugin options (e.g., { functions: ['t', 'myTag'] }).Convert .po files to JSON using 'npx ttag po2json translations.po -o translations.json' before passing to the plugin.
Run 'npm install --save ttag' to install the runtime dependency.
Run 'npm install --save-dev babel-plugin-ttag' and ensure your Babel config is correct.
Add 'babel-plugin-ttag' to your Babel plugins array and ensure Babel is processing the file.