Skip to content

feat(galley): lang: sets the document language and its hyphenation - #11

Merged
apiad merged 2 commits into
mainfrom
8-lang
Oct 20, 2026
Merged

apiad merged 2 commits into
mainfrom
8-lang

Conversation

@apiad

@apiad apiad commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Fixes #8.

What changed

  • galley._lang() reads lang: from the frontmatter or scriptorium.yaml first, then from the theme's top-level lang:, and falls back to en. emit() and emit_deck() write the result into <html lang>, and WeasyPrint uses that attribute to pick its pyphen hyphenation dictionary. The value lands inside an HTML attribute, so anything that is not a BCP 47-shaped tag raises ValueError.
  • project.py carries lang through as a content key.
  • uh defaults to lang: es. Its description is already Spanish, and it exists for Universidad de La Habana documents. No other theme changes.
  • Docs: README, the authoring know-how, the CHANGELOG.

Measured

  • tests/test_lang.py has 5 new tests. They render 30 copies of "desarrollo" in a 12 mm column, which is narrower than the word, so the column has to hyphenate:
    • With the default, the English break desar‐ appears.
    • With lang: es, every break is one of de‐, desa‐, desarro‐, and desar‐ never appears.
    • The uh theme with no lang: key behaves like Spanish.
    • A lang in scriptorium.yaml reaches the render.
    • A value carrying a quote raises ValueError.
  • The first version of the fixture used a 19 mm column, and every test passed whatever lang was set, because each word fit on its own line. That is why the column is now 12 mm. With the lang entry removed from the project allowlist, the project test fails.
  • Full suite: 267 passed locally.

Note

This PR branches from main before #10, the CI workflow, so it gets no check run until #10 merges and this branch is rebased onto it.

🤖 Generated with Claude Code

apiad and others added 2 commits October 5, 2026 09:17
Every document was emitted as <html lang='en'>, so Spanish text hyphenated
with English patterns. Frontmatter or scriptorium.yaml `lang:` now sets it,
a theme can default it (uh -> es), and the fallback stays en.

Fixes #8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apiad
apiad merged commit e45e78a into main Oct 20, 2026
2 checks passed
@apiad
apiad deleted the 8-lang branch October 20, 2026 13:57
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.

Every document is tagged lang='en', so Spanish text hyphenates with English patterns

1 participant