Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###BATCH:
- #!Translator.bat
- @echo off
- Powershell.exe -executionpolicy bypass -File "!Translator.ps1"
- echo Done.
- pause
- ###POWERSHELL:
- #!Translator.ps1
- function Translate {
- param (
- [String]
- $TargetLanguage = "English", # See list of possible languages in $LanguageHashTable below.
- [String]
- $Text = " " # This can either be the text to translate, or the path to a file containing the text to translate
- )
- # Create a Hashtable containing the full names of languages as keys and the code for that language as values
- $LanguageHashTable = @{
- Afrikaans='af'
- Albanian='sq'
- Arabic='ar'
- Azerbaijani='az'
- Basque='eu'
- Bengali='bn'
- Belarusian='be'
- Bulgarian='bg'
- Catalan='ca'
- 'Chinese Simplified'='zh-CN'
- 'Chinese Traditional'='zh-TW'
- Croatian='hr'
- Czech='cs'
- Danish='da'
- Dutch='nl'
- English='en'
- Esperanto='eo'
- Estonian='et'
- Filipino='tl'
- Finnish='fi'
- French='fr'
- Galician='gl'
- Georgian='ka'
- German='de'
- Greek='el'
- Gujarati='gu'
- Haitian ='ht'
- Creole='ht'
- Hebrew='iw'
- Hindi='hi'
- Hungarian='hu'
- Icelandic='is'
- Indonesian='id'
- Irish='ga'
- Italian='it'
- Japanese='ja'
- Kannada='kn'
- Korean='ko'
- Latin='la'
- Latvian='lv'
- Lithuanian='lt'
- Macedonian='mk'
- Malay='ms'
- Maltese='mt'
- Norwegian='no'
- Persian='fa'
- Polish='pl'
- Portuguese='pt'
- Romanian='ro'
- Russian='ru'
- Serbian='sr'
- Slovak='sk'
- Slovenian='sl'
- Spanish='es'
- Swahili='sw'
- Swedish='sv'
- Tamil='ta'
- Telugu='te'
- Thai='th'
- Turkish='tr'
- Ukrainian='uk'
- Urdu='ur'
- Vietnamese='vi'
- Welsh='cy'
- Yiddish='yi'
- }
- # Determine the target language
- if ($LanguageHashTable.ContainsKey($TargetLanguage)) {
- $TargetLanguageCode = $LanguageHashTable[$TargetLanguage]
- }
- elseif ($LanguageHashTable.ContainsValue($TargetLanguage)) {
- $TargetLanguageCode = $TargetLanguage
- }
- else {
- throw "Unknown target language. Use one of the languages in the `$LanguageHashTable hashtable."
- }
- if ($Text -eq " ") {
- $Text = ""
- }
- elseif (Test-Path $Text -PathType Leaf) {
- $Text = Get-Content $Text -Raw
- }
- #$Uri = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguageCode)&dt=t&q=$Text"
- $Uri = "https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=en&q=$Text"
- #$RawResponse = (Invoke-WebRequest -Uri $Uri -Method Get).Content
- #$CleanResponse = $RawResponse -split '\\r\\n' -replace '^(","?)|(null.*?\[")|\[{3}"' -split '","'
- $Response = ((Invoke-WebRequest -Uri $uri -Method Get).content | ConvertFrom-Json | select -expand sentences | Select trans).trans
- #$Second = $CleanResponse[2] -split '\['
- #$Final = $CleanResponse[0]+$Second[1]
- #$Final -replace '\"', "" -replace '\?', "" -replace '\\', "" -replace '\/', "" -replace '\:', "" -replace '\|', "" -replace '\*', "" -replace '\<', "" -replace '\>', ""
- $Final = ""
- foreach($name in $Response) { $final = $final+$name }
- $Final.trim()
- }
- $files = Get-ChildItem -Path $pwd -exclude('*.ps1','*.bat')
- foreach($file in $files) {
- $extension = [io.path]::GetExtension($file)
- $translation = Translate -Text "$($file.basename)"
- if ($translation -eq "") {
- break
- }
- ren "$($file.name)" $translation$extension
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement