multiple_language

1.1.0 • Public • Published

Multi Language

npm version NuGet version


Installation

Install with npm

  # Install package 
  npm i multiple_language

Import module

  const express = require('express');
  const app = express();
  ...
  const { multiLanguageBe } = require("multiple_language");
  multiLanguageBe(app);
  ...

Add translation files

  cd folder_root
  mkdir locales
  cd locales
  mkdir vi && mkdir en
  touch vi/file_name.json && touch en/file_name.json
Note
  • The directory name must be locales.
  • Locales's subdirectory is abbreviated name

API Documentation

Multi Language exposes the following api.

multiLanguageBe(app, optional)

The exported multiLanguageBe function takes two parameters. The first parameter is the app object of Express. The second parameter is an optional and It is not required. optional is the root path to the directory containing the compiled files.

By default if option is empty the package will find a directory called locales. This directory is on par with the index.js or server.js. If you want to change the path you can change the new path for this parameter.

If you use the Content-Language variable to store the language value in the request's header. You can use setLanguageBe function as a middleware to automatically set the language for your other request.

The exported setLanguageBe function gets its value fro the default variable Content-Language.

If setLanguageBe function is used, then Content-Language variable is indispensable in each request.

Example
  const express = require('express');
  const app = express();
  ...
  const { multiLanguageBe, setLanguageBe } = require("multiple_language");
  const pathName = __dirname + '/folder'
  multiLanguageBe(app, pathName);
  app.use(setLanguageBe); // Get the value from variable "Content-Language" in the request's header
  ...

Authors and acknowledgment

  • Project manager: tungdd5@fpt.com.vn

Support

Reach out to me at one of the following places!

License

Copyright © 2020 FPT VPN. Crafted with ❤️ by Tùng Duy - tungdd5@fpt.com.vn. Released under the MIT License.


This file was generated by Tùng Duy, v1.1.0, on May 10, 2020.

Package Sidebar

Install

npm i multiple_language

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

10.5 kB

Total Files

15

Last publish

Collaborators

  • tungduy