npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

language-accepter

v1.0.23

Published

Language support middleware for Express.

Downloads

14

Readme

General Information About the Package

The package aims to make it easy to build language support for API systems. By using this package, you can provide i18n support to your API systems easily and quickly. The package is used to provide language support to Sci-Hook systems and is regularly updated by the Sci-Hook Development Team.

How to Install Package?

It is possible to install the package directly to your project folder via npm. For this, you must come to the terminal where you run your project and run the npm install command below:

$ npm install language-accepter

After running the command, the latest version of the package will automatically start downloading to the "node_modules" folder. Please wait until npm service completes the process.

How to Use the Package?

To include the package in your project, simply write the following Typescript import code:

import {languageParser} from 'language-accepter';

The added function named languageParser is an Express middleware. This middleware receives the configuration specified as an object in it. Its most basic usage is as follows:

app.use(languageParser({
    "accepted-languages": ["en","tr"],
    "default-language": "en"
}));

The accepted-languages value you see here is the section where you have defined the languages you have supported in your system. The default-language value is the language that will be automatically redirected if any of the languages supported by the client are not sent. For example: If the default-language value is set to en and the fr value is sent that is not in the client system, the client will be automatically redirected to the en language.

Below are all the values and their descriptions:

| Value | Description | | ------------- | ------------------------------ | | accepted-languages | An object list of languages accepted by the system. | | default-language | The default language assigned to the system. | | autocreate-lanuage-cookie | Creates a language cookie on the client side. | | language-info-locations | A list of names of the values containing the languages sent by the client. |

A working example where all features are used:

import * as express from 'express';
import {languageParser} from 'language-accepter';

var app = express();

app.use(languageParser({
    "accepted-languages":["en","tr"],
    "default-language":"en",
    "autocreate-lanuage-cookie":{
        name:"location",
        expires:20000
    },
    "language-info-locations":[
        "headers.location",
        "cookies.location"
    ]
}));

app.use((req,res) => {
    res.send("Your language:" + res.lang);
})

app.listen(80);
  • If one of the values specified in language-info-locations contains one of the languages specified in accepted-languages and is sent, this will suppress the languages specified in the Accept-Language header.

  • The autocreate-language-cookie property ensures that the language detected by the system is stored in a cookie on the client. The value assigned to name names this cookie. The value expires determines the expiration time of this cookie.

  • The language information detected by languageParser is passed to the next middleware with the value res.lang.

Assigning as Config File

index.ts

import * as express from 'express';
import {languageParser} from 'language-accepter';

var app = express();

app.use(languageParser('language'));

app.use((req,res) => {
    res.send("Your language:" + res.lang);
})

app.listen(80);

language.json

{
    "accepted-languages":["en","tr"],
    "default-language":"en",
    "autocreate-lanuage-cookie":{
        "name":"location",
        "expires":20000
    },
    "language-info-locations":[
        "headers.location",
        "cookies.location"
    ]
}

It can also be configured with a JSON by giving the name of the above JSON file in languageParser.

Contributors

This software package is developed and provided by the Sci-Hook Organization. It is actively developed by Emirhan Gerçeker.

License

This package is made available as open-source under the MIT License. It is open for development, modification and free use. You can use the package in your personal or organizational projects, you don't need permission from anywhere. Attribution to the developers and Sci-Hook is appreciated but not legally required.