ttag

ttag

  • Docs
  • Blog
  • Github

›Tags and Functions

Getting Started

  • Installation
  • Quick start
  • Webpack integration
  • Typescript
  • Create React App
  • Gatsby
  • Next

Tags and Functions

  • t (gettext tag)
  • jt (jsx gettext)
  • c (context)
  • ngettext (plurals)
  • gettext

Features

  • Translations validation
  • Aliasing
  • Multiline strings
  • Comments for translators
  • Ignoring code blocks

API

  • ttag API
  • babel-plugin-ttag API

CHANGELOG

  • Changelog

gettext

Consider using the t function (less code, supports template expressions)

The default alias for gettext function is _.

Usage

import { gettext } from 'ttag';

gettext('simple gettext');

or

import { _ } from 'ttag';

_('simple gettext');

Try

https://jsfiddle.net/AlexMost/us7hufjr/3/

Format

Valid

gettext('simple gettext');

Invalid

gettext(`template literal`); // template literals are not supported
gettext('one', 'two'); // gettext supports only 1 argument

Extract

All translations can be extracted to .po file with ttag-cli tool.

import { gettext } from 'ttag';

gettext('Hello');

will be extracted to this:

msgid "Hello"
msgstr ""

Resolve

Suppose we have translated phrase in .po:

msgctxt "email"
msgid "Hello"
msgstr "Вітаємо"

The result js for uk locale will be

gettext('Вітаємо').
← ngettext (plurals)Translations validation →
  • Usage
  • Try
  • Format
    • Valid
    • Invalid
  • Extract
  • Resolve
ttag
Docs
Quick Startttag APIbabel-plugin-ttag API
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHubStar
Copyright © 2024 ttag