-
Notifications
You must be signed in to change notification settings - Fork 14
Add check against site language to navItem language to determine href… #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -1,6 +1,7 @@ | |||
<nav id="global-nav" aria-label="Main"> | |||
<div class="global-nav__inner l-center"> | |||
<a class="logo-link" href="{% block homepage_link %}/{% endblock %}" hreflang="{% block homepage_hreflang %}en{% endblock %}"> | |||
{% set siteLang %} {% block homepage_hreflang %}en{% endblock %} {% endset %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the block is useful here.
{% set siteLang %} {% block homepage_hreflang %}en{% endblock %} {% endset %} | |
{% set siteLang = site.locale|default('en') %} |
@@ -11,7 +12,9 @@ | |||
<ul data-component="nav-double-intro"> | |||
{%~ for navItem in navigation %} | |||
<li class="top-nav-item has-children"> | |||
<a href="{{ navItem.titleLink }}" class="nav-link">{{ navItem.title }}</a> | |||
{% set langDiff = siteLang is same as navItem.targetLinkLanguage ? false : true %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to:
{% set langDiff = siteLang is same as navItem.targetLinkLanguage ? false : true %} | |
{% set langDiff = siteLang != navItem.targetLinkLanguage %} |
<a href="{{ navItem.titleLink }}" class="nav-link">{{ navItem.title }}</a> | ||
{% set langDiff = siteLang is same as navItem.targetLinkLanguage ? false : true %} | ||
{% if navItem.language is defined %}{{ navItem.language }}{% endif %} | ||
<a href="{{ navItem.titleLink }}" class="nav-link"{% if langDiff %}hreflang="{{ navItem.targetLinkLanguage }}"{% endif %}>{{ navItem.title }}</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space mising:
<a href="{{ navItem.titleLink }}" class="nav-link"{% if langDiff %}hreflang="{{ navItem.targetLinkLanguage }}"{% endif %}>{{ navItem.title }}</a> | |
<a href="{{ navItem.titleLink }}" class="nav-link"{% if langDiff %} hreflang="{{ navItem.targetLinkLanguage }}"{% endif %}>{{ navItem.title }}</a> |
@@ -28,8 +31,9 @@ | |||
{% if navItem.children is defined and navItem.children|length > 0 -%} | |||
<ul> | |||
{%~ for child in navItem.children %} | |||
{% set childLangDiff = siteLang is same as child.targetLinkLanguage ? false : true %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified:
{% set childLangDiff = siteLang is same as child.targetLinkLanguage ? false : true %} | |
{% set childLangDiff = siteLang != child.targetLinkLanguage %} |
<li{{ child.startNewColumn is defined and child.startNewColumn ? ' class="break-after"' : '' }}>{# -#} | ||
<a href="{{ child.url }}">{{ child.title }}</a>{# -#} | ||
<a href="{{ child.url }}{% if childLangDiff %}hreflang="{{ child.targetLinkLanguage }}"{% endif %}">{{ child.title }}</a>{# -#} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space and wrong quoting:
<a href="{{ child.url }}{% if childLangDiff %}hreflang="{{ child.targetLinkLanguage }}"{% endif %}">{{ child.title }}</a>{# -#} | |
<a href="{{ child.url }}"{% if childLangDiff %} hreflang="{{ child.targetLinkLanguage }}"{% endif %}>{{ child.title }}</a>{# -#} |
@@ -11,7 +12,9 @@ | |||
<ul data-component="nav-double-intro"> | |||
{%~ for navItem in navigation %} | |||
<li class="top-nav-item has-children"> | |||
<a href="{{ navItem.titleLink }}" class="nav-link">{{ navItem.title }}</a> | |||
{% set langDiff = siteLang is same as navItem.targetLinkLanguage ? false : true %} | |||
{% if navItem.language is defined %}{{ navItem.language }}{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some debug information
{% if navItem.language is defined %}{{ navItem.language }}{% endif %} |
This ticket related to task w3c/w3c-website#517 It is currently being tested internall. We'll update the task & convert this PR to "Ready for review" once this is done. Sorry for any confusion on the status of this one. |
This pull request adds support for the "targetLinkLanguage" field that is added by a branch of the same name in the w3c-website-craft repo and the w3c-website-frontend repo
When it detects that the language of the current site (
siteLang
) is different from the value of thetargetLinkLanguage
field (if it's populated), it adds ahreflang
attribute to the relevant<a>
tag as well as some indicative text following the current text inside the<a>
tag.This has been tested locally and seems to be working as intended
How to test
ddev composer update
s on the frontend andddev craft project-config/apply
on the craft repoIf you would like to test this on another language, you can do the following:
Expected behaviour
If a navigation item has a Target Link Language that is different from the site language, it should have a
hreflang
in the markup for the anchor tag for that link, and there should be an indicator (in the Roman Alphabet / Romaji) of what language the target page is in. [e.g - Working Groups (Chinese)] or something similar.