Page MenuHomePhabricator

Titles not translated when set in frontmatter
Open, MediumPublicBUG REPORT

Description

Expected behavior

If a translated string is available for the title of a page, the site should display the translated text whether the title is set in the frontmatter or using an h1 tag.

Observed behavior

Titles set in the frontmatter are always shown in English, even when a translated string is available. For example:

---
title: Get started
---

Workaround

Set all titles using #

Event Timeline

@bd808 I'm happy to just use the workaround to avoid this issue, unless you think this is an easy fix or indicative of other, undiscovered issues?

@bd808 I'm happy to just use the workaround to avoid this issue, unless you think this is an easy fix or indicative of other, undiscovered issues?

It should be fixable. The issue is that we are not currently treating values in the page metadata as translatable units. An open question at the moment is which event(s) we will need to use to capture the English as a unit and then replace that English with a translation. on_page_context seems like the most likely hook point for both on a quick examination. page.meta.title, page.meta.description, and page.meta.tags are all things we could think about localizing. I think title is the only one of these that we are actively using right now.

It would be nice to have the ability to localize page.meta.description to use in link previews. I tried to do some quick testing locally and it seems that the page description does get put into a <meta name="description"> tag, but the title is always in a <title> tag regardless of whether it is set in the frontmatter or in an h1

On further testing, it looks like the correct workaround is actually to remove the title from the frontmatter and set the page title in the navigation config. This works for everything except the homepage (since it isn't included in the navigation config) which still shows the English title at the top of the page after scrolling down:

Screen Shot 2022-04-25 at 2.48.35 PM.png (524×2 px, 104 KB)

While looking at the code I noticed that the plugin is currently extracting the page.title value and making a translation unit for it, but we are not doing anything to fetch that translation when rendering localized pages. This looks like an attempt by me in the past to cover this issue, but somehow I only addressed half of the problem.

Change 785962 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[wikimedia/developer-portal@main] i18n: Localize page metadata

https://gerrit.wikimedia.org/r/785962

bd808 changed the task status from Open to In Progress.Apr 26 2022, 12:43 AM
bd808 claimed this task.
bd808 triaged this task as Medium priority.

Change 785962 merged by jenkins-bot:

[wikimedia/developer-portal@main] i18n: Localize page metadata

https://gerrit.wikimedia.org/r/785962

In gerrit 785962 @apaskulin wrote:
This is working great for displaying the page title at the top of the page and in the header on scroll, but not in the sidebar nav. (See /es/get-started where it should have "Más información sobre la tecnología de Wikimedia" instead of "Learn about Wikimedia technology" in the sidebar.) Setting the title in the navigation config works fine as a workaround for this, so it's not a problem. But, I'm curious, is there a way to get the translated title into the nav by using a different event?

In gerrit 785962 @bd808 wrote:
There is an on_nav event. The translate_nav method is called from that hook to localize the explicit titles and urls already.

An open question is why this is not already working? I guess the nav.item.title value is not set when the title is inherited from the page markdown rather than explicit in the config? There must be some point where the title from the page is known for it to render anything...

I would like to at least understand why this happens...

bd808 changed the task status from In Progress to Open.May 6 2022, 11:31 PM
bd808 removed bd808 as the assignee of this task.Oct 26 2022, 5:55 PM