diff --git a/.eleventy.js b/.eleventy.js index 9a02e4b..df43924 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -11,6 +11,9 @@ module.exports = function(eleventyConfig) { "node_modules/@fortawesome/fontawesome-free/webfonts/": "font", "node_modules/flag-icon-css/flags/4x3/(de|us)*": "flags" }); + eleventyConfig.addShortcode("translatedUrl", function(currentLocale, newLocale) { + return this.page.url.replace(new RegExp(`\/${currentLocale}\/`), `/${newLocale}/`); + }); return { dir: { diff --git a/src/_includes/layouts/base.njk b/src/_includes/layouts/base.njk index fd358e0..98618b1 100644 --- a/src/_includes/layouts/base.njk +++ b/src/_includes/layouts/base.njk @@ -43,14 +43,8 @@ title: sp-codes
{% for language in site.languages %} - {% set translatedUrl = "/" + language.code + "/" %} - {% for item in collections.all %} - {% if item.data.key == key and item.data.locale == language.code and not item.data.hidden %} - {% set translatedUrl = item.url %} - {% endif %} - {% endfor%}
- +
@@ -74,20 +68,15 @@ title: sp-codes
{% for language in site.languages %} - {% set translatedUrl = "/" + language.code + "/" %} - {% for item in collections.all %} - {% if item.data.key == key and item.data.locale == language.code and not item.data.hidden %} - {% set translatedUrl = item.url %} - {% endif %} - {% endfor%}
- +
{% endfor %}
+

{{url}}

{{ content | safe }} @@ -96,7 +85,7 @@ title: sp-codes