const fs = require('fs')
const path = require('path')
const rootDir = process.cwd()
const docsReadmeDir = path.join(rootDir, 'docs-readme')
const rootReadmePath = path.join(rootDir, 'README.md')
const locales = [
{ code: 'zh-CN', name: '简体中文' },
{ code: 'zh-TW', name: '繁體中文' },
{ code: 'en-US', name: 'English' },
{ code: 'ja-JP', name: '日本語' },
{ code: 'es-ES', name: 'Español' },
{ code: 'fr-FR', name: 'Français' },
{ code: 'tlh', name: 'Klingon' },
{ code: 'ko-KR', name: '한국어' },
{ code: 'ar-SA', name: 'العربية' },
{ code: 'tr-TR', name: 'Türkçe' },
{ code: 'vi-VN', name: 'Tiếng_Việt' },
{ code: 'de-DE', name: 'Deutsch' },
{ code: 'bn-BD', name: 'বাংলা' }
]
function generateNavBlock(isRoot) {
const links = locales.map((locale) => {
const href = isRoot
? `docs-readme/${locale.code}/README.md`
: `../${locale.code}/README.md`
return ` `
})
return `
\n${links.join('\n')}\n
` } function updateFile(filePath, isRoot) { if (!fs.existsSync(filePath)) { console.log(`File not found: ${filePath}`) return } let content = fs.readFileSync(filePath, 'utf8') const newNavBlock = generateNavBlock(isRoot) // Regex to match the existing nav block. It starts withand contains the badges. // The badges in previous versions had slightly different names/links, but they all were inside
...
// We look for the block containing "简体中文" or "English" to be sure it's the language nav. const regex = /