Closed suhlig closed 3 weeks ago
Nice job. Can this be changed so that when a page-level override isn't present, it won't emit the lang
attribute at all?
Hmm, I did not think about it that way. My thought was that we always know the language (at least the default system fallback would be available).
But if it's a blocker to merging the PR I can certainly make that change.
My take on this is that it's a per-page settings override, so the lang
tag need not be present if nothing was overridden. A secondary reason is to keep the changes at a minimal level for existing users, such that the output HTML doesn't change unnecessarily across theme versions.
Makes sense. I'll update the PR.
I pushed another commit that emits the lang attribute only if page.locale
is set. I marked it as fixup so that it stays separate while we are discussing it, but at rebase time it should probably be squashed with the previous one.
This is a feature.
Summary
This PR allows for a page to specify a content
locale
that is used only for that one page.Compared to the similar PR https://github.com/mmistakes/minimal-mistakes/pull/4679, this set of changes is relatively small, as I am not going for localising anything. Instead, the focus is on expressing the actual locale of the content, as it is written in the page and declared as
locale
in the front matter, in the containing element'slang
attribute.Fallback to
site.locale
is present where applicable.This PR has an associated commit that writes the site locale (
lang
attribute of thehtml
element) in the style the W3C recommends (language and region separated by dash), instead of just cutting off the region. Let me know if you'd prefer this one as a separate PR.Context
I am running my blog mostly in English, but a few pages are in German. I am running a spell checker across all pages before publishing them, and having an accurate locale on each page is crucial for that.
Example
A site that has
locale: en_US
in its_config.yaml
generates the followinghtml
element:A page may specify that its content is written in German:
With this PR, the rendered HTML looks like this:
Everything is still being treated as written in the site's locale
en-US
, but this one page declares its main content correctly asde-DE
.