diff --git a/base64decoder.html b/base64decoder.html new file mode 100644 index 0000000..82a51f1 --- /dev/null +++ b/base64decoder.html @@ -0,0 +1,170 @@ + + + + + + + + + +
+

Base64

+ +
+
+ + + +
+
+
+

Japanese

+ +

English

+ + +
+ + + \ No newline at end of file diff --git a/translator.ps1 b/translator.ps1 new file mode 100644 index 0000000..167f245 --- /dev/null +++ b/translator.ps1 @@ -0,0 +1,75 @@ +$lines = Get-Content .\MainMenu.xib -Encoding UTF8 + +$output = $lines + +$regex = '(?.+?)<\/string>' + +$strings = [regex]::Matches($lines,$regex) + +$url = 'https://translate.mentality.rip/translate' + +$errors = @() + +$csv = 'Base64JP,UTF8JP,Base64EN,UTF8EN' + +foreach($string in $strings) { + # get the value + $txt = $string.Groups["txt"].Value + + # append appropriate padding + $mod = ($txt.length % 4) + switch ($mod) { + '0' {$txtp = $txt} + '1' {$txtp = $txt.Substring(0,$txt.Length - 1)} + '2' {$txtp = $txt + ('=' * (4 - $mod))} + '3' {$txtp = $txt + ('=' * (4 - $mod))} + + } + + # convert the base64 to UTF8 text + $utf = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($txtp)) + + # get current array index + $idx = [array]::IndexOf($strings,$string) + + # get percent complete + $pct = (($idx + 1) / $strings.Count) * 100 + + # round the percent + $pcn = [math]::Round($pct,2) + + # update the status bar + Write-Progress -Activity ("Translating <<" + $utf + ">>") -Status "$pcn% Complete:" -PercentComplete $pct + + # create the json request + $json = '{"q":"' + $utf + '","source":"ja","target":"en"}' + + # add delay due to api throttle + Start-Sleep -Seconds 1.5 + + try { + # post the request to the translation service + $result = Invoke-WebRequest -Method 'Post' -Uri $url -Body $json -ContentType "application/json; charset=utf-8" + + # this is the english translation + $ttxt = ($result.Content | ConvertFrom-Json).translatedText + + # convert the english translation to base64 using .net + $txt64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($ttxt)) + + # remove the padding == because these don't exist in the original XIB + $txt64clean = $txt64 -replace '=','' + + # replace the value everywhere it occurs in the source data + $output = $output -replace $txt,$txt64clean + + # add to the csv + $csv += "`n""$txt"",""$utf"",""$txt64clean"",""$ttxt""" + } catch { + Write-Host ("Couldn't translate <<" + $utf + ">>") + $errors += $utf + } +} + +$output | Out-File Output.xib -Encoding utf8 +$csv | Out-File output.csv -Encoding utf8 \ No newline at end of file