Socket
Socket
Sign inDemoInstall

browser-localization-detector

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-localization-detector

Detects and sets the user's preferred language for web applications.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

browser-localization-detector

This library provides a simple and efficient way to detect the preferred language of a user's browser in a Node.js environment. It utilizes the accept-language-parser library to parse the Accept-Language header of an HTTP request and extract the user's preferred language.

Installation

npm install browser-localization-detector

Usage

const detectPreferredLanguage = require('browser-localization-detector');

// Example usage in an Express.js route handler
app.get('/', (req, res) => {
  const preferredLanguage = detectPreferredLanguage(req);
  res.send(`Your preferred language is: ${preferredLanguage}`);
});

API

detectPreferredLanguage(req)
  • req: HTTP request object.

Returns the user's preferred language code based on the Accept-Language header of the provided request object (req). If no language is detected, null is returned.

Example

const express = require('express');
const detectPreferredLanguage = require('browser-localization-detector');

const app = express();

app.get('/', (req, res) => {
  const preferredLanguage = detectPreferredLanguage(req);
  res.send(`Your preferred language is: ${preferredLanguage}`);
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Note

This library is designed to be used in a Node.js environment and does not support browser-side JavaScript. If you require browser-side localization detection, consider using libraries such as i18next in conjunction with i18next-browser-languagedetector.

License

This library is licensed under the MIT License. See the LICENSE file for details.

Author

For any questions or issues, please open an issue on GitHub. Contributions are welcome!

Keywords

FAQs

Package last updated on 17 Apr 2024

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