{% macro languageSwitcher(show_icons = false,show_current_as_top = true,use_hubspot_name = false) %} {% set languages_list = is_listing_view ? group.translations : content.translated_content %} {% if languages_list|length > 0 %} {# ['ISO 639-1' : 'ISO 3166'] ISO 3166 COUNTRY codes for https://flagpedia.net/download/api Hubspot uses ISO 639-1 LANGUAGE codes for translations http://www.lingoes.net/en/translator/langcode.htm #} {% set iso_code_map = { "sv" : ["se", "Svenska"], "en" : ["gb", "English"], "no" : ["no", "Norsk"], "fi" : ["fi", "Suomalainen"], "da" : ["dk", "Dansk"], "de" : ["de", "Deutsche"], "nl" : ["nl", "Nederlands"], "es" : ["es", "EspaƱol"] } %} {# Get the current 639-1 from Hubspot eg. en or en-gb #} {% set currentLang = (content.language.languageTag || group.language) %} {# Split with "-" if possible #} {% set current_split = currentLang|split('-') %} {# Use the first part as the language code ignoring the country #} {% set current_language = current_split[0] %} {# get the country code (ISO 3316). eg. extract se from "sv-se" or gb from "en-gb" #} {% set current_country = current_split|length > 1 ? current_split[1] : iso_code_map[current_language][0] %} {% set current_name = use_hubspot_name ? locale_name((show_icons ? current_language : currentLang)) : iso_code_map[current_language][1] %} {% set current_icon = (show_icons && current_country) ? '' : '' %} {% set top_icon = show_current_as_top ? current_icon : '' %} {% set top_name = show_current_as_top ? current_name : '' %} {% endif %} {% endmacro %}