Hey everyone!
I’m working on a multilingual HubSpot site and need some help with HubL. My site uses different URLs for each language (something like mysite.com/fr-ca/ or mysite.com/de-de/).
I want to show different content based on what language the visitor is currently viewing. Is there a built-in HubL variable or function that can detect the current page language automatically?
Right now I’m thinking about using {{ request.path }} and then writing my own code to extract the language code from the URL, but I’m hoping there’s an easier way.
Has anyone dealt with this before? Any suggestions would be really helpful!
Thanks in advance
i think using the regex with request.path is a solid move. it gives u more control over the language extraction, plus it just feels more customizable. content.translated_content could be helpful too, but parsing the URL seems more direct in ur case.
Skip the HubL variables and manual coding - I automated the whole language detection thing instead.
Built a workflow that watches page visits, pulls language codes from URLs, and switches content based on where visitors are from and their language settings. No more hardcoding language checks or fixing broken templates when URLs change.
It handles everything automatically - finds new language patterns, updates content across pages, even tracks which languages get the most traffic so you can see what’s working.
Way better than coding language detection that breaks every time you add a language or change your URL setup. You can also set fallback languages and test different content versions.
Set it up once and you’re done. I used https://latenode.com to build it.
HubSpot actually has a simpler way than parsing URLs manually. Use content.absolute_url with HubSpot’s language detection methods. The content.translated_content object has language-specific data you can use without writing custom regex patterns. I’ve found that page_meta.html_lang often gives you the current language code directly. This works great when your site follows HubSpot’s recommended multilingual setup. URL parsing with request.path works, but HubSpot’s built-in language handling is more reliable across different configurations and needs less maintenance when adding new languages.
I’ve built multilingual HubSpot sites and ran into issues where browser language settings don’t match URL language codes - it breaks the solutions people mentioned above. Here’s what worked for me: I created a custom module that uses content.language.code but also checks request.full_url as backup to grab the language segment. This fixes problems when HubSpot’s language detection fails, especially with custom domains or subdirectory setups that don’t follow standard patterns. Using both methods means your content shows up correctly no matter how visitors land on your pages or how search engines index your multilingual content.
Just a heads up - {{ content.translated_content }} has a language property you can grab directly instead of using locale variables that act weird sometimes. Found this out when {{ locale }} kept giving me different values between preview and live pages. Use {{ content.translated_content.language }} instead - it pulls straight from HubSpot’s CMS rather than browser detection. Works perfectly across different hosting setups and won’t break when you migrate accounts or change domains. Also handles visitors hitting cached pages with outdated language detection.
honestly, content.language.code is probably your best bet. if that doesn’t work, try checking request.headers.accept_language with your url structure. I’ve seen sites use both as backups when one fails.
Manual detection works okay for simple setups, but falls apart with multiple sites or complex language configurations.
I ditched the custom HubL approach and automated everything. Built a system that pulls visitor language from URL structure, browser settings, location data, and visit history.
Serves the right content automatically - no template changes needed. Add new languages or tweak URL patterns and it updates everywhere instantly.
Handles tricky situations too, like French URL + English browser settings. Makes smart choices using all available data points.
Bonus: tracks which language versions convert better. Way more reliable than hardcoded detection that constantly needs updates.
Built it using automation tools at https://latenode.com
i’d use {{ locale }} too, but test it on different subdomains first. mine worked fine on staging then broke in production with multiregion setup. add a fallback check just in case.
I’ve dealt with this exact issue on multilingual HubSpot sites. content.language.code works fine, but I’d recommend {{ locale }} instead - it’s cleaner and more reliable across different account setups. You can pair it with conditionals like {% if locale == 'fr-CA' %} for language-specific blocks. The big win is it won’t break if you change your URL structure later, plus it plays nice with HubSpot’s translation tools when you add more languages.
I’ve been using {{ content.language.code }} for exactly this on several multilingual HubSpot sites. It directly returns the language code (‘fr-ca’ or ‘de-de’) without any URL parsing. Works great with HubSpot’s multi-language domains when your language variants are set up properly. Then you can use {% if content.language.code == 'fr-ca' %} to show language-specific content. Way cleaner than regex and handles edge cases better since it pulls from HubSpot’s internal language detection instead of URL structure that might change.