I need help with getting the current language of a HubSpot page using HubL. My website has multiple language versions and the URL structure shows the language code (for example domain.com/es-us/ for Spanish).
Is there a built-in HubL variable or method that can automatically detect the current page language? I want to show different content based on what language the visitor is viewing.
Right now I’m thinking about using {{ request.path }} to grab the URL and then extract the language code manually, but I’m wondering if there’s a cleaner way to do this in HubL.
Any suggestions would be great!
The {{ content.translated_from_id }} variable might help, but I’ve had better luck with {{ request.headers.accept_language }} plus some basic string manipulation. Just heads up - this pulls from browser settings, not the actual page language. What worked better for me was creating custom module fields for language-specific content and using {{ request.path|regex_replace('^\/([a-z]{2}-[a-z]{2})\/', '') }} to grab the locale code from your URL structure. Then you can use conditional logic to show the right content blocks. Also found that HubSpot’s multi-language feature gives you {{ content.absolute_url }} which can help identify the current language variant. Though honestly, parsing the URL path like you mentioned is probably still your most reliable bet for dynamic content switching.
I’ve been working with HubSpot multilanguage setups for years - the built-in HubL options are pretty weak for this.
Your URL parsing approach works well. I’d use {{ request.path|split('/')|select(1) }} to grab the language code directly. Much more reliable than browser headers.
Here’s the problem though - managing all this conditional logic in HubL templates gets messy quickly. You’ll have if statements everywhere.
I automate the entire language detection and content switching process now. Set up workflows that detect the visitor’s page language, then trigger different content variations or redirect to personalized landing pages.
The automation handles everything - detects URL structure and serves the right content blocks. No template complexity, and you can add new languages without touching code.
You also get analytics on which language versions perform better and can automatically optimize the experience.
This scales much better than hardcoding language logic into every template. Check out the setup: https://latenode.com
There’s actually a simpler way - no regex or complex parsing needed. HubSpot has {{ content.language }} that gives you the current page’s language code. Works great when you’ve set up multi-language pages correctly.
For URL-based detection, I use {{ request.path|truncate(6,true,'') }} to grab the first segment, then handle different language codes with a switch statement. It’s better than parsing with split since it handles edge cases when there’s no language code in the URL.
One heads up - if you’re using this for conditional content, cache the language detection result at the top of your template instead of calling it multiple times. I ran into performance issues when the detection logic fired repeatedly on the same page load.