Enable the language switcher and fix URLs copied from the English config - #80
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Quantecon Book Theme language-switcher configuration to the Chinese edition’s Sphinx theme options so the UI switcher (and theme-provided hreflang alternates) can be rendered correctly with 中文 marked active.
Changes:
- Add a
languageslist (en/fa/fr/zh-cn) underhtml_theme_options. - Set
current_language: zh-cnto activate the Chinese entry in the switcher.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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>
This was referenced Aug 3, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related changes: enable the language switcher, and stop this edition advertising itself as the English site. The second is a prerequisite for the first to be worth anything, which is why they are together — see below.
1. Language switcher
Adds the switcher configuration to
html_theme_options, mirroring QuantEcon/lecture-python-programming#490 which adds the same block to the English source.enfafrzh-cncurrent_language: zh-cn, so this edition renders as active. English stays first because the theme useslanguages[0]as thehreflangx-defaulttarget.This does not propagate from the English source: the sync workflows trigger only on
lectures/**/*.mdandlectures/_toc.yml, so_config.ymlnever reaches a sync run, and each edition needs its owncurrent_languageanyway.2. URLs copied from the English config
Four settings appear to have been copied from the English
_config.ymland never updated, with the effect that this edition presented itself as the English site:html.baseurlcanonicalandog:urldeclaring it a duplicate of the English pagerepository_urlnb_repository_urltojupyter_urlpath/_image_urlpathbaseurland the twotojupyterpaths now use this edition's GitHub Pages address, which is where it is hosted while the broader URL structure is worked out.repository_urlpoints here.nb_repository_urlis dropped rather than repointed:lecture-python-programming.zh-cn.notebooksdoes not exist. Replaced with the same explanatory comment thefredition already carries; the theme omits notebook-launch links when the option is unset, which is how.frruns in production today.The canonical is the one that interacts with part 1. An
hreflangcluster asserting the Chinese version lives here, on pages that simultaneously declare themselves the English page, is incoherent — search engines resolve it by preferring the canonical, so the annotations would have been discounted. Fixing the canonical is what makes the switcher's SEO half function.Verification
Built locally against the theme:
hreflangalternates inject, includingx-default→ en.canonicalandog:urlnow readhttps://quantecon.github.io/lecture-python-programming.zh-cn/{page}.html, matching this edition's ownhreflangself-reference.No environment change needed. This repo pins
quantecon-book-theme==0.20.0, and I confirmed against the v0.20.0 tag that it already carries thelanguages/current_languageoptions and the switcher andhreflangtemplate code. Moving to 0.21.0 to match the other editions is worth doing separately.Note
Nothing here changes a live page until a
publish*tag is pushed. This edition last published on 2026-06-19.