Skip to content

Find the preferred language of the current user using JavaScript

const findPreferredLang = (defaultLang = 'en-US') => 
  navigator.language ||
  (Array.isArray(navigator.languages) && navigator.languages[0]) ||
  defaultLang;
Advertisements

Examples

findPreferredLang(); //en-GB

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.