diff --git a/lib/correct-translation-content.js b/lib/correct-translation-content.js index 05ae6fdd8c..f9c8ed1415 100644 --- a/lib/correct-translation-content.js +++ b/lib/correct-translation-content.js @@ -7,7 +7,7 @@ * It looks for easy "low hanging fruit" that we can correct for. * */ -export function correctTranslatedContentStrings(content, englishContent, debug = false) { +export function correctTranslatedContentStrings(content, englishContent, context = {}) { // A lot of translations have corruptions around the AUTOTITLE links. // We've requested that these are corrected back but as a temporary // solution we'll manually recover now. @@ -86,5 +86,31 @@ export function correctTranslatedContentStrings(content, englishContent, debug = // are suddenly gone. content = content.replaceAll(' | | ', ' |\n| ') + // This is a bit of a hack, but it works. + // It looks for patterns like this: + // + // Some words --------|-------|{ + // + // And from that it tries to convert it to: + // + // Some words + // --------|-------|{ + // + // But because it's quite a broad solution specifically around any + // Markdown table syntax, let's be extra careful and only apply it + // to the select few pages with known problems. + if (context.relativePath?.endsWith('scopes-for-oauth-apps.md')) { + if (context.code === 'pt') { + // As of Aug 2023, the Portuguese translation seems to have lost the + // `|` characters in their Markdown table syntax. + content = content.replace(/(\w)(\s-+\s-+\s){%/g, (whole, start, rest) => { + return `${start}\n${rest.replace(/\s/g, '|')}` + }) + } + content = content.replace(/(\S\s*)(--+\|--+\|{)/, (whole, start, rest) => { + return `${start}\n${rest}` + }) + } + return content } diff --git a/lib/page-data.js b/lib/page-data.js index 7030c0892e..7dddf09690 100644 --- a/lib/page-data.js +++ b/lib/page-data.js @@ -150,7 +150,10 @@ async function translateTree(dir, langObj, enTree) { ) // The "content" isn't a frontmatter key - translatedData.markdown = correctTranslatedContentStrings(content, enPage.markdown) + translatedData.markdown = correctTranslatedContentStrings(content, enPage.markdown, { + relativePath, + code: langObj.code, + }) item.page = new Page( Object.assign(