News for hackers. Stuff that matters.
Re:Building a currency conversion tooltip for my website by nailer on Friday November 25, 2022 @06:57AM (#33741565)
> Instead, I check the user's preferred locales in navigator.languages, and use that to choose which currencies to list.

Excellent. That’s how it should be done. So many people seem to ignore things browsers already tell the server.

Re:Building a currency conversion tooltip for my website by nicbou on Friday November 25, 2022 @07:00AM (#33741589)
While the locale implies a country, it does not imply its currency. Many people set their conputers to en-US without ever living there.

It's a hack in my book, but it's the best hack I could come up with.

Re:Building a currency conversion tooltip for my website by masklinn on Friday November 25, 2022 @07:52AM (#33741922)
> While the locale implies a country, it does not imply its currency. Many people set their computers to en-US without ever living there.

And the relation between system and browser language is not always simple. For instance Safari on macOS doesn't (seem to) reflect all the system-configured languages, it just returns the primary (or whatever you configured for safari specifically).

So if you habitually configure your system in en (-US or -GB) then add your "mother culture" as secondary, won't work, you'll get USD or GBP which may mean nothing to your day-to-day.

> It's a hack in my book, but it's the best hack I could come up with.

Since it's your own site, why not add a `localStorage` override?

Obviously it requires additional work (a currency picker UI of some sort, and a way to get to it from the tooltip), but it should allow users to fix things up when the defaults are not right for them.

Re:Building a currency conversion tooltip for my website by nicbou on Friday November 25, 2022 @08:29AM (#33742175)
The initial design (on paper) let you choose your currency, but I went for something simpler. I like that the tooltips just use :hover styling, and could even work without JavaScript if I set their value on the server side. Something more complex would be a bit more finicky (as are the current glossary tooltips).