New Free Plugin: Browser Timezone and Locale

Hi, the plugin is returning just a lang code, not the whole locale (like fr instead of fr_fr)

image

Just published Browser Timezone and Locale v 1.2.0. This version adds 2 new outputs which give the browser’s current timezone offset in hours and minutes:

Runtime:

As a reminder, I work for tips. You can tip me here:

2 Likes

@keith,
This is great, thanks for adding it! Quick question: Are all offset values supposed to be positive?

Example: I’m in the “America/New_York (-4)” time zone and it’s returning “4” for the offset (hours) value.

Is there not a note about this in the plugin interface? Anyway, from the docs for getTimezoneOffset:

The time-zone offset is the difference, in minutes, from local time to UTC.

Note that this means that the offset is positive if the local timezone is behind UTC, and negative if it is ahead. For example, for time zone UTC+10:00 (Australian Eastern Standard Time, Vladivostok Time, Chamorro Standard Time), -600 will be returned.

Heh, yeah it’s probably in there, but it might have been cut off in the editor:

Thanks for the clarification!

Oh, well that’s annoying, isn’t it? I didn’t notice that happening in my own tests. Will look into that.

But glad the clarification helped!

1 Like

Hi, I have just noticed that the browser locale does not return any data. Anybody else experiencing this issue ? Thanks

Hey @keith

Great plugin, thanks. Just installed it.

Question: Is there a list of languages and their appropriate locale codes? Something like:

  • en-US = English (USA)
  • de = German
  • fr = French

Is there a full list of all the codes?

Best,
Flurin

@flurin and others who may have wondered the same question (where to find a list of locales - which are technically “BCP 47 language codes”), here’s GitHub repo with a good rundown. (You’re interested in the “Language Identifier” columns in these tables:

1 Like

hey @keith just stumbled on this thread, but I’m looking to set up something for an app that goes “hey, looks you be a 'murican, blah blah”. Because I need to separate US from CA users. But some quick testing showed that it shows Canadian Locations as e.g. America/Vancouver

While that’s not wrong, I’m not sure if it’s able to detect wether the users are in US or CA, if it doesn’t give me a country. Figured I’d check with you before I get stuck in, apologize for being lazy.

Edit. I was too damn lazy there, sorry. Looks like Locale is reported as en-CA and en-US, could probably use that, duh!

You are correct. :slight_smile:

BTW, AFIAK, the only difference between the en-US and en-CA locales is that the preferred date format in en-CA is YYYY-MM-DD (while it’s MM/DD/YYYY in en-US). I’m not sure what the preferred hourly time format is (meaning, I don’t know if momentjs forces hours to 24 hour clock or not for en-CA).

Canada and the US share the following:

  • Basic en (english) alphabetization
  • Week starts on Sunday
  • Month/Weekday names are shared (because en)
2 Likes

Hi all,
Reading all your questions and replies, I was sure to have find the solution to my problem but… finally not.

My app is in 2 different languages (fr and en) parameterized in the settings/languages of bubble.
I installed this plugin in my login page and I created this workflow :


ANd I don’t know why, even if my browser language is french, the page is still in english…
(For information, my primary language is en)

The “Browser Locale” output of this plugin is the following:

Intl.DateTimeFormat().resolvedOptions().locale

:point_up:execute this in your browser console and you will see the same string that is published to the Browser Locale output. (Which you can see if you just drop a text element on your page and print that output.)

What you’ll find is that these strings look like this:

en-US

They aren’t just ‘fr’ or ‘en’. What you’re looking to do is trigger your workflow when the text in Browser Locale includes or starts with ‘fr’. This is documented in the plugin.

You can read up on Intl.DateTimeFormat().resolvedOptions() here: Intl.DateTimeFormat.prototype.resolvedOptions() - JavaScript | MDN

You can read up on BCP 47 language tags here: JavaScript: Language Tags (BCP 47)

1 Like

Thanks ! I succed to correct my app :slight_smile:
I just still have a problem with my WF, because of the last action “refresh the page”. It creates a loop and the page refreshes everytime. But it’s not linked to your plugin

Got errors in debuger:
Recursion when evaluating visibility on element “BrowserTimezone/Locale A”

How I can fix it?

You have a nonsensical condition or expression. The issue checker probably shows this as an issue. Click the issue to take you to the circular expression.

This is the problem, the error checker does not show anything

For anyone wanting to restrict certain users from different countries accessing your site based on time zones, I made a plug-in that spits out the current user’s state or region and their country. No need to break your head anymore. It’s completely free

1 Like