|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | + |
| 6 | +const WARNING_BANNERS = { |
| 7 | + 'es': `:::warning La traducción puede estar desactualizada |
| 8 | +La versión en inglés de este documento se actualizó recientemente. Es posible que esta traducción aún no refleje esos cambios. |
| 9 | +
|
| 10 | +¡Ayuda a mantener nuestras traducciones actualizadas! Si hablas este idioma con fluidez, considera revisar la [versión en inglés](ENGLISH_DOC_LINK) y actualizar esta traducción. |
| 11 | +::: |
| 12 | +
|
| 13 | +`, |
| 14 | + 'pt-BR': `:::warning A tradução pode estar desatualizada |
| 15 | +A versão em inglês deste documento foi atualizada recentemente. Esta tradução pode não refletir essas alterações ainda. |
| 16 | +
|
| 17 | +Ajude-nos a manter nossas traduções atualizadas! Se você é fluente neste idioma, considere revisar a [versão em inglês](ENGLISH_DOC_LINK) e atualizar esta tradução. |
| 18 | +::: |
| 19 | +
|
| 20 | +`, |
| 21 | +}; |
| 22 | + |
| 23 | +const DEFAULT_WARNING = `:::warning Translation May Be Outdated |
| 24 | +The English version of this document was recently updated. This translation may not reflect those changes yet. |
| 25 | +
|
| 26 | +Please help keep our translations up to date! If you're fluent in this language, consider reviewing the [English version](ENGLISH_DOC_LINK) and updating this translation. |
| 27 | +::: |
| 28 | +
|
| 29 | +`; |
| 30 | + |
| 31 | +const WARNING_MARKER = ':::warning'; |
| 32 | + |
| 33 | +const changedFilesPath = path.join(process.cwd(), 'changed_english_docs.txt'); |
| 34 | +if (!fs.existsSync(changedFilesPath)) { |
| 35 | + console.log('No changed English docs file found'); |
| 36 | + process.exit(0); |
| 37 | +} |
| 38 | + |
| 39 | +const changedEnglishDocs = fs.readFileSync(changedFilesPath, 'utf8') |
| 40 | + .trim() |
| 41 | + .split('\n') |
| 42 | + .filter(line => line.trim().length > 0); |
| 43 | + |
| 44 | +if (changedEnglishDocs.length === 0) { |
| 45 | + console.log('No changed English docs to process'); |
| 46 | + process.exit(0); |
| 47 | +} |
| 48 | + |
| 49 | +const i18nDir = path.join(process.cwd(), 'frontend', 'i18n'); |
| 50 | +if (!fs.existsSync(i18nDir)) { |
| 51 | + console.log('No i18n directory found'); |
| 52 | + process.exit(0); |
| 53 | +} |
| 54 | + |
| 55 | +const languages = fs.readdirSync(i18nDir).filter(item => { |
| 56 | + const itemPath = path.join(i18nDir, item); |
| 57 | + return fs.statSync(itemPath).isDirectory(); |
| 58 | +}); |
| 59 | + |
| 60 | +console.log(`Found ${languages.length} language directories: ${languages.join(', ')}`); |
| 61 | + |
| 62 | +let totalFilesMarked = 0; |
| 63 | +const markedFiles = []; |
| 64 | + |
| 65 | +changedEnglishDocs.forEach(englishDocPath => { |
| 66 | + const relativePath = englishDocPath.replace('frontend/docs/', ''); |
| 67 | + const englishDocLink = `/docs/${relativePath.replace('.md', '')}`; |
| 68 | + |
| 69 | + console.log(`\nProcessing: ${englishDocPath}`); |
| 70 | + console.log(` Relative path: ${relativePath}`); |
| 71 | + |
| 72 | + languages.forEach(lang => { |
| 73 | + const translationPath = path.join( |
| 74 | + i18nDir, |
| 75 | + lang, |
| 76 | + 'docusaurus-plugin-content-docs', |
| 77 | + 'current', |
| 78 | + relativePath |
| 79 | + ); |
| 80 | + |
| 81 | + if (!fs.existsSync(translationPath)) { |
| 82 | + console.log(` [${lang}] Translation does not exist, skipping`); |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + let content = fs.readFileSync(translationPath, 'utf8'); |
| 87 | + |
| 88 | + if (content.includes(WARNING_MARKER)) { |
| 89 | + console.log(` [${lang}] Already has outdated warning, skipping`); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + let frontmatterEnd = 0; |
| 94 | + if (content.startsWith('---')) { |
| 95 | + const secondDelimiter = content.indexOf('---', 3); |
| 96 | + if (secondDelimiter !== -1) { |
| 97 | + frontmatterEnd = secondDelimiter + 3; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + const warningBanner = WARNING_BANNERS[lang] || DEFAULT_WARNING; |
| 102 | + const warningWithLink = warningBanner.replace('ENGLISH_DOC_LINK', englishDocLink); |
| 103 | + |
| 104 | + let updatedContent; |
| 105 | + if (frontmatterEnd > 0) { |
| 106 | + const frontmatter = content.substring(0, frontmatterEnd); |
| 107 | + const restOfContent = content.substring(frontmatterEnd).trimStart(); |
| 108 | + updatedContent = `${frontmatter}\n\n${warningWithLink}${restOfContent}`; |
| 109 | + } else { |
| 110 | + const restOfContent = content.trimStart(); |
| 111 | + updatedContent = `${warningWithLink}${restOfContent}`; |
| 112 | + } |
| 113 | + |
| 114 | + fs.writeFileSync(translationPath, updatedContent, 'utf8'); |
| 115 | + console.log(` [${lang}] ✓ Marked as outdated`); |
| 116 | + totalFilesMarked++; |
| 117 | + markedFiles.push(translationPath.replace(process.cwd() + path.sep, '').replace(/\\/g, '/')); |
| 118 | + }); |
| 119 | +}); |
| 120 | + |
| 121 | +console.log(`\n✅ Total files marked: ${totalFilesMarked}`); |
| 122 | + |
| 123 | +if (markedFiles.length > 0) { |
| 124 | + const markedFilesPath = path.join(process.cwd(), 'marked_translation_files.txt'); |
| 125 | + fs.writeFileSync(markedFilesPath, markedFiles.join('\n'), 'utf8'); |
| 126 | + console.log(`Marked files list written to: ${markedFilesPath}`); |
| 127 | +} |
0 commit comments