Skip to content
/ i18n Public
forked from eartharoid/i18n

Lightweight localisation for Node.JS projects.

License

Notifications You must be signed in to change notification settings

theandyl/i18n

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i18n

Lightweight message localisation for NodeJS.

Installation

  • pnpm add @eartharoid/i18n or
  • yarn add @eartharoid/i18n or
  • npm i @eartharoid/i18n

Usage

Localisation files

en-GB.json:

{
	"hello": "Hello!",
	"hello_name": "Hello, %s!",
	"other": {
		"age": [
			"1 year old",
			"%d years old"
		]
	}
}

Your code

See test/index.js.

const I18n = require('@eartharoid/i18n'); // require module
const i18n = new I18n('src/locales', 'en-GB'); // create new instance - first value is the locales directory, second value is the default locale

const en = i18n.get(); // get default locale
const fr = i18n.get('fr-FR'); // get specified locale

console.log('en', en('hello')); // get english translation of 'hello' key
console.log('fr', fr('hello')); // get french translation of 'hello' key

console.log('en', en('hello_name', 'Isaac')); // english with placeholder
console.log('fr', fr('hello_name', 'Isaac')); // french with placeholder

// keys can be nested
console.log('en', en('other.age', 1)); // age[0] if first argument is 1
console.log('en', en('other.age', 21)); // age[1] if first argument is not 1
console.log('fr', fr('other.age', 1));
console.log('fr', fr('other.age', 21));

Support

Discord support server

Donate

ko-fi

About

Lightweight localisation for Node.JS projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%