Skip to content

mouafa/malal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

malal

a lightweight i18n and l10n library for node.js and the browser Coverage Status

  • Version 2 is now use ES6 modules, for CJS modules please use version 1 *

Installation

$ yarn add malal

If you prefer using npm:

$ npm i -S malal

Usage

const m = require('malal')
// decalre your translation mapping or parse a json file
const en = { greeting : { _hello : 'hello {{name}}' }}
const de = { greeting : { _hello : 'hallo {{name}}' }}
m.set('en', en)
m.set('de', de)

by default the first language is used

.__ is an alias of .tanslate

m.__('greeting._hello') // >> 'hello {{name}}'
m.translate('greeting._hello') // >> 'hello {{name}}'

change the language

m.use('de') // >> 'hello {{name}}'
m.__('greeting._hello') // >> 'hallo {{name}}'

set default context

m.context = { name: 'Adam'}
m.__('greeting._hello') // >> 'hallo Adam'

set in place context

m.context = { name: 'Adam'}
m.__('greeting._hello', { name: 'Sami'}) // >> 'hallo Sami'

composable use

 m.set('en', en)
  .set('de', de)
  .use('de')
  .setContext({ name: 'Adam'})
  .__('greeting._hello', { name: 'Sami'}) // >> 'hallo Sami'

About

📝 lightweight i18n library for the javascript ecosystem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published