mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-23 00:13:36 +01:00
Add translate-file.ps1
This commit is contained in:
parent
1907062856
commit
b2e571ec15
@ -142,6 +142,7 @@ switch-branch.ps1, switches the branch in the current/given Git repository (incl
|
||||
switch-shelly1.ps1, switches a Shelly1 device in the local network
|
||||
take-screenshot.ps1, takes a single screenshot
|
||||
take-screenshots.ps1, takes multiple screenshots
|
||||
translate-file.ps1, translates the given text file into another language
|
||||
translate-text.ps1, translates the given text into other languages
|
||||
turn-volume-up.ps1, turns the audio volume up (+10% by default)
|
||||
turn-volume-down.ps1, turns the audio volume down (-10% by default)
|
||||
|
|
5693
Data/trans
Executable file
5693
Data/trans
Executable file
File diff suppressed because it is too large
Load Diff
@ -173,7 +173,8 @@ Mega Collection of PowerShell Scripts
|
||||
* [simulate-matrix.ps1](Scripts/simulate-matrix.ps1) - simulates the Matrix (fun)
|
||||
* [simulate-presence.ps1](Scripts/simulate-presence.ps1) - simulates the human presence against burglars
|
||||
* [switch-shelly1.ps1](Scripts/switch-shelly1.ps1) - switches a Shelly1 device in the local network
|
||||
* [translate-text.ps1](Scripts/translate-text.ps1) - translates the given text into other languages
|
||||
* [translate-file.ps1](Scripts/translate-file.ps1) - translates the given text file into other languages
|
||||
* [translate-text.ps1](Scripts/translate-text.ps1) - translates the given text in English into other languages
|
||||
* [weather.ps1](Scripts/weather.ps1) - prints the current weather forecast
|
||||
* [weather-alert.ps1](Scripts/weather-alert.ps1) - checks the current weather for critical values
|
||||
* [weather-report.ps1](Scripts/weather-report.ps1) - prints the local weather report
|
||||
|
26
Scripts/translate-file.ps1
Executable file
26
Scripts/translate-file.ps1
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./translate-file.ps1 [<file>] [<source-lang>] [<target-lang>]
|
||||
.DESCRIPTION translates the given text file into another language and prints the result.
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($File = "", $SourceLang = "", $TargetLang = "")
|
||||
|
||||
if ($File -eq "" ) { $File = read-host "Enter path to file" }
|
||||
if ($SourceLang -eq "" ) { $SourceLang = read-host "Enter language used in this file" }
|
||||
if ($TargetLang -eq "" ) { $TargetLang = read-host "Enter language to translate to" }
|
||||
|
||||
try {
|
||||
$PathToRepo = "$PSScriptRoot/.."
|
||||
|
||||
$Engine = "google" # aspell | google | bing | spell | hunspell | apertium | yandex
|
||||
|
||||
start-process -filePath "$PathToRepo/Data/trans" -argumentList "-i $File -s $SourceLang -t $TargetLang -e $Engine -brief" -noNewWindow -wait
|
||||
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -1,30 +1,17 @@
|
||||
#!/usr/bin/pwsh
|
||||
<#
|
||||
.SYNTAX translate-text.ps1 [<text>] [<source-lang>]
|
||||
.DESCRIPTION translates the given text into other languages
|
||||
.DESCRIPTION translates the given text in English into other languages
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($SourceText = "", $SourceLang = "en")
|
||||
if ($SourceText -eq "" ) { $SourceText = read-host "Enter text to translate" }
|
||||
param($Text = "", $SourceLang = "en")
|
||||
|
||||
if ($Text -eq "" ) { $Text = read-host "Enter text in English to translate" }
|
||||
$TargetLanguages = "af","da","de","el","es","fr","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
|
||||
)
|
||||
function TranslateUsingGoogle { param([string]$Text, [string]$SourceLang, [string]$TargetLang)
|
||||
|
||||
$URL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=$($SourceLang)&tl=$($TargetLang)&dt=t&q=$($Text)"
|
||||
$result = Invoke-RestMethod $URL
|
||||
@ -32,9 +19,9 @@ function TranslateWithGoogle {
|
||||
}
|
||||
|
||||
try {
|
||||
foreach($TargetLanguage in $TargetLanguages) {
|
||||
$Result = TranslateWithGoogle $SourceText $SourceLang $TargetLanguage
|
||||
write-output $TargetLanguage" : "$Result
|
||||
foreach($TargetLang in $TargetLanguages) {
|
||||
$Result = TranslateUsingGoogle $Text $SourceLang $TargetLang
|
||||
write-output "$TargetLang : $Result"
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
|
Loading…
Reference in New Issue
Block a user