localize-agents-zh.ps1 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. param(
  2. [string[]]$TargetDirs = @(
  3. "$env:USERPROFILE\.github\agents",
  4. "$env:USERPROFILE\.copilot\agents"
  5. )
  6. )
  7. $mapFile = Join-Path $PSScriptRoot "agent-names-zh.json"
  8. $map = Get-Content $mapFile -Raw -Encoding UTF8 | ConvertFrom-Json
  9. $totalUpdated = 0
  10. foreach ($dir in $TargetDirs) {
  11. if (-not (Test-Path $dir)) { Write-Warning "Skip (not found): $dir"; continue }
  12. $files = Get-ChildItem "$dir\*.md" -ErrorAction SilentlyContinue
  13. $updated = 0
  14. foreach ($f in $files) {
  15. $raw = [System.IO.File]::ReadAllText($f.FullName, [System.Text.Encoding]::UTF8)
  16. if (-not $raw.StartsWith("---")) { continue }
  17. $endIdx = $raw.IndexOf("---", 3)
  18. if ($endIdx -lt 0) { continue }
  19. $yaml = $raw.Substring(3, $endIdx - 3)
  20. if (-not ($yaml -match "(?m)^name:\s*(.+)$")) { continue }
  21. $currentName = $Matches[1].Trim()
  22. $entry = $map.$currentName
  23. if (-not $entry) { continue }
  24. $newYaml = $yaml -replace "(?m)^name:\s*.+$", "name: $($entry.name)"
  25. if ($newYaml -match "(?m)^description:") {
  26. $newYaml = $newYaml -replace "(?m)^description:\s*.+$", "description: $($entry.description)"
  27. }
  28. $newContent = "---" + $newYaml + "---" + $raw.Substring($endIdx + 3)
  29. [System.IO.File]::WriteAllText($f.FullName, $newContent, [System.Text.Encoding]::UTF8)
  30. $updated++
  31. }
  32. Write-Host "OK: $updated agents localized -> $dir"
  33. $totalUpdated += $updated
  34. }
  35. Write-Host "Total: $totalUpdated agent files updated."
  36. Write-Host "Reload VS Code window (Ctrl+Shift+P -> Reload Window) to apply."