c-3po
This project was formely named
c-3po
and later on renamed tottag
. Some of the talks, presentations, and documentation may still reference it by the old name. All new features will be applied tottag
package, the oldc-3po
packages will be supported only with bugfixes. Follow this simple migration guide
Please refer to the new doc https://ttag.js.org
Modern javascript i18n localization library based on ES6 tagged templates and the good old GNU gettext
Key features
- Uses ES6 template literals
for string formatting (no need for
sprintf
). - It can precompile translations on a build step.
- Support for plurals with
ngettext
- Standard gettext contexts supported
- Uses a babel plugin to extract and resolve translations, works with modern javascript AST.
- It can be integrated in any build tool that works with babel.
- Has options for both efficient development and production setups.
- Has a built-in validation for translated strings format.
- It can use any default locale in sources (not only English).
- Handles React (jsx) translations.
Live example https://jsfiddle.net/0atw0hgh/
Tools:
The whole solution consists of 2 parts:
- ttag library - https://github.com/ttag-org/ttag
- ttag babel plugin - https://github.com/ttag/babel-plugin-ttag
How it looks like in the code:
Here is a usage of some ttag functions:
import { t, nt, ngettext, msgid } from 'ttag'
// simple string literals
const hello = t`Hello ttag`;
// formatted strings
const name = 'Mike';
const helloMike = t`Hello ${name}`;
// plurals (works for default locale out of the box)
const n = 5;
const msg = ngettext(msgid`${ n } task left`, `${ n } tasks left`, n)
The ttag
library aims to provide the most natural and reliable way to translate strings in JavaScript sources. It
provides some helper functions (tags) for making JavaScript templates as translatable with all their shiny
features like string interpolation, multiline etc.