Skip to content

Commit 8adab0e

Browse files
authored
Unbreak the scopes-for-oauth-apps markdown table in translations (#40366)
1 parent 173e0b1 commit 8adab0e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/correct-translation-content.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* It looks for easy "low hanging fruit" that we can correct for.
88
*
99
*/
10-
export function correctTranslatedContentStrings(content, englishContent, debug = false) {
10+
export function correctTranslatedContentStrings(content, englishContent, context = {}) {
1111
// A lot of translations have corruptions around the AUTOTITLE links.
1212
// We've requested that these are corrected back but as a temporary
1313
// solution we'll manually recover now.
@@ -86,5 +86,31 @@ export function correctTranslatedContentStrings(content, englishContent, debug =
8686
// are suddenly gone.
8787
content = content.replaceAll(' | | ', ' |\n| ')
8888

89+
// This is a bit of a hack, but it works.
90+
// It looks for patterns like this:
91+
//
92+
// Some words --------|-------|{
93+
//
94+
// And from that it tries to convert it to:
95+
//
96+
// Some words
97+
// --------|-------|{
98+
//
99+
// But because it's quite a broad solution specifically around any
100+
// Markdown table syntax, let's be extra careful and only apply it
101+
// to the select few pages with known problems.
102+
if (context.relativePath?.endsWith('scopes-for-oauth-apps.md')) {
103+
if (context.code === 'pt') {
104+
// As of Aug 2023, the Portuguese translation seems to have lost the
105+
// `|` characters in their Markdown table syntax.
106+
content = content.replace(/(\w)(\s-+\s-+\s){%/g, (whole, start, rest) => {
107+
return `${start}\n${rest.replace(/\s/g, '|')}`
108+
})
109+
}
110+
content = content.replace(/(\S\s*)(--+\|--+\|{)/, (whole, start, rest) => {
111+
return `${start}\n${rest}`
112+
})
113+
}
114+
89115
return content
90116
}

lib/page-data.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ async function translateTree(dir, langObj, enTree) {
150150
)
151151

152152
// The "content" isn't a frontmatter key
153-
translatedData.markdown = correctTranslatedContentStrings(content, enPage.markdown)
153+
translatedData.markdown = correctTranslatedContentStrings(content, enPage.markdown, {
154+
relativePath,
155+
code: langObj.code,
156+
})
154157

155158
item.page = new Page(
156159
Object.assign(

0 commit comments

Comments
 (0)