1.2.0 • Published 9 months ago

@skyscanner/babel-plugin-skyscanner-i18n v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

A Babel transform plugin to replace strings with their translations.

Example

.babelrc

{
    "plugins": [
        ["skyscanner-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 i -D babel-plugin-skyscanner-i18n

Usage

Via .babelrc

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

Via Node API

require('babel-core').transform('code', {
    plugins: [
        ['skyscanner-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.

leftDelimiter, rightDelimiter

The delimiter to be used for templating. Defaults to { }.

delimiter

Shorthand for when both leftDelimiter and rightDelimiter are the same. Example: @@

1.2.0

9 months ago

1.2.0-beta.0

9 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.3.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago