Reveal page translations as a HubL variable


Currently in HubL there doesn't seem to be any way to know if a page has translations or not, and what and where those translations are. It'd be really great if HubL had a variable that contained data about the page's translations as an array or a dict. E.g. write something like:

{% for translation in page_meta.translations %}
<a href={{ translation.url }}>
{{ translation.languageFullName }}
{% endfor %}

to create a link to a translation. With that I could build my own language switcher, one that could even create fallback links to language front pages, if there's not a translation of that certain page.


Currently I can only, with great frustration, try to override all the CSS in the default language switcher, which doesn't even allow to change the label to anything, just show a globe (or not, after I hide it, because I don't like it at all).


Now, if I want to know if a page has translations or not (e.g. to decide if I want to show my own label for the language switcher), I have to write quite some JavaScript magic to sniff if the language switcher produces something or not, and then based on that, create other elements with JavaScript, or modify that globe element contents. That is tedious and frustrating, as everything would be easily done with some HubL and HTML, and would allow so much more customization.

(Also, the page that is in original language, doesn't even seem to have {{ content.language }} defined at all. It's only defined in its translations. Also, the original page doesn't have <link rel="alternate"> meta tags defined, only the translations have. Which is just sloppy work. These should be corrected as well.)

3 Replies
Status updated to: In Planning
HubSpot Product Team
Contributor | Elite Partner

There most definitely exists such an HubL variable; {{content.translated_content}}


This returns an object with the page name and URL of it's translated equivalents:


{de=Translation Demo - DE de, id: 10388640097, slug: de/german-test}

If you want to check for a specific language, like when you need to exclude current option in your custom language switcher you can check for a specific language with the country code parameter. See below a couple of examples:


//check if current page language is eg. french
{% if content.language.languageTag is equalto 'fr'%}
{% endif %}

//retrieve the english translation specifically

//or eg. spanish

Hope that helps!



Thanks @anders_grove for the info. I wish HubSpot better documented all the HubL variables. There's no mention of that anywhere, especially not on the page where it's supposed to be.