Add language switcher support for fa, fr and zh-cn editions - #490
Conversation
4c4ed45 to
4d35290
Compare
There was a problem hiding this comment.
Pull request overview
Adds multi-language switcher configuration to the Jupyter Book theme settings so the site can link between the English, Farsi, and Simplified Chinese builds (and emit corresponding hreflang alternates).
Changes:
- Adds
languagesentries (en, fa, zh-cn) undersphinx.config.html_theme_options. - Sets
current_language: ento mark the English build as active.
|
Heads-up: French now exists and this PR does not include it.
Not asking for a rewrite here — flagging it so the gap is a decision rather than an oversight. Two things worth knowing if French is added:
Tracked in QuantEcon/project-translation#3 (rollout) — happy to add French here once the site is published, or to leave it for a follow-up. |
Add `languages` and `current_language` to `html_theme_options` to enable the language switcher (globe icon) and SEO hreflang tags provided by quantecon-book-theme. Main already ships the 0.21.0 theme, so no environment change is needed here. Languages: - English (en) — https://python-programming.quantecon.org - فارسی (fa) — https://quantecon.github.io/lecture-python-programming.fa - 中文 (zh-cn) — https://quantecon.github.io/lecture-python-programming.zh-cn Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The .fr edition went live on 2026-07-17 at the default Pages URL, with no custom domain to reconcile. That resolves the deferral recorded on this PR in July, when French was left out because the site was not yet published and its URL would have been a guess. See the rollout tracker QuantEcon/project-translation#3. Ordered alphabetically by code after English; English stays first because the theme uses languages[0] for the hreflang x-default. Verified with a local build against quantecon-book-theme 0.21.0: the switcher lists all four languages with English active, and the hreflang alternates — including x-default — inject on every page. All 26 shared lecture pages resolve on the .fr site; polars is not yet synced there, as is also the case for .fa and .zh-cn. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
4d35290 to
b5f3ad1
Compare
|
French added, branch rebased, and re-validated against a fresh build. Following up on the July heads-up above: the condition it named for deferring French no longer holds. What changedRebased onto current No theme upgrade needed
Validation against the new previewThe previous Netlify preview had expired, so this was re-checked end to end on the rebuilt one. Every page carries the switcher and a complete set of five One detail worth recording: in the deployed build the English switcher link is post-processed to the extensionless form Live URL checks: all four configured URLs return 200. Of the 27 lecture pages, 26 resolve on each of Follow-up, not blocking this PRNone of the three translation sites currently emit a switcher or reciprocal |
|
Correcting the
The 404s are publish cadence. Every repo in this series publishes only when someone pushes a Practical consequence for this PR: unchanged, still fine to merge. But the switcher will advertise Tracked as QuantEcon/action-translation#239, which asks for a scheduled check so this condition is detected rather than found by hand. |
Mirrors QuantEcon/lecture-python-programming#490, which adds the same block to the English source. Lists all four editions with current_language set to fa so this edition renders as active, and injects the hreflang alternates for the set. English stays first in the list because the theme uses languages[0] as the hreflang x-default target. Verified with a local build against the theme: the switcher lists all four languages with fa active. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Mirrors QuantEcon/lecture-python-programming#490, which adds the same block to the English source. Lists all four editions with current_language set to fr so this edition renders as active, and injects the hreflang alternates for the set. English stays first in the list because the theme uses languages[0] as the hreflang x-default target. Verified with a local build against the theme: the switcher lists all four languages with fr active. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Mirrors QuantEcon/lecture-python-programming#490, which adds the same block to the English source. Lists all four editions with current_language set to zh-cn so this edition renders as active, and injects the hreflang alternates for the set. English stays first in the list because the theme uses languages[0] as the hreflang x-default target. Verified with a local build against the theme: the switcher lists all four languages with zh-cn active. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…fig (#80) * Enable the language switcher for the Chinese edition Mirrors QuantEcon/lecture-python-programming#490, which adds the same block to the English source. Lists all four editions with current_language set to zh-cn so this edition renders as active, and injects the hreflang alternates for the set. English stays first in the list because the theme uses languages[0] as the hreflang x-default target. Verified with a local build against the theme: the switcher lists all four languages with zh-cn active. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Point the site and repository URLs at this edition, not the English one Four settings were copied from the English config and never updated, so this edition advertised itself as the English site: - baseurl was https://python-programming.quantecon.org/, making every page emit a canonical and og:url declaring it a duplicate of the corresponding English page - repository_url sent "View Source" to the English repository - nb_repository_url pointed at the English notebooks - both tojupyter paths resolved notebook and image links to the English site baseurl and the tojupyter paths now use this edition's GitHub Pages address, which is where it is hosted while the broader URL structure is decided. repository_url points here. nb_repository_url is dropped rather than repointed, since no zh-cn notebooks repository exists; this mirrors the comment the fr edition already uses. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Enable the language switcher for the Farsi edition Mirrors QuantEcon/lecture-python-programming#490, which adds the same block to the English source. Lists all four editions with current_language set to fa so this edition renders as active, and injects the hreflang alternates for the set. English stays first in the list because the theme uses languages[0] as the hreflang x-default target. Verified with a local build against the theme: the switcher lists all four languages with fa active. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Point the site URLs at the GitHub Pages address actually served baseurl claimed https://python-programming-fa.quantecon.org/, a host that does not resolve, so every page emitted a canonical and og:url to a dead address while the site serves from github.io. The two tojupyter paths carried the same dead host. This edition is hosted at its GitHub Pages URL while the broader URL structure is decided, so the config now says so. Also drops nb_repository_url, which pointed at lecture-python-programming.fa.notebooks — a repository that does not exist. Mirrors the comment the fr edition already uses; the theme skips notebook-launch links when the option is unset. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Mirrors QuantEcon/lecture-python-programming#490, which adds the same block to the English source. Lists all four editions with current_language set to fr so this edition renders as active, and injects the hreflang alternates for the set. English stays first in the list because the theme uses languages[0] as the hreflang x-default target. Verified with a local build against the theme: the switcher lists all four languages with fr active. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Changes
Add the language switcher configuration to
html_theme_optionsinlectures/_config.yml:enfafrzh-cnwith
current_language: en. This enables the language switcher globe icon in the bottom toolbar and injects SEOhreflangtags for all configured languages.Languages are ordered alphabetically by code after English. English stays first because the theme uses
languages[0]as thehreflangx-defaulttarget.French
French was deliberately left out when this PR was first opened, because
.frhad no published site and its URL would have been a guess. Both conditions have since been resolved: the.fredition went live on 2026-07-17 at the default Pages URL with no custom domain, which settles the Deferred item on the rollout tracker QuantEcon/project-translation#3 — the one that said to decide the Pages URL before wiring the switcher. French is therefore included here rather than left to a follow-up.No environment change needed
mainalready shipsquantecon-book-theme==0.21.0(bumped in #558), which provides the switcher. 0.21.0 is the latest release on both GitHub Releases and PyPI, so no theme upgrade is required. This branch has been rebased onto currentmain, so it remains a single-file_config.ymlchange.Verification
Verified against
quantecon-book-theme==0.21.0with a local build using this file'shtml_theme_optionsparsed verbatim:aria-current="true"andclass="active".hreflangalternates inject on every page, includingx-default→ en._process_languages(). Because the theme callsurl.rstrip("/")and always appends{pagename}.html, a bare root URL is never emitted — this is why the configured URLs carry no trailing slash, per the Copilot review threads above.Live URL checks: all four configured URLs return 200, and 26 of the 27 lecture pages resolve on each of the
.fa,.frand.zh-cnsites. The exception ispolars, added recently in #408 and not yet synced to any translation edition; its switcher links andhreflangalternates will 404 until each edition picks it up.Follow-up, not blocking
None of the
.fa,.fror.zh-cnsites currently emit a switcher or reciprocalhreflang, and all three serve<html lang="en">.hreflangannotations are most effective when bidirectional. Each of those repos already pins a theme version supporting the switcher (fa and fr on 0.21.0, zh-cn on 0.20.0), so each needs only the equivalent config block with its owncurrent_language.Ref: https://github.com/QuantEcon/quantecon-book-theme/releases/tag/v0.20.0