0.0.5 • Published 5 years ago

inno-trans-react-element-plugin v0.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

inno-trans-react-element-plugin

inno-trans plugin for react element interpolation.

npm

Install

npm i inno-trans-react-element-plugin
const InnoTrans = require('inno-trans')
const InnoTransReactElementPlugin = require('inno-trans-react-element-plugin')

InnoTrans.use(InnoTransReactElementPlugin) // install plugin.

Example

const t = InnoTrans({
    locale: 'en',
    messages: {
        en: {
            welcome: '<wrap>welcome<0/>to {name}</wrap>'
        }
    }
})

function App(){
    return t.rt('welcome', {wrap: <p className='a' />, 0: <br/>, name: 'my world'})
}

ReactDOM.render(<App />, document.getElementById('app'))

output:

<div id="app">
    <p class='a'>welcome<br />to my world</p>
</div>

API

t.rt(key [, values , options])

Returns a message that matches the key. with react element interpolation.

// 'hello' : '<0>hello<1 />{name}!!</0>'

t.rt('hello', {0: <div className='abc' />, 1: <br/>, name: 'byungi!'})

// => <div class='abc'>hello<br/>byungi!!</div>

t.rtc(key, number [, values , options])

Returns a message that matches the key and the quantity number. with react element interpolation.

// 'apple' : '<0>an apple</0>|<0>apples</0>'

t.rtc('apple', 10, {0: <div className='abc' />})

// => <div class='abc'>apples</div>

Related

  • inno-trans - simple localization library (inspired by laravel translation)
  • tag-name-parser - A tag name parser that does not support attributes. Lightweight and fast when only need tag names.

License

MIT