Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Text = @"
- Watch out for the dog.
- It's angry.
- I'm telling you.
- You better watch out.
- Do you hear me?
- Last warning my dude.
- You are going to far.
- I don't know.
- You check.
- I couldn't be arse with it.
- Now leave, please.
- "@
- Function TranslateText ([string]$TextToTranslate, [string]$TargetLanguage) {
- <#
- .SYNOPSIS
- Translate text to the specified language.
- The exhaustive languages list is available in $LanguagesList.
- .EXAMPLE
- TranslateText "hello" "es"
- TranslateText $Text "fr"
- #>
- $LanguagesList = @('af','sq','am','ar','hy','az','eu','be','bn','bs','bg','ca','ceb','zh-CN','zh-TW','co','hr','cs','da','nl','en','eo','et','fi','fr','fy','gl','ka','de','el','gu','ht','ha','haw','he','hi','hmn','hu','is','ig','id','ga','it','ja','jv','kn','kk','km','rw','ko','ku','ky','lo','lv','lt','lb','mk','mg','ms','ml','mt','mi','mr','mn','my','ne','no','ny','or','ps','fa','pl','pt','pa','ro','ru','sm','gd','sr','st','sn','sd','si','sk','sl','so','es','su','sw','sv','tl','tg','ta','tt','te','th','tr','tk','uk','ur','ug','uz','vi','cy','xh','yi','yo','zu')
- $PhrasesList = New-Object -TypeName 'System.Collections.ArrayList'
- $Uri = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguage)&dt=t&q=$TextToTranslate"
- $RawResponse = (Invoke-WebRequest -Uri $Uri -Method Get).Content
- $RawResponse = $RawResponse -replace '\[','' -replace '\]','' -replace '\"','' -replace '\\r\\n',''
- $RawResponse = $RawResponse -split ',' | foreach {
- If($_ -ne "null" -And (-Not $LanguagesList.Contains($_)) -And $_ -ne "true" -And $_ -notmatch "^[\d\.]+$" -And $_ -notlike "*.md" -And $TextToTranslate -notmatch $_ -And $_ -notmatch "[0123456789abcdef]{$($_.length)}") {
- $PhrasesList.Add($_)
- }
- }
- Return $PhrasesList
- }
- TranslateText $Text "fr"
- #TranslateText "hello" "es"
Add Comment
Please, Sign In to add comment