How can I detect browser language setting and pass it to bubble?

I spent hours looking for the answer in the forum, but I am kind of lost regarding how to pass the browser language setting into bubble via “javascript to bubble”.

I am trying to selectively show an Sign-in screen that is appropriate for the “first time visitor(logged out)”. Say, the visitor is Japanese, I want the Sign-in written in Japanese.

This is the steps I want to take.

  1. Get browser language setting.
  2. Pass the data(1) into bubble.
  3. Change custom state according to the data(2)

I need a solution on 2. Pass the data to bubble.

This is the code I found on the internet that is supposed to “Get browser language setting(1)”.

 >    window.onload = function() {  
>   var language;  
>   
>   if (navigator.browserLanguage != null) {  
>     // Internet Explorer, Opera, etc 
>     language = navigator.browserLanguage.substr(0, 2);  
>   } else if(navigator.userLanguage != null) {  
>     // Internet Explorer  
>     language = navigator.userLanguage.substr(0, 2);  
>   } else if(navigator.language != null) {  
>     // Chrome, Firefox, Opera, etc
>     language = navigator.language.substr(0, 2);  
>   } else { 
>     language = "en";  
>   }  
>   
>   setLanguage(language);  
> }  

Anybody has an idea? Thanks.

Btw, I know how to show an appropriate language nicely via “App Text”. But this is good for the users “logged in”.

2 Likes

I have a free plugin for that: Search “Browser Timezone and Locale”.

You’re welcome!

5 Likes

Thanks for the quick reply, @keith !
I assumed the plugin is made to get Time and Locale.
Can I use it to detect Language as well?? Let me try it anyway!

Thanks again.

I could not make it work…
Am I missing something here?

06

Btw, I see some error in your instruction page. Is this related to my failure?
25

Thanks! @keith

I think this is the right path to use.
48

1 Like

No, that’s not the problem. (And apologies: I guess I need to change my demo app for Browser Timezone & Locale. The Timezoner app has become a place where I test a whole bunch of stuff related to my Calendar Grid Pro plugin, which has Locale detection built-in, so I seem to have deleted BT&L from that project.)

The problem is that the Locale code for Japan is “ja”, not “ja-jp”. The one problem with Locales (which are an awesome concept) is that it can be hard to know what the codes are.

You basically need to test in a browser to know what the reported locales are for areas you are interested in.

A little more on Locales:

There is no “language” setting in the browser. Instead, there is this concept of “Locale”. A Locale (while primarily used for language preference detection) represents a broader set of cultural preferences beyond most-common language.

For example, Locale “en-us” (English, US) means (among other things):

  • The preferred language is English (US-style)
  • Preferred date format is month/day/year
  • The first day of the week is Sunday… etc.

In Locale “fr” (France) these are:

  • The preferred language is French
  • Preferred date format is day/month/year
  • The first day of the week is Mondays

The thing that’s a bit confusing is that the Locale attribute is generally set in a browser by selecting a “Language” preference (in Chrome for example), but language is a sub-type of Locale.

For the real detail on this, see the URL shown in the BTZ&L plugin’s interface: http://rebrand.ly/browser-locale-info

If you’re really into int8n and doing a commercial project you might be interested in my Calendar Grid Pro commercial plugin, which is (among many other things) an internationalized date picker/calendar generator. <— shameless plug!!!

Hope this helps!
Keith

3 Likes

Thanks for the detail!! @keith
I got your idea thoroughly.

I keep getting so many solutions from your thread.
This time again!

1 Like

By the way, you could simply have this step as:

Set State
Element u
Custom state: lang
Value: BrowserTimezone/Locale A’s Browser Locale

(and omit the “Only when…” condition)

:wink:

5 Likes

OMG! What a beauty of simplicity!
This is it!

Thanks @keith !!

1 Like

Hey @keith and @rio , thanks for the explanation. How can we use the locale (once it’s saved as a state) to select a different language for the app? In settings, you can specify a user’s field to be used for languages, but if the visitor is not logged in (it’s not a user yet), how can we select the strings in English or a different translated language? Thanks a lot!

Hi, @eurogar.

In my case, I created a different set of language group. Then, I made the group visible only when the browser locale match the group. This is the actual conditions for Sign-up.

57

One thing that bother me is the loading time. It takes a few seconds to complete displaying the correct language group. Need some experiments here.

1 Like

Hey @rio! Thanks for sharing how you do it! Although it’s a good option, I see how your approach would impact negatively my app in 2 ways:

  1. Bubble’s editor becomes very heavy and slower when having a lot of hidden groups. In the past, this brought me some problems.
  2. As I want to build some serious SEO, I need the content to be loaded by default on page. Content that is initially hidden (e.g. a text within a hidden div) won’t be captured by Google as text to be taken into account for SEO purposes. The solution would be having visible the English version, at least, and then based on the locale, you hide it (and show other divs with the right language) or not.

Indeed the loading time is a bit of a pain. You can read in this post at Crazy Egg, loading speed is usually critical if you want to have a low bounce rate on your website. If that’s not super critical for your business, it’s OK though.

To be honest, I’m still waiting for some improvements in terms of multi-language easiness and SEO friendliness. Sure Bubble will be offering some improvements at this respect (I hope so!).

Hey @eurogar! Thanks for the SEO things. Yep, I do need to think about it seriously as well.
I have come up with two ideas that might meet your needs.

  1. Redirect to the language page by making users choose their language from dropdown list. Page is lighter since it’s separated from other language.
  2. Log the user in as the anonymous language user in response to selecting the language. You can use the “app text” since the user is logged in.

Hope it helps!

1 Like

Thanks for the follow up, @rio! Super quickly:

  1. True, but that, in some cases, can kill the UX, thus conversion. For same examples, this can be perfectly valid, though! :smiley:
  2. Tip: Even if a visitor is not logged it (so there’s no real user in the User database), you can assign values to that user, as the language/locale. It seems like Bubble creates a virtual user using cookies, which is not saved on the database, but on a virtual table. So you can assign the value of the language without signing up the user (signing up a user without its consent doesn’t seem very GDPR compliant, so just in case! :slight_smile:)
1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.