ChemPal Documentation - v1.6.0
    Preparing search index...

    Function getUserLocation

    • Gets the user's location (two-letter country code) from the browser's i18n API. This just splits the locale by the "-" character and returns the second part. This is a simple way to get the country code from the locale.

      Returns valueof

      The user's location as a CountryCode. (defaults to "US")

      // If the locale is "en-US"
      getUserLocation() // Returns "US" (United States)

      // If the locale is "en-GB"
      getUserLocation() // Returns "GB" (United Kingdom)

      // If the locale is "en-CA"
      getUserLocation() // Returns "CA" (Canada)
      export function getUserLocation(): CountryCode {
      if (typeof chrome === 'undefined' || typeof chrome.i18n === 'undefined') {
      return 'US';
      }
      return chrome.i18n.getUILanguage().split('-')[1];
      }