{{- /*
-- This shortcode generates the HTML link to an internal resource, which can be translated or not.
-- It displays a country flag when the target page is in a different language than the current page.
-- Currently, this shortcode can only handle Hugo sites with two languages.
--
-- The output must not contain any extra whitespace since the link is
-- usually embedded in a sentence.
*/ -}}
{{- $path := .Get "path" -}}
{{- $currentLang := .Page.Lang -}}
{{- $title := .Get "title" -}}
{{- $sites := hugo.Sites -}}
{{- if ne $currentLang (index hugo.Sites 0).Language.Lang -}}
{{- $sites = collections.Reverse hugo.Sites -}}
{{- end -}}
{{- range $sites -}}
{{- with .GetPage $path -}}
{{ or $title .Title }}
{{- if and (eq $currentLang "en") (eq .Lang "fr") }} {{ partial "icons/fr.svg" . | strings.TrimSpace | safeHTML }}{{ end -}}
{{- if eq $currentLang "fr" -}}
{{- partial "lang-detection.html" . -}}
{{- if .Store.Get "en_article_in_fr_site" }} {{ partial "icons/en.svg" . | strings.TrimSpace | safeHTML }}{{ end -}}
{{- end -}}
{{- break -}}
{{- end -}}
{{- end -}}