Unbreak the scopes-for-oauth-apps markdown table in translations (#40366)

This commit is contained in:
Peter Bengtsson 2023-08-09 09:56:42 -04:00 коммит произвёл GitHub
Родитель 173e0b14d7
Коммит 8adab0e825
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 31 добавлений и 2 удалений

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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(