bukinoshita / detect-browser-language

Detect browser language
MIT License
37 stars 3 forks source link

Does not work in Safari #7

Open j4nos opened 3 years ago

j4nos commented 3 years ago

It detects English though in my Mac OS I have Hungarian language set. Laguage is not set per browser in Mac Safari. Maybe this is the reason of the bug.

bukinoshita commented 3 years ago

Can you share a reproducible code and what error you're getting?

I tested with

import detectBrowserLanguage from 'detect-browser-language';
import { useState, useEffect } from 'react';

const Home = () => {
  const [language, setLanguage] = useState(null);
  useEffect(() => {
    const language = detectBrowserLanguage();
    setLanguage(language);
  }, []);

  return (
    <h1>
      Language preference: {language}
    </h1>
  );
};

export default Home;

And this is the result:

Screen Shot 2020-12-03 at 2 40 11 PM

You can set the browser language in the Language & Region in MacOS.

Screen Shot 2020-12-03 at 2 44 00 PM