Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page locale #4862

Merged
merged 4 commits into from
Jun 15, 2024
Merged

Page locale #4862

merged 4 commits into from
Jun 15, 2024

Conversation

suhlig
Copy link
Contributor

@suhlig suhlig commented May 30, 2024

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 #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's lang attribute.

Fallback to site.locale is present where applicable.

This PR has an associated commit that writes the site locale (lang attribute of the html 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 following html element:

<html lang="en-US" ...>

A page may specify that its content is written in German:

---
title: Eine Seite in Deutsch
locale: de_DE
---

Das ist der Inhalt...

With this PR, the rendered HTML looks like this:

<html lang="en-US"...>
<article class="page" ... lang="de-DE">
  <h1>Eine Seite in Deutsch</h1>
  ...

Everything is still being treated as written in the site's locale en-US, but this one page declares its main content correctly as de-DE.

The W3C [recommends](https://www.w3.org/International/questions/qa-html-language-declarations) to specify language using identifiers as per [RFC 5646](https://tools.ietf.org/html/rfc5646) which uses dashes.
Allows a page to override the site locale for this one page.
@iBug
Copy link
Collaborator

iBug commented Jun 9, 2024

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?

@suhlig
Copy link
Contributor Author

suhlig commented Jun 9, 2024

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.

@iBug
Copy link
Collaborator

iBug commented Jun 9, 2024

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.

@suhlig
Copy link
Contributor Author

suhlig commented Jun 9, 2024

Makes sense. I'll update the PR.

@suhlig
Copy link
Contributor Author

suhlig commented Jun 14, 2024

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.

_includes/archive-single.html Outdated Show resolved Hide resolved
@iBug iBug merged commit b82680b into mmistakes:master Jun 15, 2024
1 check passed
minyoongi96 pushed a commit to minyoongi96/minyoongi96.github.io that referenced this pull request Aug 26, 2024
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