-
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?
Changes from 6 commits
919f2cd
b84234f
0863c00
5fb0a70
bc677ff
1f95108
934b99e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,8 @@ | ||||||||||||||
<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 %} #} | ||||||||||||||
{% set siteLang = site.locale|default('en')|trans %} | ||||||||||||||
<a class="logo-link" href="{% block homepage_link %}/{% endblock %}" hreflang="{{ siteLang }}"> | ||||||||||||||
<span class="logo"> | ||||||||||||||
<img src="{{ absolute_url(asset('w3c/w3c-no-bars.svg', 'logos')) }}" alt="{{ 'header.logo_alt'|trans({}, 'w3c_website_templates_bundle') }}" role="img"/> | ||||||||||||||
</span> | ||||||||||||||
|
@@ -11,7 +13,25 @@ | |||||||||||||
<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> | ||||||||||||||
{% if navItem.targetLinkLanguage is not empty %} | ||||||||||||||
{% set targetLangLabel = '' %} | ||||||||||||||
{% set langDiff = false %} | ||||||||||||||
{% if navItem.targetLinkLanguage is not same as siteLang %} | ||||||||||||||
{% set langDiff = true %} | ||||||||||||||
|
||||||||||||||
{% if navItem.targetLinkLanguage == 'zh-Hans' %} | ||||||||||||||
{% set targetLangLabel = "Chinese" %} | ||||||||||||||
{% else %} | ||||||||||||||
{% set targetLangLabel = "English" %} | ||||||||||||||
{% endif %} | ||||||||||||||
{% endif %} | ||||||||||||||
{% endif %} | ||||||||||||||
<a href="{{ navItem.titleLink }}" class="nav-link"{% if langDiff is defined and langDiff %} hreflang="{{ navItem.targetLinkLanguage }}"{% endif %}> | ||||||||||||||
{{ navItem.title }} | ||||||||||||||
{% if navItem.targetLinkLanguage is not empty %} | ||||||||||||||
{{ (langDiff is defined and langDiff) ? '(' ~ targetLangLabel ~ ')' : '' }} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the target language is different from the current one, you chose to display it as "(Language)". Do you think it should be styled to be less prominent? https://www.w3.org/International/questions/qa-link-lang suggests some CSS, that, despite not being accessible (at least because of the contrast ratio), makes that less "in your face". It also suggests adding the language through CSS content rather than in the markup, but I don't know what are the implications of one or the other. |
||||||||||||||
{% endif %} | ||||||||||||||
</a> | ||||||||||||||
<div class="nav__submenu" data-nav="submenu" style="display: none;"> | ||||||||||||||
<div class="l-center"> | ||||||||||||||
<div class="nav__submenu__intro"> | ||||||||||||||
|
@@ -29,7 +49,26 @@ | |||||||||||||
<ul> | ||||||||||||||
{%~ for child in navItem.children %} | ||||||||||||||
<li{{ child.startNewColumn is defined and child.startNewColumn ? ' class="break-after"' : '' }}>{# -#} | ||||||||||||||
<a href="{{ child.url }}">{{ child.title }}</a>{# -#} | ||||||||||||||
|
||||||||||||||
{% if child.targetLinkLanguage is not empty %} | ||||||||||||||
{% set childLangDiff = siteLang != child.targetLinkLanguage %} | ||||||||||||||
{% set targetLangLabel = '' %} | ||||||||||||||
|
||||||||||||||
{% if childLangDiff == true %} | ||||||||||||||
{% if child.targetLinkLanguage == 'zh-Hans' %} | ||||||||||||||
{% set targetLangLabel = "Chinese" %} | ||||||||||||||
{% else %} | ||||||||||||||
{% set targetLangLabel = "English" %} | ||||||||||||||
{% endif %} | ||||||||||||||
|
{% if child.targetLinkLanguage == 'zh-Hans' %} | |
{% set targetLangLabel = "Chinese" %} | |
{% else %} | |
{% set targetLangLabel = "English" %} | |
{% endif %} | |
{% set targetLangLabel = child.targetLinkLanguage|replace('-', '_')|language_name(siteLang) %} |
Note that I replace - with _ because language_name seems to expect 'zh_Hans' instead of 'zh-Hans'
Uh oh!
There was an error while loading. Please reload this page.
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.
See my previous comment on how to make this more generic