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

merge en-US metadata with translated metadata #3955

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion kumascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
LiveSampleError,
} = require("./src/live-sample.js");
const { HTMLTool } = require("./src/api/util.js");
const { DEFAULT_LOCALE } = require("../libs/constants");

const DEPENDENCY_LOOP_INTRO =
'The following documents form a circular dependency when rendering (via the "page" and/or "IncludeSubnav" macros):';
Expand Down Expand Up @@ -51,7 +52,23 @@ const renderFromURL = async (
`Tried to find a folder called ${Document.urlToFolderPath(url)}`
);
}
const { rawBody, metadata, fileInfo, isMarkdown } = document;
let { metadata } = document;
// If we're rendering a translation, merge in the parent document's
// metadata into this metadata.
if (metadata.locale !== DEFAULT_LOCALE) {
const parentURL = url
.toLowerCase()
.replace(`/${metadata.locale.toLowerCase()}/`, `/${DEFAULT_LOCALE}/`);

const parentDocument = invalidateCache
? Document.findByURL(parentURL, Document.MEMOIZE_INVALIDATE)
: Document.findByURL(parentURL);
if (parentDocument) {
metadata = { ...parentDocument.metadata, ...metadata };
}
}

const { rawBody, fileInfo, isMarkdown } = document;
const rawHTML = isMarkdown ? await m2h(rawBody) : rawBody;
const [renderedHtml, errors] = await renderMacros(
rawHTML,
Expand Down
23 changes: 23 additions & 0 deletions testing/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,29 @@ test("content built French foo page", () => {
);
});

test("French translation using English front-matter bits", () => {
const builtFolder = path.join(
buildRoot,
"fr",
"docs",
"web",
"spec_section_extraction"
);
const jsonFile = path.join(builtFolder, "index.json");
const { doc } = JSON.parse(fs.readFileSync(jsonFile));
expect(doc.title).toBe("Extraction de sections de spécifications");
const specifications = doc.body.find(
(section) => section.type === "specifications"
);
expect(specifications.value.query).toBe(
"javascript.builtins.Array.toLocaleString"
);
const bcd = doc.body.find(
(section) => section.type === "browser_compatibility"
);
expect(bcd.value.query).toBe("javascript.builtins.Array.toLocaleString");
});

test("content built zh-TW page with en-US fallback image", () => {
const builtFolder = path.join(buildRoot, "zh-tw", "docs", "web", "foo");
const jsonFile = path.join(builtFolder, "index.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Extraction de sections de spécifications
slug: Web/Spec_Section_Extraction
---

<p>
The purpose of this fixture is to test that this translated document can
benefit from the <code>browser-compat</code> front-matter in it's en-US
parent.
</p>

<h2 id="Specifications">Spécifications</h2>

<p>{{Specifications}}</p>

<h2 id="Browser_compatibility">Compatibilité des navigateur</h2>

<p>{{Compat}}</p>