自动化立体仓库 - WMS系统
lty
3 天以前 8e943b7104561c3b14cf223016698709c5ade4b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$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"
}