From 0428ef086c22ac8ff1c2abff6ca47e7ad2719d12 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 26 Sep 2024 01:10:29 +0200 Subject: [PATCH] book: when navigating to another language, find the corresponding section This addresses https://github.com/git/git-scm.com/issues/747. Signed-off-by: Johannes Schindelin --- layouts/partials/sidebar.html | 14 ++++++ layouts/partials/translated-chapter.html | 5 ++ layouts/partials/translations.html | 60 ++++++++++++------------ tests/git-scm.spec.js | 3 +- 4 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 layouts/partials/translated-chapter.html diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index a96cc0540a..919d6518e8 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -51,6 +51,20 @@ {{ if (eq .Params.Sidebar "book") }} + {{- /* If this page displays a section of the ProGit book, map all the translations thereof */ -}} + {{ with $.Page.Params.book }} + {{ $cs_number := .section.cs_number }} + {{ range $.Page.Site.Data.book }} + {{ $language_code := .language_code }} + {{ range .chapters }} + {{ range .sections }} + {{ if (eq .cs_number $cs_number) }} + {{ $.Scratch.SetInMap "translations" $language_code .url }} + {{ end }} + {{ end }} + {{ end }} + {{ end }} + {{ end }} {{ partial "translations.html" . }} {{ else if (and (ne $section "documentation") (ne $section "site")) }} diff --git a/layouts/partials/translated-chapter.html b/layouts/partials/translated-chapter.html new file mode 100644 index 0000000000..76ec9cfc6e --- /dev/null +++ b/layouts/partials/translated-chapter.html @@ -0,0 +1,5 @@ +{{- with (index (.ctx.Scratch.Get "translations") .lang) -}} + {{- relURL . -}} +{{- else -}} + {{- relURL (add "book/" .lang) -}} +{{- end -}} diff --git a/layouts/partials/translations.html b/layouts/partials/translations.html index 2cb786361c..eb945d16f3 100644 --- a/layouts/partials/translations.html +++ b/layouts/partials/translations.html @@ -1,49 +1,49 @@

This book is available in - English. + English.

Full translation available in - - - - - - - - - - - - - - + + + + + + + + + + + + + +
azərbaycan dili,
български език,
Deutsch,
Español,
Français,
Ελληνικά,
日本語,
한국어,
Nederlands,
Русский,
Slovenščina,
Tagalog,
Українська
简体中文,
azərbaycan dili,
български език,
Deutsch,
Español,
Français,
Ελληνικά,
日本語,
한국어,
Nederlands,
Русский,
Slovenščina,
Tagalog,
Українська
简体中文,

Partial translations available in - - - - - - + + + + + +
Čeština,
Македонски,
Polski,
Српски,
Ўзбекча,
繁體中文,
Čeština,
Македонски,
Polski,
Српски,
Ўзбекча,
繁體中文,

Translations started for - - - - - - - - - + + + + + + + + +
Беларуская,
فارسی,
Indonesian,
Italiano,
Bahasa Melayu,
Português (Brasil),
Português (Portugal),
Svenska,
Türkçe.
Беларуская,
فارسی,
Indonesian,
Italiano,
Bahasa Melayu,
Português (Brasil),
Português (Portugal),
Svenska,
Türkçe.

diff --git a/tests/git-scm.spec.js b/tests/git-scm.spec.js index 72c27c915d..4e890a9779 100644 --- a/tests/git-scm.spec.js +++ b/tests/git-scm.spec.js @@ -230,7 +230,8 @@ test('book', async ({ page }) => { // Navigate to the French translation await page.getByRole('link', { name: 'Français' }).click() await expect(page).toHaveURL(/book\/fr/) - await expect(page.getByRole('link', { name: 'Démarrage rapide' })).toBeVisible() + await expect(page.locator('.inner h1')).toHaveText(/Démarrage rapide/) + await expect(page.getByRole('link', { name: 'Démarrage rapide' })).not.toBeVisible() // the repository URL now points to the French translation await expect(page.getByRole('link', { name: 'hosted on GitHub' }))