Skip to content

tiaanduplessis/langylanglang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

langylanglang

package version package downloads standard-readme compliant package license make a pull request

Localize your interface

Table of Contents

Usage

import { set, onMissingKey, t, locale, fallback } from './langylanglang'

set('en', {
  greeting: 'Hi {bar}! how are you?',
  info: 'Bye buddy!'
})

set('za', {
  greeting: 'Hi {bar}! Hoe gaan dit my bra?',
  info: 'Cheers tjom!'
})

// Can also set multiple
// set({
//   'en': {
//     greeting: 'Hi {bar}! how are you?',
//     info: 'Bye buddy!'
//   },
//   {
//     greeting: 'Hi {bar}! Hoe gaan dit my bra?',
//     info: 'Cheers tjom!'
//   }
// })

onMissingKey((...args) => {
  console.log('Got missing key', args)
  return ''
})

console.log(
  t('greeting', {
    bar: 'Tiaan',
    bing: 'mcface'
  })
)

console.log(t('info'))

locale('za')

console.log(
  t('greeting', {
    bar: 'Tiaan',
    bing: 'mcface'
  })
)

console.log(t('info'))

Install

This project uses node and npm.

$ npm install langylanglang
$ # OR
$ yarn add langylanglang

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT