{%- if page.lang-exclusive -%} {%- unless page.lang-exclusive contains lang -%} {%- continue -%} {%- comment -%}skip langs from dropdown list if not in lang-exclusive{%- endcomment -%} {%- endunless -%} {%- endif -%} {%- if page.permalink_lang[lang] -%} {%- assign localized_permalink = page.permalink_lang[lang] -%} {%- assign localized_permalink = localized_permalink | remove_first: "/" -%} {%- if lang == site.default_lang -%} {%- capture lang_href -%}/{{ localized_permalink }}{%- endcapture -%} {%- else -%} {%- capture lang_href -%}/{{ lang }}/{{ localized_permalink }}{%- endcapture -%} {%- endif -%} {%- else -%} {%- assign original_stubs = site.data[site.active_lang].links -%} {%- assign translated_stubs = site.data[lang].links -%} {%- assign localized_permalink = page.url -%} {%- for stub_pair in original_stubs -%} {%- assign key = stub_pair[0] -%} {%- assign original = stub_pair[1] -%} {%- assign translated = translated_stubs[key] -%} {%- assign localized_permalink = localized_permalink | replace: original, translated -%} {%- endfor -%} {%- comment -%}Handle autopage item_link translation{%- endcomment -%} {%- if page.pagination and (page.pagination.category or page.pagination.tag) -%} {%- comment -%} Identify autopage type and get the term {%- endcomment -%} {%- if page.pagination.category -%} {%- assign autopage_term = page.pagination.category -%} {%- assign collection_name = "blogcategories" -%} {%- elsif page.pagination.tag -%} {%- assign autopage_term = page.pagination.tag -%} {%- assign collection_name = "blogtags" -%} {%- endif -%} {%- comment -%} Find current document by term, then use page_id for cross-language matching {%- endcomment -%} {%- assign current_doc = nil -%} {%- for doc in site[collection_name] -%} {%- if doc.lang == site.active_lang and doc.page_id == autopage_term -%} {%- assign current_doc = doc -%} {%- break -%} {%- endif -%} {%- endfor -%} {%- comment -%} Find corresponding document in target language by page_id {%- endcomment -%} {%- if current_doc -%} {%- assign target_doc = "" | unfiltered: collection_name, lang | where: "page_id", current_doc.page_id | first -%} {%- comment -%} Replace item_link in URL if both documents have item_link {%- endcomment -%} {%- if target_doc and target_doc.item_link and current_doc.item_link -%} {%- assign localized_permalink = localized_permalink | replace: current_doc.item_link, target_doc.item_link -%} {%- endif -%} {%- endif -%} {%- endif -%} {%- comment -%} End autopage item_link translation{%- endcomment-%} {%- if site.active_lang == site.default_lang -%} {%- assign localized_permalink = localized_permalink | remove_first: "/" -%} {%- if lang == site.default_lang -%} {%- capture lang_href -%}/{{ localized_permalink }}{%- endcapture -%} {%- else -%} {%- capture lang_href -%}/{{ lang }}/{{ localized_permalink }}{%- endcapture -%} {%- endif -%} {%- else -%} {%- assign active_lang_prefix = '/' | append: site.active_lang | append: '/' -%} {%- assign localized_permalink = localized_permalink | replace_first: active_lang_prefix, '/' -%} {%- assign localized_permalink = localized_permalink | remove_first: "/" -%} {%- if lang == site.default_lang -%} {%- capture lang_href -%}/{{ localized_permalink }}{%- endcapture -%} {%- else -%} {%- capture lang_href -%}/{{ lang }}/{{ localized_permalink }}{%- endcapture -%} {%- endif -%} {%- endif -%} {%- endif -%} {%- comment -%} Clean up any double slashes {%- endcomment -%} {%- if lang_href contains '//' -%} {%- assign lang_href = lang_href | replace: '//', '/' -%} {%- endif -%} {%- comment -%} if url no resolve, hide flag for that lang{%- endcomment -%} {%- capture translation_exists -%}{%- file_exists {{ lang_href }}.html -%}{%- endcapture -%}