|
|
@ -1,22 +1,36 @@ |
|
|
|
|
|
|
|
# read in the xib, original encoding is utf8 |
|
|
|
$lines = Get-Content .\MainMenu.xib -Encoding UTF8 |
|
|
|
$lines = Get-Content .\MainMenu.xib -Encoding UTF8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set new variable for output |
|
|
|
|
|
|
|
# this is where we make our translation edits |
|
|
|
$output = $lines |
|
|
|
$output = $lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pull out every line with a string keyed "NSDev" |
|
|
|
$regex = '<string type="base64-UTF8" key="NSDev">(?<txt>.+?)<\/string>' |
|
|
|
$regex = '<string type="base64-UTF8" key="NSDev">(?<txt>.+?)<\/string>' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# regex results |
|
|
|
$strings = [regex]::Matches($lines,$regex) |
|
|
|
$strings = [regex]::Matches($lines,$regex) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# public translation API - no key required! |
|
|
|
|
|
|
|
# throttled to 40 requests per 60 seconds |
|
|
|
|
|
|
|
# one request per 1.5 seconds |
|
|
|
$url = 'https://translate.mentality.rip/translate' |
|
|
|
$url = 'https://translate.mentality.rip/translate' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# log errors |
|
|
|
$errors = @() |
|
|
|
$errors = @() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# create a CSV of translated values, to make corrections easier |
|
|
|
|
|
|
|
# this is because the final XIB still has base64-encoded strings |
|
|
|
$csv = 'Base64JP,UTF8JP,Base64EN,UTF8EN' |
|
|
|
$csv = 'Base64JP,UTF8JP,Base64EN,UTF8EN' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# process every regex match |
|
|
|
foreach($string in $strings) { |
|
|
|
foreach($string in $strings) { |
|
|
|
# get the value |
|
|
|
# get the base64 value |
|
|
|
|
|
|
|
# uses named regex key |
|
|
|
$txt = $string.Groups["txt"].Value |
|
|
|
$txt = $string.Groups["txt"].Value |
|
|
|
|
|
|
|
|
|
|
|
# append appropriate padding |
|
|
|
# append appropriate padding |
|
|
|
|
|
|
|
# sauce: https://gist.github.com/obscuresec/82775093ad892ef5fd00 |
|
|
|
$mod = ($txt.length % 4) |
|
|
|
$mod = ($txt.length % 4) |
|
|
|
switch ($mod) { |
|
|
|
switch ($mod) { |
|
|
|
'0' {$txtp = $txt} |
|
|
|
'0' {$txtp = $txt} |
|
|
@ -29,19 +43,19 @@ foreach($string in $strings) { |
|
|
|
# convert the base64 to UTF8 text |
|
|
|
# convert the base64 to UTF8 text |
|
|
|
$utf = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($txtp)) |
|
|
|
$utf = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($txtp)) |
|
|
|
|
|
|
|
|
|
|
|
# get current array index |
|
|
|
# get current array index (for progress bar) |
|
|
|
$idx = [array]::IndexOf($strings,$string) |
|
|
|
$idx = [array]::IndexOf($strings,$string) |
|
|
|
|
|
|
|
|
|
|
|
# get percent complete |
|
|
|
# get percent complete (for progress bar) |
|
|
|
$pct = (($idx + 1) / $strings.Count) * 100 |
|
|
|
$pct = (($idx + 1) / $strings.Count) * 100 |
|
|
|
|
|
|
|
|
|
|
|
# round the percent |
|
|
|
# round the percent to one decimal |
|
|
|
$pcn = [math]::Round($pct,2) |
|
|
|
$pcn = [math]::Round($pct,2) |
|
|
|
|
|
|
|
|
|
|
|
# update the status bar |
|
|
|
# update the status bar |
|
|
|
Write-Progress -Activity ("Translating <<" + $utf + ">>") -Status "$pcn% Complete:" -PercentComplete $pct |
|
|
|
Write-Progress -Activity ("Translating <<" + $utf + ">>") -Status "$pcn% Complete:" -PercentComplete $pct |
|
|
|
|
|
|
|
|
|
|
|
# create the json request |
|
|
|
# create the json request using Japanese string |
|
|
|
$json = '{"q":"' + $utf + '","source":"ja","target":"en"}' |
|
|
|
$json = '{"q":"' + $utf + '","source":"ja","target":"en"}' |
|
|
|
|
|
|
|
|
|
|
|
# add delay due to api throttle |
|
|
|
# add delay due to api throttle |
|
|
@ -66,10 +80,14 @@ foreach($string in $strings) { |
|
|
|
# add to the csv |
|
|
|
# add to the csv |
|
|
|
$csv += "`n""$txt"",""$utf"",""$txt64clean"",""$ttxt""" |
|
|
|
$csv += "`n""$txt"",""$utf"",""$txt64clean"",""$ttxt""" |
|
|
|
} catch { |
|
|
|
} catch { |
|
|
|
|
|
|
|
# couldn't translate, probably because it's already English |
|
|
|
Write-Host ("Couldn't translate <<" + $utf + ">>") |
|
|
|
Write-Host ("Couldn't translate <<" + $utf + ">>") |
|
|
|
$errors += $utf |
|
|
|
$errors += $utf |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# save the xib |
|
|
|
$output | Out-File Output.xib -Encoding utf8 |
|
|
|
$output | Out-File Output.xib -Encoding utf8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# save the csv |
|
|
|
$csv | Out-File output.csv -Encoding utf8 |
|
|
|
$csv | Out-File output.csv -Encoding utf8 |