Repository navigation
feat(markdown-alert): localize alert titles for Traditional Chinese - #137
Merged
Merged
Conversation
## Why Markdown alerts show English titles such as `Note` on Traditional Chinese pages like `/zh/hk-tunnels-tolls/`. The site already sets the page language on `<html lang>` during static export in `src/pages/_document.tsx` and during client navigation in `src/pages/_app.tsx`. Reading `<html lang>` in CSS keeps every page in sync without passing a locale argument to `parseMarkdown`. ## What changed The change spans three files. - `src/remark-github-alerts/index.ts` adds `markdown-alert-title-default` to default alert title paragraphs and wraps the English text in `<span class="markdown-alert-title-text">`. Custom inline titles and `options.titles` overrides still render as plain text without those classes. CSS localization then leaves author-written titles untouched. - `src/styles/markdown-alert/github-i18n.css` defines Traditional Chinese titles (`備註`, `提示`, `重要`, `警告`, and `注意`) and sets `--markdown-alert-title-text-display` to `none` on matching `<html>` elements. The selector matches `[lang="zh" i]`, `:lang(zh-Hant)`, `:lang(zh-HK)`, `:lang(zh-TW)`, and `:lang(zh-MO)`. That selector covers every Traditional Chinese page on the site without matching `zh-CN` or `zh-Hans`. Using CSS avoids a flash of English text on static exports and updates immediately when `document.documentElement.lang` changes. Keeping all i18n rules in `src/styles/markdown-alert/github-i18n.css` leaves `src/styles/markdown-alert/github-base.css` untouched. - `src/pages/_app.tsx` imports `src/styles/markdown-alert/github-i18n.css` next to the other `markdown-alert` stylesheets. Every route loads the localized alert rules globally. ## Screenshots | Traditional Chinese (`<html lang="zh-HK">`) | English (`<html lang="en">`) | | --- | --- | | <img width="420" alt="Traditional Chinese markdown alert showing 備註 on /zh/hk-tunnels-tolls/" src="https://gist.githubusercontent.com/JaylyDev/e742895506cc3c3f32e8e3197edc4be2/raw/bee588f28dd17e17883157bb1f35ae6e04c2e008/markdown-alert-zh-hk.png" /> | <img width="420" alt="English markdown alert showing Note on /hk-tunnels-tolls/" src="https://gist.githubusercontent.com/JaylyDev/e742895506cc3c3f32e8e3197edc4be2/raw/bee588f28dd17e17883157bb1f35ae6e04c2e008/markdown-alert-en.png" /> |
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.
Why
Markdown alerts show English titles such as
Noteon Traditional Chinese pages like/zh/hk-tunnels-tolls/. The site already sets the page language on<html lang>during static export insrc/pages/_document.tsxand during client navigation insrc/pages/_app.tsx. Reading<html lang>in CSS keeps every page in sync without passing a locale argument toparseMarkdown.What changed
The change spans three files.
src/remark-github-alerts/index.tsaddsmarkdown-alert-title-defaultto default alert title paragraphs and wraps the English text in<span class="markdown-alert-title-text">. Custom inline titles andoptions.titlesoverrides still render as plain text without those classes. CSS localization then leaves author-written titles untouched.src/styles/markdown-alert/github-i18n.cssdefines Traditional Chinese titles (備註,提示,重要,警告, and注意) and sets--markdown-alert-title-text-displaytononeon matching<html>elements. The selector matches[lang="zh" i],:lang(zh-Hant),:lang(zh-HK),:lang(zh-TW), and:lang(zh-MO). That selector covers every Traditional Chinese page on the site without matchingzh-CNorzh-Hans. Using CSS avoids a flash of English text on static exports and updates immediately whendocument.documentElement.langchanges. Keeping all i18n rules insrc/styles/markdown-alert/github-i18n.cssleavessrc/styles/markdown-alert/github-base.cssuntouched.src/pages/_app.tsximportssrc/styles/markdown-alert/github-i18n.cssnext to the othermarkdown-alertstylesheets. Every route loads the localized alert rules globally.Screenshots
<html lang="zh-HK">)<html lang="en">)