Language Switcher

SOLVE
Occasional Contributor

Our web company is implementing a language switcher for our site pages

 

They have said that the only way to implement a switcher on hubspot is to do a Javascript re-direct, which will allow the person to land on the default (UK) page before redirecting them to the alternative language one. This will cause a slight delay, as the page will have to load twice. So, my question is: are there any bespoke options available through custom code etc, that would take visitors directly to the correct language page?

Reply
0 Upvotes
2 Accepted solutions

Accepted Solutions
Esteemed Advisor

Hi @AccessAmity ,

 

Have you read this article from Hubspot? https://knowledge.hubspot.com/articles/kcs_article/cos-general/how-to-manage-multi-language-content-...

 

download (4).png

 

The coding languages available for development in hubspot are html, css, javascript, and hubl. all of these except hubl are processed by the browser. hubl is a server side language, but it is a templating language, and the last language processed by the server before the pages are served to the browser. I do not see any variables that would supply the user's location in the HubL supported variable docs, but even with something like that available, the route to the page would have already started the process of serving the page, which would then be interupted by logic in the template to create a redirect.

 

There are some javascript apis that can detect the user's location, under the right conditions, but javascript isn't processed by the browser until after the page has been served to the browser, so it would actually be slower than a template redirect.

 

html and css are strictly structure and styling so they aren't any help here.

 

While it makes since that you would want to avoid a redirect, the redirect provided through the language switcher functionality seams to process before the template, so it would be the fastest. I am only speculating, but I believe that when a user requests a page, Hubspot's router will check the users location before trying to serve the template. they request a "url", but the router attempts to check the users language, then redirects them to a new route that then builds the template and serves the page in the correct language. 

 

There has to be some sort of anchor in this situation, otherwise the user's browser would need to know their language and know what what page to send them to on your site, performing the redirect before the request for the page is sent. That isn't possible, so your user has to attempt to access your page, and the backend programming has to make these decisions before trying to serve the page.

As far as redirects go, using Hubpot's default language switcher functionality would be the fastest. I would perform a test as soon as you are able to access the templates. If you are experiencing a noticeable issue with load time, you might want to do a speed check on the template itself. 

 

hopefully this helps answer your question.

 

Need help? Hire Us Here

- Jonathan Sumner
Highlighted
HubSpot Moderator

That's a great response. Thanks for chiming in, @Jsum.

 

The only other thing I'd add here is that we do create a HubL "request" dict. It has certain attributes like "geoip_country", "geoip_city", "geoip_region". Like you said though, this would need to be processed at the template-level before the page is loaded. And then you'd be able to add in a redirect through JavaScript using those variables, which would happen after the page load. But ultimately this won't be faster than using the default language switcher anyway.

Leland Scanlan

HubSpot Developer Support
5 Replies 5
HubSpot Moderator

Hi @AccessAmity,

 

Just so I understand, is your goal to avoid having multiple pages altogether? So for example instead of having 2 URLs: https://www.domain.com/en/slug and https://www.domain.com/fr/slug for example, you'd have just https://www.domain.com/slug ? And then on that one page, you'd have all the content already: both in English and in French. So that when a visitor clicks on the link to get the French or English version, the content just loads from within the page, rather than the browser redirecting to a new URL.

 

Or do you have an example page somewhere that demonstrates the effect you're going for? I might be able to provide some recommendations based on that.

 

 - Leland

Leland Scanlan

HubSpot Developer Support
Reply
0 Upvotes
Occasional Contributor

Hey Leland,

Thanks for offering to help.

 

We have built translation pages within Hubspot for UK English and US English- as we are moving into the US market, example here of US URL: https://www.accessplanit.com/en-us/course-management-software

 

We are having our webdevs set it up so that US IPs get redirected to the en-us pages, but they currently have to land on the UK version first and then be redirected (unless they discover the US url first that is), which causes two page loads. Although its not a massive problem, I just wondered if there was any work-around, so they get redirected before initial page load.

Reply
0 Upvotes
Esteemed Advisor

Hi @AccessAmity ,

 

Have you read this article from Hubspot? https://knowledge.hubspot.com/articles/kcs_article/cos-general/how-to-manage-multi-language-content-...

 

download (4).png

 

The coding languages available for development in hubspot are html, css, javascript, and hubl. all of these except hubl are processed by the browser. hubl is a server side language, but it is a templating language, and the last language processed by the server before the pages are served to the browser. I do not see any variables that would supply the user's location in the HubL supported variable docs, but even with something like that available, the route to the page would have already started the process of serving the page, which would then be interupted by logic in the template to create a redirect.

 

There are some javascript apis that can detect the user's location, under the right conditions, but javascript isn't processed by the browser until after the page has been served to the browser, so it would actually be slower than a template redirect.

 

html and css are strictly structure and styling so they aren't any help here.

 

While it makes since that you would want to avoid a redirect, the redirect provided through the language switcher functionality seams to process before the template, so it would be the fastest. I am only speculating, but I believe that when a user requests a page, Hubspot's router will check the users location before trying to serve the template. they request a "url", but the router attempts to check the users language, then redirects them to a new route that then builds the template and serves the page in the correct language. 

 

There has to be some sort of anchor in this situation, otherwise the user's browser would need to know their language and know what what page to send them to on your site, performing the redirect before the request for the page is sent. That isn't possible, so your user has to attempt to access your page, and the backend programming has to make these decisions before trying to serve the page.

As far as redirects go, using Hubpot's default language switcher functionality would be the fastest. I would perform a test as soon as you are able to access the templates. If you are experiencing a noticeable issue with load time, you might want to do a speed check on the template itself. 

 

hopefully this helps answer your question.

 

Need help? Hire Us Here

- Jonathan Sumner
Highlighted
HubSpot Moderator

That's a great response. Thanks for chiming in, @Jsum.

 

The only other thing I'd add here is that we do create a HubL "request" dict. It has certain attributes like "geoip_country", "geoip_city", "geoip_region". Like you said though, this would need to be processed at the template-level before the page is loaded. And then you'd be able to add in a redirect through JavaScript using those variables, which would happen after the page load. But ultimately this won't be faster than using the default language switcher anyway.

Leland Scanlan

HubSpot Developer Support
Occasional Contributor

Thanks, i thought this would be the case- but worth double-checking. A great response, thank you