forked from openrails/openrails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate-Pseudo.ps1
90 lines (89 loc) · 4.08 KB
/
Update-Pseudo.ps1
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
function Get-Translation {
process {
$a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
$b = "ÂßÇÐÉFGHÌJK£MNÓÞQR§TÛVWXÝZáβçδèƒϱλïJƙℓ₥ñôƥ9řƨƭúƲωж¥ƺ"
Write-Output ('[{0} !!!]' -f ((($_ -split '' | % {
$inFormat = 0
} {
$i = $a.IndexOf($_);
if (-not $inFormat -and $_ -and $i -ge 0) { Write-Output $b[$i] } else { Write-Output $_ }
if (-not $inFormat -and $_ -eq '{') { $inFormat = 1 }
elseif ($inFormat -and $_ -eq '{') { $inFormat = 0 }
elseif ($inFormat -and $_ -eq '}') { $inFormat = 0 }
}) -join '') -creplace '\\ř','\r' -creplace '\\ñ','\n'))
}
}
gci -Directory | %{
$file = $_
Write-Host ('Reading template file ''{0}''' -f (gi ($file.Name + '\*.pot')))
(gc -Encoding UTF8 ($file.Name + '\*.pot') | %{
$header = 1
$msgid = @()
$msgid_plural = @()
} {
if ($header -and $_ -cmatch '^#:') {
$header = 0
Write-Output $_
} elseif ($header -and $_ -like '"Project-Id-Version: *"') {
Write-Output ('"Project-Id-Version: {0}\n"' -f $file.Name)
} elseif ($header -and $_ -like '"Language-Team: *"') {
Write-Output '"Language-Team: Open Rails Dev Team\n"'
Write-Output '"Language: qps-ploc\n"'
} elseif ($header -and $_ -like '"Language: *"') {
} elseif ($header -and $_ -like '"X-Generator: *"') {
Write-Output '"X-Generator: PowerShell Update-Pseudo.ps1\n"'
Write-Output '"Plural-Forms: nplurals=2; plural=(n != 1);\n"'
} elseif ($header) {
Write-Output $_
} elseif ($_ -cmatch '^msgid "(.*)"') {
$msgid = @($Matches[1])
Write-Output $_
} elseif ($_ -cmatch '^msgid_plural "(.*)"') {
$msgid_plural = @($Matches[1])
Write-Output $_
} elseif ($msgid.Length -gt 0 -and $msgid_plural.Length -eq 0 -and $_ -cmatch '^"(.*)"$') {
$msgid += @($Matches[1])
Write-Output $_
} elseif ($msgid_plural.Length -gt 0 -and $_ -cmatch '^"(.*)"$') {
$msgid_plural += @($Matches[1])
Write-Output $_
} elseif ($msgid.Length -gt 0 -and $_ -cmatch '^msgstr ""') {
if ($msgid.Length -gt 1) {
Write-Output 'msgstr ""'
((($msgid | select -Skip 1) -join "`n") | Get-Translation) -split "`n" | %{'"{0}"' -f $_}
} else {
$msgid[0] | Get-Translation | %{'msgstr "{0}"' -f $_}
}
$msgid = @()
} elseif ($msgid.Length -gt 0 -and $_ -cmatch '^msgstr\[0\] ""') {
if ($msgid.Length -gt 1) {
Write-Output 'msgstr[0] ""'
((($msgid | select -Skip 1) -join "`n") | Get-Translation) -split "`n" | %{'"{0}"' -f $_}
} else {
$msgid[0] | Get-Translation | %{'msgstr[0] "{0}"' -f $_}
}
$msgid = @()
} elseif ($msgid_plural.Length -gt 0 -and $_ -cmatch '^msgstr\[1\] ""') {
if ($msgid_plural.Length -gt 1) {
Write-Output 'msgstr[1] ""'
((($msgid_plural | select -Skip 1) -join "`n") | Get-Translation) -split "`n" | %{'"{0}"' -f $_}
} else {
$msgid_plural[0] | Get-Translation | %{'msgstr[1] "{0}"' -f $_}
}
$msgid_plural = @()
} elseif ($_ -like '"Project-Id-Version: *"') {
Write-Output ('"Project-Id-Version: {0}\n"' -f $file.Name)
} elseif ($_ -like '"Language-Team: *"') {
Write-Output '"Language-Team: Open Rails Dev Team\n"'
Write-Output '"Language: qps-ploc\n"'
} elseif ($_ -like '"Language: *"') {
} elseif ($_ -like '"X-Generator: *"') {
Write-Output '"X-Generator: PowerShell Update-Pseudo.ps1\n"'
Write-Output '"Plural-Forms: nplurals=2; plural=(n != 1);\n"'
} else {
Write-Output $_
}
}) -join "`r`n" | % {
[System.IO.File]::WriteAllLines(($file.Name + '\qps-ploc.po'), $_)
}
}