PowerShell/Scripts/translate-file.ps1

29 lines
925 B
PowerShell
Raw Normal View History

2020-12-12 16:18:46 +01:00
#!/snap/bin/powershell
# Syntax: ./translate-file.ps1 [<file>]
# Description: translates the given file from source to target language.
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
param([string]$SourceFile, [string]$SourceLanguage, [string]$TargetLanguage)
if ($SourceFile -eq "" ) {
$SourceFile = read-host "Enter path to file"
}
if ($SourceLanguage -eq "" ) {
2020-12-13 12:21:58 +01:00
$SourceLanguage = read-host "Enter language of this file"
2020-12-12 16:18:46 +01:00
}
if ($TargetLanguage -eq "" ) {
2020-12-13 12:21:58 +01:00
$TargetLanguage = read-host "Enter language to translate to"
2020-12-12 16:18:46 +01:00
}
try {
2020-12-14 15:06:09 +01:00
$PathToData=(get-item $MyInvocation.MyCommand.Path).directory
$PathToData="$PathToData/../Data"
Start-Process -FilePath "$PathToData/trans" -ArgumentList "-i $SourceFile -s $SourceLanguage -t $TargetLanguage -e google -brief" -NoNewWindow -Wait
2020-12-12 16:18:46 +01:00
exit 0
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}