$javaFiles = Get-ChildItem -Path "src/main/java" -Recurse -Filter "*.java"
|
$foundKeys = @()
|
foreach ($file in $javaFiles) {
|
$content = Get-Content $file.FullName
|
$matches = [regex]::Matches($content, 'response\.[a-zA-Z0-9_]+')
|
foreach ($match in $matches) {
|
$foundKeys += $match.Value
|
}
|
}
|
|
# Manually add keys mentioned by user or known to be missing from grep
|
$manualKeys = @("response.mat_list", "response.menu_list", "response.mat_delete", "response.mat_update", "response.user_detail")
|
$foundKeys += $manualKeys
|
|
$foundKeys = $foundKeys | Sort-Object | Get-Unique
|
|
# Exclude technical calls
|
$exclude = @("response.getOutputStream", "response.setContentType", "response.setCharacterEncoding", "response.setHeader", "response.sendRedirect", "response.getWriter", "response.addCookie", "response.setStatus", "response.reset", "response.isSuccessful", "response.getStatus")
|
$foundKeys = $foundKeys | Where-Object { $exclude -notcontains $_ }
|
|
$enPath = "src/main/webapp/static/i18n/en.json"
|
$cnPath = "src/main/webapp/static/i18n/zh-cn.json"
|
$mapPath = "scripts/mapping.json"
|
|
$enContent = Get-Content $enPath -Raw -Encoding UTF8
|
$cnContent = Get-Content $cnPath -Raw -Encoding UTF8
|
$mapContent = Get-Content $mapPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
# Parse existing keys
|
$enKeys = [regex]::Matches($enContent, '"(response\.[^"]+)"') | ForEach-Object { $_.Groups[1].Value }
|
$cnKeys = [regex]::Matches($cnContent, '"(response\.[^"]+)"') | ForEach-Object { $_.Groups[1].Value }
|
|
$missingEn = $foundKeys | Where-Object { $enKeys -notcontains $_ }
|
$missingCn = $foundKeys | Where-Object { $cnKeys -notcontains $_ }
|
|
function Get-EnTrans($key) {
|
$parts = $key.Replace("response.", "").Split("_")
|
$text = $parts | ForEach-Object { $_.Substring(0,1).ToUpper() + $_.Substring(1) }
|
return $text -join " "
|
}
|
|
function Get-CnTrans($key) {
|
$keyRaw = $key.Replace("response.", "")
|
$parts = $keyRaw.Split("_")
|
$trans = ""
|
foreach ($part in $parts) {
|
$found = $false
|
if ($mapContent -ne $null) {
|
# Robust property check
|
if ($mapContent.PSObject.Properties.Name -contains $part) {
|
$trans += $mapContent.$part
|
$found = $true
|
}
|
}
|
|
if (-not $found) {
|
if ($part.Length -gt 0) {
|
$trans += $part.Substring(0,1).ToUpper() + $part.Substring(1)
|
}
|
}
|
}
|
return $trans
|
}
|
|
# Add to EN
|
if ($missingEn.Count -gt 0) {
|
$newEntries = @()
|
foreach ($key in $missingEn) {
|
$val = Get-EnTrans $key
|
$newEntries += " `"$key`": `"$val`""
|
}
|
$toAdd = "," + [Environment]::NewLine + ($newEntries -join "," + [Environment]::NewLine)
|
|
$lastBraceIndex = $enContent.LastIndexOf("}")
|
if ($lastBraceIndex -ge 0) {
|
$enContent = $enContent.Substring(0, $lastBraceIndex) + $toAdd + [Environment]::NewLine + "}"
|
Set-Content -Path $enPath -Value $enContent -Encoding UTF8
|
Write-Host "Added $($missingEn.Count) keys to en.json"
|
}
|
} else {
|
Write-Host "No missing keys in EN"
|
}
|
|
# Add to CN
|
if ($missingCn.Count -gt 0) {
|
$newEntries = @()
|
foreach ($key in $missingCn) {
|
$val = Get-CnTrans $key
|
$newEntries += " `"$key`": `"$val`""
|
}
|
$toAdd = "," + [Environment]::NewLine + ($newEntries -join "," + [Environment]::NewLine)
|
|
$lastBraceIndex = $cnContent.LastIndexOf("}")
|
if ($lastBraceIndex -ge 0) {
|
$cnContent = $cnContent.Substring(0, $lastBraceIndex) + $toAdd + [Environment]::NewLine + "}"
|
Set-Content -Path $cnPath -Value $cnContent -Encoding UTF8
|
Write-Host "Added $($missingCn.Count) keys to zh-cn.json"
|
}
|
} else {
|
Write-Host "No missing keys in CN"
|
}
|