vendredi 22 octobre 2021

Obtain default currency in web application

I'm searching for a straight forward, simple solution to set a default currency for my users (clientside/web), based on their location. No external API shall be called.

Apparently, this procedure requires two steps:

  • determine location
  • map location to a currency (i.e. 'USD', 'GBP', 'EUR')

So far, I tried using navigator.language (see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language) to receive the language, and then mapped the language to a currency, i.e. de -> EUR, en -> GBP

However, navigator.language does not seem like the correct tool, as it is not precise enough. It may returns 'de' for swiss for example, which has a different currency to EUR.

Any guidance and idea is welcome.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire