项目作者: ttag-org

项目描述 :
:orange_book: simple approach for javascript localization
高级语言: JavaScript
项目地址: git://github.com/ttag-org/ttag.git
创建时间: 2017-01-11T21:26:37Z
项目社区:https://github.com/ttag-org/ttag

开源协议:MIT License

下载


Stand With Ukraine



ttag

Modern javascript i18n localization library based on ES6 tagged templates and the good old GNU gettext

travis codecov downloads

NPM


Key features

  • Uses ES6 template literals for string formatting (no need for sprintf).
  • Contexts support
  • It can precompile translations on a build step.
  • Plurals support ngettext.
  • It can be integrated in any build tool that works with babel.
  • Has a builtin validation for translated strings format.
  • It can use any default locale in sources (not only English).
  • Handles React (jsx) translations.
  • Can be easily integrated with Create React App. CRA doc

Usage example

  1. import { t, ngettext, msgid } from 'ttag';
  2. // formatted strings
  3. const name = 'Mike';
  4. const helloMike = t`Hello ${name}`;
  5. // plurals (works for en locale out of the box)
  6. const n = 5;
  7. const msg = ngettext(msgid`${n} task left`, `${n} tasks left`, n);

Installation

  1. npm install --save ttag

CLI

You may also need to install ttag-cli for po files manipulation.

ttag cli - https://github.com/ttag-org/ttag-cli

  1. npm install --save-dev ttag-cli

Usage from CDN

https://unpkg.com/ttag/dist/ttag.min.js

This project is designed to work in pair with babel-plugin-ttag.
But you can also play with it without transpilation.

Support

Give a ⭐️ if this project helped you!

Slides from talks

Talks

License

This project is licensed under the MIT license.