isekaimaou1109 / fastify-i18njs

The wrapper for i18n-js being used in fastify framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@isekaimaouyoki-sama/fastify-i18njs

This is a small wrapper around i18n-js.

Install

npm install --save @isekaimaouyoki-sama/fastify-i18njs

Usage

Easy to use require/import this plugin as below

const path = require('path')
const fastify = require('fastify')()

fastify.register(
  require('@isekaimaouyoki-sama/fastify-i18njs'),
  { 
    locale: 'vi',
    supportedLocales: ['en', 'de', 'vi'],
    messages: {
      de: require(path.join(__dirname, 'locales', 'de.js')),
      en: require(path.join(__dirname, 'locales', 'en.js')),
      vi: require(path.join(__dirname, 'locales', 'vi.js'))
    }
  }
)

fastify.get("/", async function(request, reply) {
  reply.send(fastify.i18n.t('<....>'))
})

fastify.listen({ port: 3000 }, err => {
  if (err) throw err
})

About

The wrapper for i18n-js being used in fastify framework


Languages

Language:JavaScript 100.0%