Extracting page language information using HubL variables in HubSpot

I’m working on a multilingual HubSpot website where different languages are handled through URL paths (such as …mysite.com/fr-ca/ or …mysite.com/de-de/). I need to create dynamic content that changes based on the current page language.

Is there a built-in HubL variable or function that can automatically detect the current page’s language and region settings? I want to show different content blocks depending on what language the visitor is viewing.

Right now my workaround is using {{ request.path }} and manually extracting the language code from the URL, but I’m wondering if there’s a more elegant solution available in HubL.

Any suggestions would be appreciated!

The request.path approach you’re using is spot on for HubSpot’s multilingual setup. I’ve done this on multiple HubSpot sites and parsing the URL path beats relying on browser language headers every time - those headers rarely match your actual site structure anyway. Here’s what I’d tweak: create a global variable at the template level that grabs and caches the language code once per page load. Then just reference that variable throughout your templates instead of parsing the path over and over. I usually split the request.path to grab the first segment, then validate it against my supported language codes. Works like a charm and plays nice with HubSpot’s content translation workflows.

I’ve hit this same issue. You’re right that HubL doesn’t give you a clean variable for language detection. Most devs I know use request.path like you mentioned. Here’s what worked for me: build a custom module that handles the extraction logic, then reuse it everywhere. I wrote a function that grabs the language code and validates it against my supported languages list - saves you from edge case headaches. Pro tip: once you’ve got the language, store it in a cookie or session. Makes things way faster if you’re doing multiple language checks on one page. Parsing URL paths is solid and plays nice with HubSpot’s multilingual setup.

yeah, there’s no native hubL variable for this - super annoying. i built a simple regex pattern that pulls language codes from request.path and it works pretty well. you could try checking request.headers for accept-language, but it’s not reliable with most URL structures.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.