Set the site language "On Page Load"

Hi guys!

I’m building an app with multiple languages. When a new user register I’m saving his primary language in a “lang” filed and if he is logged in, Bubble is doing the localization accordingly.

My problem starts when the user is a new one and he isn’t logged in. I’m busting my head on how to detect and set the localization programmatically when the page load

The site primary language is English, however, I thought of a solution but I need a little help.

I’ve set a parameter in the URL from the marketing site, something like

www.mysite.com/?lang=heb

how do I read the “lang” param when the page is loading? and more importantly, How do I set the local language of the site accordingly?

I’m looking for a clean solution without the need to use a ghost “fake” users to handle this matter

Any thoghts?

1 Like

Try use a plugin to determine location based on ip

That URL parameter is available to you via the Get data from URL option in any expression field.

You can use my ipstack plugin, which returns the preferred language for the specific country.

You could use “Get data from ip stack” and find the Language. Then, have a conditional workflow that updates the URL accordingly. (Ex. When Language = French, navigate to www.mysite.com/?lang=fr_fr).

Or, you could have it trigger a popup that shows to the user based on a similar condition, asking if they would like to change visibility to a different language.

1 Like

This is actually such a complex problem. The user’s language preference and location are of course related, but one does not conclusively imply the other.

An easy UI is just to have a dropdown (or set of flag icons) indicating the languages the site supports.

This can be a lot simpler that programmatic approaches. Just an idea!

@jonathan2, how many languages is your site localized for?

1 Like

Ok, your plugin is cool! it’s returning the GEO location of the user how ever I still didn’t figur how do I call (SET) the local lang accordiangly (the user is logged out)

With my solution, I know the user is comming from specific GEO from the param in the URL

I’m using GET DATA FROM URL function I need to set the site lang progrematical when page load (Navigation to another web page is not a good solution)

5 langs

There’s two separate issues here:

  1. Setting user’s language preference
  2. Displaying the page in selected language

For issue #2:

Presumably, your multi-language pages are already configured either with conditions on the text elements (when lang=x change text to y) or some other method. When you get data from the URL, set whatever value you are keying off of to the value you’ve retrieved from the URL parameter.

It could be that you’ve ONLY set up your multi-language pages to key off of the user’s stored language preference… Is that correct?

What I’d do is abstract that a bit. Have a custom state on the page which is used to store the preferred language. Key your conditional displaying of multi-lingual text off of THAT.

Then, on page load, establish whether we know if the visitor has a language preference. (1) If the user is logged in and has a set language preference, use that preference (set the custom state to that value). (2) If the URL has the language parameter, use that as the preference (and this should probably override the user language preference). (3) If neither of these things, use the default language (and perhaps this also causes your flags or language select dropdown to be more prominently displayed?).

As for #1, note that you can write to Current User even on visitors who have not converted to signed up users. Bubble’s mechanism for this seems to be creating a temporary User object in the database, combined with tying that the the browser using cookies. If the user converts before those things expire, the data fields you’ve written on their User object will remain intact.

Point is, you can set an unknown visitors preferences and they may be persistent across visits (if the User’s browser allows cookies, etc.). That is, you can Make Changes to a Thing on Current User at any time.

A user who HAS converted, should be accessing your site logged in and they aren’t likely to be going through your onboarding flow again, but that’s always possible.

Hope this is helpful rather than confusing… Just trying to point you in the right direction in terms of how you might think about these issues!

1 Like

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