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

@clqu/express-translation

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clqu/express-translation

Express middleware for translating your app

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@clqu/express-translation

NPM Version NPM Downloads

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install @clqu/express-translation express-session

express-session is required module.

Usage

const app = require("express")();
const { Translation } = require("@clqu/express-translation");

const session = require("express-session"); // required module
const translation = new Translation({
    path: "./locales/%file", // ./locales/en-US.json
    defaultLanguage: "en-US"
});

// Sequence is important, import after session.
app.set('trust proxy', 1);
app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    cookie: { 
        secure: false 
    },
}));

app.use(translation.use);

app.get("/", (req, res) => {
    res.send(req.t("hello"));
});

app.get("/languages", (req, res) => {
    res.send(req.getLanguages());
});

app.get('/addLanguage', (req, res) => {
    req.addLanguage('tr-TR');
    res.send('Added language');
});

app.get('/setLanguage', (req, res) => {
    req.setLanguage('tr-TR');
    res.send(req.t('hello'));
});

app.listen(3000, () => {
    console.log("Server started on port 3000");
});

Interface

interface Request {
    t: (key: any) => void;
    language: string;
    addLanguage: (language: string) => void;
    getLanguages: () => void;
    setLanguage: (language: string) => void;
}

License

MIT

Keywords

FAQs

Package last updated on 23 Oct 2022

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