Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-vk-bot-api-i18n

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-vk-bot-api-i18n

I18n middleware for node-vk-bot-api

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-vk-bot-api-i18n node-vk-bot-api-i18n

node-vk-bot-api-i18n

🇪🇺 I18n middleware for node-vk-bot-api.

Install

$ npm i node-vk-bot-api-i18n -S

Tests

Before you must set TOKEN and GROUP_ID in process.env.

$ npm test

Usage

const VkBot = require('node-vk-bot-api')
const Session = require('node-vk-bot-api/lib/session')
const I18n = require('node-vk-bot-api-i18n')
const path = require('path')

const bot = new VkBot({
  token: process.env.TOKEN,
  group_id: process.env.GROUP_ID
})
const session = new Session()
const i18n = new I18n({
  locales: ['en', 'ru'],
  defaultLocale: 'en',
  directory: path.join(__dirname, 'locales')
})

bot.use(session.middleware())
bot.use(i18n.middleware())

bot.command('/start', (ctx) => {
  ctx.reply(ctx.i18n.__('start', {
    name: 'Mikhail'
  }))
})

bot.startPolling()

API

Options

  • locales: Languages list
  • defaultLocale: Default language
  • directory: Absolute path to locales directory

Methods

  • ctx.i18n.locale=: Setter for locale
  • ctx.i18n.locale: Getter for locale
  • ctx.i18n.__(key, [variables]): Generate message from template

Locale file example

All files must be store as json.

{
  "start": "Hello, %name%!",
  "errors": {
    "userNotFound": "User not found."
  }
}

License

MIT.

Keywords

FAQs

Package last updated on 10 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc