Skip to content

Translate function with templates precompiling and helpers

License

Notifications You must be signed in to change notification settings

andrepolischuk/translate-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Translate function with templates precompiling and helpers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published