Skip to content

Enable the language switcher and fix URLs copied from the English config - #80

Merged
mmcky merged 2 commits into
mainfrom
add-language-switcher
Aug 3, 2026
Merged

Enable the language switcher and fix URLs copied from the English config#80
mmcky merged 2 commits into
mainfrom
add-language-switcher

Conversation

@mmcky

@mmcky mmcky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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.

Code Name URL
en English https://python-programming.quantecon.org
fa فارسی https://quantecon.github.io/lecture-python-programming.fa
fr Français https://quantecon.github.io/lecture-python-programming.fr
zh-cn 中文 https://quantecon.github.io/lecture-python-programming.zh-cn

current_language: zh-cn, so this edition renders as active. English stays first because the theme uses languages[0] as the hreflang x-default target.

This does not propagate from the English source: the sync workflows trigger only on lectures/**/*.md and lectures/_toc.yml, so _config.yml never reaches a sync run, and each edition needs its own current_language anyway.

2. URLs copied from the English config

Four settings appear to have been copied from the English _config.yml and never updated, with the effect that this edition presented itself as the English site:

Setting Was Effect
html.baseurl the English site every page emitted a canonical and og:url declaring it a duplicate of the English page
repository_url the English repo "View Source" sent Chinese readers and editors to the English repository
nb_repository_url the English notebooks repo notebook links pointed at English notebooks
tojupyter_urlpath / _image_urlpath the English site generated notebooks resolved their links and images against the English site

baseurl and the two tojupyter paths now use this edition's GitHub Pages address, which is where it is hosted while the broader URL structure is worked out. repository_url points here.

nb_repository_url is dropped rather than repointed: lecture-python-programming.zh-cn.notebooks does not exist. Replaced with the same explanatory comment the fr edition already carries; the theme omits notebook-launch links when the option is unset, which is how .fr runs in production today.

The canonical is the one that interacts with part 1. An hreflang cluster 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:

  • The switcher lists all four languages with 中文 active.
  • hreflang alternates inject, including x-default → en.
  • canonical and og:url now read https://quantecon.github.io/lecture-python-programming.zh-cn/{page}.html, matching this edition's own hreflang self-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 the languages/current_language options and the switcher and hreflang template 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.

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>
Copilot AI review requested due to automatic review settings August 3, 2026 01:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 languages list (en/fa/fr/zh-cn) under html_theme_options.
  • Set current_language: zh-cn to activate the Chinese entry in the switcher.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lectures/_config.yml
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>
@mmcky mmcky changed the title Enable the language switcher for the Chinese edition Enable the language switcher and fix URLs copied from the English config Aug 3, 2026
@mmcky
mmcky merged commit 5463111 into main Aug 3, 2026
2 checks passed
@mmcky
mmcky deleted the add-language-switcher branch August 3, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants