Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

translate-text

andrepolischuk475MIT0.4.1

Translate function with templates precompiling and helpers

translate, translator, i18n, intl, internationalization

readme

translate-text Build Status

Translate function with templates precompiling and helpers

Install

npm install --save translate-text

Usage

import createTranslate from 'translate-text'
import pluralize from 'numd'

const translation = {
  hello: 'Hello',
  echo: 'You say: $1',
  more: {
    age: 'I\'m a (pluralize $1|year|years) old'
  },
  greeting: 'I\m $name and I\'m (pluralize $age|year|years) old'
}

const translate = createTranslate(translation, {pluralize})

translate('hello') // Hello
translate('echo', 'Foo') // You say: Foo
translate('more.age', 25) // I'm a 25 years old
translate('greeting', {
  name: 'John Smith',
  age: 25
}) // I'm John Smith and I'm 25 years old

API

createTranslate(translation[, helpers])

Compile templates and return translate function.

translation

Type: object

Translation templates.

helpers

Type: object

Helper functions that are used in templates.

translate(key[, ...args])

key

Type: string

Template key.

args

Type: ...any

Arguments to insert into the template.

License

MIT