0.4.1 • Published 3 years ago

translate-text v0.4.1

Weekly downloads
47
License
MIT
Repository
github
Last release
3 years ago

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.

Related

License

MIT

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago