Smart i18n (i18x)
Smart easy-to-use i18n library

npm i i18x
or:
yarn add i18x
Usage
import I18n from 'i18x'
import messages from './messages.js'
const i18n = new I18n(messages)
const t = i18n.getTranslator('fa')
console.log(t`Hello`)
Example
First create your translation file (we call it as messages.js) file, based to this template:
export default {
en: {
$dir: 'LTR',
$locale: 'en-US',
},
fa: {
$dir: 'RTL',
$locale: 'fa-IR',
',': '،',
';': '؛',
Hello: 'سلام',
world: 'دنیا',
Human: 'انسان',
water: 'آب',
Earth: 'زمین',
Sun: 'خورشید',
Moon: 'ماه',
star: 'ستاره',
galaxy: 'کهکشان',
Venus: 'ناهید',
Mars: 'بهرام',
and: 'و',
or: 'یا',
'In the name of God': 'به نام خدا',
'the stars': 'ستارگان',
'is very nice': 'خیلی خوبه',
$numerical: {
0: '۰',
'.': '٫',
',': '٬',
},
},
$RTLs: {
'\u200E': '\u200F',
$arrows: [
'←',
'⇐',
],
},
}
Then create a new instance of I18n class using that file and get your translators (t):
import I18n from 'i18x'
import messages from './messages.js'
const i18n = new I18n(messages)
const t = i18n['fa']
console.log(t('Hello'))
console.log(t`Hello`)
const world = 'world'
console.log(t`Hello ${world}`)
console.log(t`${1 + 2}. Earth`)
console.log(t`1,234,567.890`)
console.log(t`Today: ${new Date()}`)
console.log(t`Hello, world`)
const LRM = '\u200E'
console.log(t`${LRM}Javascript is very nice!`)
See example.