Added translate.ps1

This commit is contained in:
Markus Fleschutz 2020-05-03 16:54:49 +00:00
parent e2c36d42ef
commit cfd8114b44
4 changed files with 36 additions and 0 deletions

0
password.ps1 Normal file → Executable file
View File

0
passwords.ps1 Normal file → Executable file
View File

0
speak.ps1 Normal file → Executable file
View File

36
translate.ps1 Executable file
View File

@ -0,0 +1,36 @@
# PowerShell Script for Translating Texts
# ---------------------------------------
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
$SourceText = "Hello World!"
$SourceLang = "en"
$TargetLanguages = "af","da","de","el","es","hr","it","ja","ko","pl","pt","nl","ru","tr","uk","vi"
function TranslateWithGoogle {
[CmdletBinding()]
param (
[Parameter(Position = 1, ValueFromPipeline = $true)]
[ValidateNotNullorEmpty()]
[string]$Text,
[Parameter(Position = 2)]
[ValidateNotNullorEmpty()]
[string]$SourceLang,
[Parameter(Position = 3)]
[ValidateNotNullorEmpty()]
[string]$TargetLang
)
$URL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=$($SourceLang)&tl=$($TargetLang)&dt=t&q=$($Text)"
$result = Invoke-RestMethod $URL
return $result[0][0][0]
}
foreach($TargetLang in $TargetLanguages) {
$Result = TranslateWithGoogle $SourceText $SourceLang $TargetLang
write-output $TargetLang" : "$Result
}
exit 0