@tgify/i18n
v1.0.3
Published
Tgify i18n engine
Maintainers
Readme
i18n for @tgify/bot
Internationalization middleware for @tgify/bot.
Installation
$ npm install @tgify/i18nExample
const { Tgify } = require('@tgify/bot')
const TgifyI18n = require('@tgify/i18n')
/*
yaml and json are ok
Example directory structure:
├── locales
│ ├── en.yaml
│ ├── en-US.yaml
│ ├── it.json
│ └── ru.yaml
└── bot.js
*/
const bot = new Tgify(process.env.BOT_TOKEN)
// @tgify/i18n can save current locale setting into session.
const i18n = new TgifyI18n({
defaultLanguageOnMissing: true, // implies allowMissing = true
directory: path.resolve(__dirname, 'locales'),
})
bot.use(i18n.middleware())
bot.start((ctx) => {
return ctx.reply(
ctx.i18n.t('greeting', {
username: ctx.from.username,
})
)
})
bot.launch()See full example
