i18next / i18next-browser-languageDetector

language detector used in browser environment for i18next
MIT License
873 stars 90 forks source link

Feature du simply display the browser language #227

Closed Aarbel closed 4 years ago

Aarbel commented 4 years ago

How can i simply display the browser langage with this lib ?

I'm just looking for a simple function to ouput browser langage (an see if it's "en" or "fr") for example.

adrai commented 4 years ago

https://stackoverflow.com/questions/8199760/how-to-get-the-browser-language-using-javascript

jamuhl commented 4 years ago

you do not need this lib to get the browser language -> https://github.com/i18next/i18next-browser-languageDetector/blob/master/src/browserLookups/navigator.js

you can get it by using browsers navigator.languages and similar -> this detector is used for i18next to detect languages from possible sources...

adrai commented 4 years ago

btw: i18next.language (or i18next.languages)

Aarbel commented 4 years ago

Thanks a lot guys !

Best solution i've found:

export const getCurrentLng = () =>
  i18n.language || window.localStorage.i18nextLng || "";

This should be clearly written in the Readme @adrai

adrai commented 4 years ago

This should be clearly written in the Readme @adrai

i18n.language is documented here: https://www.i18next.com/overview/api#language and window.localStorage.i18nextLng is an internal information, and does not necessarily reflect your browser language