自动化立体仓库 - 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
# Set encoding to UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
 
# Paths
$root = "f:\workFile\2026.1.12yuedan\zy-asrs"
$enPath = "$root\src\main\webapp\static\i18n\en.json"
$cnPath = "$root\src\main\webapp\static\i18n\zh-cn.json"
$mapPath = "$root\scripts\mapping.json"
$javaPath = "$root\src\main\java"
 
# 1. Load Mapping
if (Test-Path $mapPath) {
    $mapContent = Get-Content $mapPath -Raw -Encoding UTF8 | ConvertFrom-Json
} else {
    Write-Host "Mapping file not found!"
    $mapContent = $null
}
 
# 2. Scan Java Files for keys
Write-Host "Scanning Java files..."
$javaFiles = Get-ChildItem -Path $javaPath -Recurse -Filter "*.java"
$foundKeys = @()
foreach ($file in $javaFiles) {
    $content = Get-Content $file.FullName
    # Regex to capture response.xxx
    # Matches response. followed by letters, numbers, underscores, dots
    $matches = [regex]::Matches($content, 'response\.[a-zA-Z0-9_]+')
    foreach ($match in $matches) {
        $foundKeys += $match.Value
    }
}
 
# Manual keys mentioned by user
$manualKeys = @("response.mat_list", "response.menu_list", "response.mat_delete", "response.mat_update", "response.user_detail")
$foundKeys += $manualKeys
 
# Unique and Sort
$foundKeys = $foundKeys | Sort-Object | Get-Unique
 
# Exclude technical calls (heuristic)
$exclude = @("response.getOutputStream", "response.setContentType", "response.setCharacterEncoding", "response.setHeader", "response.sendRedirect", "response.getWriter", "response.addCookie", "response.setStatus", "response.reset", "response.isSuccessful", "response.getStatus", "response.put")
$foundKeys = $foundKeys | Where-Object { $exclude -notcontains $_ }
 
Write-Host "Found $($foundKeys.Count) unique 'response.*' keys."
 
# Helper Functions
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) {
            if ($mapContent.PSObject.Properties.Name -contains $part) {
                $trans += $mapContent.$part
                $found = $true
            }
        }
        
        if (-not $found) {
             if ($part.Length -gt 0) {
                 # Fallback: capitalize
                 # Or maybe leave as English if no mapping? 
                 # User wants Chinese, but better English than nothing.
                 # But we try to map.
                 # If valid mapping is missing, we might want to flag it?
                 # For now, just Capitalize
                 $trans += $part.Substring(0,1).ToUpper() + $part.Substring(1)
             }
        }
    }
    return $trans
}
 
function Process-JsonFile($path, $lang) {
    Write-Host "Processing $path ..."
    $jsonContent = Get-Content $path -Raw -Encoding UTF8 | ConvertFrom-Json
    
    # Convert to hashtable for easier manipulation if possible, 
    # but ConvertFrom-Json returns PSCustomObject.
    # We will build a new Ordered Dictionary to store results.
    
    $newDict = [Ordered]@{}
    
    # Copy existing keys
    foreach ($prop in $jsonContent.PSObject.Properties) {
        $newDict[$prop.Name] = $prop.Value
    }
    
    # Update/Add keys
    $addedCount = 0
    $updatedCount = 0
    
    foreach ($key in $foundKeys) {
        $val = ""
        if ($lang -eq "en") {
            $val = Get-EnTrans $key
        } else {
            $val = Get-CnTrans $key
        }
        
        if ($newDict.Contains($key)) {
            # Check if empty
            if ([string]::IsNullOrEmpty($newDict[$key])) {
                $newDict[$key] = $val
                $updatedCount++
                Write-Host "  Updated empty key: $key -> $val"
            }
        } else {
            # Add new
            $newDict[$key] = $val
            $addedCount++
            Write-Host "  Added new key: $key -> $val"
        }
    }
    
    Write-Host "  Added: $addedCount, Updated: $updatedCount"
    
    # Sort keys
    $sortedDict = [Ordered]@{}
    $keys = $newDict.Keys | Sort-Object
    foreach ($k in $keys) {
        $sortedDict[$k] = $newDict[$k]
    }
    
    # Convert back to JSON
    $jsonOutput = $sortedDict | ConvertTo-Json -Depth 100
    
    # Unescape Unicode
    $jsonOutput = [regex]::Replace($jsonOutput, "\\u([0-9a-fA-F]{4})", { param($m) [char][int]::Parse($m.Groups[1].Value, [System.Globalization.NumberStyles]::HexNumber) })
    
    # Save
    $jsonOutput | Set-Content -Path $path -Encoding UTF8
}
 
Process-JsonFile $enPath "en"
Process-JsonFile $cnPath "cn"
 
Write-Host "Done."