Socket
Socket
Sign inDemoInstall

browser-lang

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    browser-lang

Detect user's most preferred language within the given language list.


Version published
Weekly downloads
20K
decreased by-15.69%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

browser-lang

Detect user's most preferred language within the given language list.

Why?

  • To determine an initial display language or default language router on your application with fallback options.

Inspiration

  • I made en and ko router to support i18n. How do I detect user's preferred language in browser?
  • My app only supports en and ko for now. What language should I display when zh users visit us?
  • I added fr router. But, how do I handle fr_FR and fr_CA users as well?

Installation

npm install browser-lang --save

or

yarn add browser-lang

Options

  • languages: language code list that is available on your application.

  • fallback: default language when user's preferred language is not on the list.

Example

in javascript project

// const browserLang = require('browser-lang');
import browserLang from 'browser-lang';

const myLanguage = browserLang();
// return the preferred language in browser: e.g. "ko-KR" or "ko".

const myLanguage = browserLang({
  languages: ['ko', 'de', 'zh', 'zh_TW', 'en'], 
  fallback: 'en',
});

// return "ko" if the preferred language in browser is set to "ko-KR" or "ko".
// return "en" as a fallback if the preferred language in browser is "fr".
// return 'zh' if the preferred language in browser is set to "zh_HK".

Browser support

  • Chrome
  • Firefox
  • Safari
  • IE
  • Edge
  • Opera

License

MIT © Daewoong Moon

Keywords

FAQs

Last updated on 27 Oct 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc