@vimeo/babel-plugin-transform-i18n

1.0.1 • Public • Published

babel-plugin-transform-i18n Build Status Coverage npm Gitter

A Babel transform plugin to replace strings with their translations.

Example

.babelrc

{
    "plugins": [
        ["transform-i18n", {
            "dictionary": {
                "Hello": "Bonjour",
                "Hello, {name}!": "Bonjour, {name}!"
            }
        }]
    ]
}

In

const name = 'Brad';
const hello = t('Hello');
const helloWithName = t('Hello, {name}!', {
    name
})

Out

const name = 'Brad';
const hello = 'Bonjour';
const helloWithName = 'Bonjour, ' + name + '!';

Installation

npm install babel-plugin-transform-i18n

Usage

Via .babelrc

{
    "plugins": [
        ["transform-i18n", {
            "functionName": "t",
            "dictionary": {}
        }]
    ]
}

Via Node API

require('babel-core').transform('code', {
    plugins: [
        ['transform-i18n', {
            functionName: 't',
            dictionary: {}
        }]
    ]
});

Options

There are two options available, both are optional:

dictionary

A mapping of the strings passed to the translation function to their translated versions. If no dictionary is passed, calls to the translation function will be replaced with the original string.

functionName

The name of the function that wraps the strings. Defaults to t.

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i @vimeo/babel-plugin-transform-i18n

    Weekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    9.32 kB

    Total Files

    25

    Last publish

    Collaborators

    • rowankrishnan
    • cxiang
    • tylerthegrove
    • vimeo-npmbot