-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use disclosure widget for language selection
- Loading branch information
Showing
6 changed files
with
102 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<nav class="idg-language-picker" aria-labelledBy="idg-language-button"> | ||
<button id="idg-language-button" aria-expanded="false" aria-controls="idg-language-list">{{ _("Language") }}</button> | ||
<ul id="idg-language-list"> | ||
{% localeLink locale, translationKey, category, collections %} | ||
</ul> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
"use strict"; | ||
|
||
const config = require("../_data/config.json"); | ||
const i18n = require("eleventy-plugin-i18n-gettext"); | ||
|
||
module.exports = (locale, translationKey, category, collection) => { | ||
let output = ""; | ||
for (let language in config.languages) { | ||
if (locale && locale !== language) { | ||
|
||
if (locale) { | ||
for (let language in config.languages) { | ||
let langProps = config.languages[language]; | ||
if (category && collection) { | ||
let attrs = locale === language ? "aria-current=\"page\"" : ""; | ||
let url = language === config.defaultLanguage ? "/" : `/${langProps.slug}`; | ||
|
||
if (category && collection && translationKey) { | ||
let matchedPage = collection[`${category}_${language}`].find(page => page.fileSlug === translationKey); | ||
if (matchedPage) { | ||
output += `<a href="${matchedPage.url}">${langProps.name}</a>`; | ||
url = matchedPage.url; | ||
} | ||
} else { | ||
output += `<a href="/${language === config.defaultLanguage ? "" : langProps.slug}">${langProps.name}</a>`; | ||
} | ||
|
||
output += `<li><a href="${url}" ${attrs}>${langProps.name}</a></li>`; | ||
} | ||
} | ||
|
||
return output ? `<nav class="idg-locale" aria-label="${i18n._(locale, "Language")}">${output}</nav>` : output; | ||
return output; | ||
}; |