Add the country/language to the url from the switcher
Hello all,
My client is actually using a localize.js to translate their pages. The translation works fine but for SEO and other reasons, they would like to add the locale in to the url. So when they switch to Germany the url will switch from www.example.com to www.example.com/de. And if it switchs to Spanish, it's look liek www.example.com/es.
We've set up multilanguage groups if you simply type in the country with the correct url and locale, it does automatically switch to that language, just not from the switcher. Any ideas? Is there a javascript solution to maybe make this happen?
Add the country/language to the url from the switcher
When you hit the switcher does it go to the correct url (i.e. when you click Germany you see the "/de" in the url)? Trying to understand if the switcher isn't going to the right page or if it is but not showing the translated content.
Add the country/language to the url from the switcher
I'm going to recap what's happening for my benefit (and for anyone else that wants to chime in). You are using the localize language switcher, not the HubSpot language switcher. The localize language switcher works in that it translates the page but it is not interacting the HubSpot multi-language by going to the different versions of the page. So basically you have an English, Spanish, and German version of the page and on each one you can translate to the different languages.
I would approach this a different way and use the HubSpot multilanguage switcher. That solves the problem of properly redirecting to correct url (with the added benefit of defaulting to that region depending on the visitor's browser settings). To fire the localize code you could set up something like this in the template file header:
<script>
{% if content.language == "es" %}
Localize.setLanguage('es');
{% elif content.language == "de" %}
Localize.setLanguage('de');
{# insert any other language conditionals here #}
{% else %}
Localize.setLanguage('en');
{% endif %}
</script>
* The above code won't work on a translated blog as blogs don't have the content.language set properly. If you need to use this on a blog you could swap out the conditional of {% if content.language == "es" %} with something like {% if request.path is string_containing "/es/" %}
** I'm not familiar with localize and how they load their script so you may need to adjust the positioning of this code or wrap in require tags.