Update check-ps1-file.ps1 and translate-files.ps1

This commit is contained in:
Markus Fleschutz 2023-05-26 11:55:16 +02:00
parent fb208f3814
commit e4b9649681
2 changed files with 13 additions and 12 deletions

View File

@ -1,10 +1,10 @@
<#
.SYNOPSIS
Checks a PowerShell file for validity
Checks PowerShell file(s) for validity
.DESCRIPTION
This PowerShell script checks the given PowerShell file for validity.
.PARAMETER pattern
Specifies the file pattern to the PowerShell file(s) to check
This PowerShell script checks the given PowerShell file(s) for validity.
.PARAMETER filePattern
Specifies the file pattern to the PowerShell file(s)
.EXAMPLE
PS> ./check-ps1-file *.ps1
Valid PowerShell in myfile.ps1
@ -14,16 +14,17 @@
Author: Markus Fleschutz | License: CC0
#>
param([string]$pattern = "")
param([string]$filePattern = "")
try {
if ($pattern -eq "" ) { $path = Read-Host "Enter the file pattern to the PowerShell file(s)" }
$files = Get-ChildItem $pattern
if ($filePattern -eq "" ) { $path = Read-Host "Enter the file pattern to the PowerShell file(s)" }
$files = Get-ChildItem $filePattern
foreach ($file in $files) {
$syntaxError = @()
[void][System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$null, [ref]$syntaxError)
if ("$syntaxError" -ne "") { throw "$syntaxError" }
"✔️ Valid PowerShell in $file"
$basename = (Get-Item "$file").Basename
"✔️ Valid PowerShell in $basename"
}
exit 0 # success
} catch {

View File

@ -1,6 +1,6 @@
<#
.SYNOPSIS
Translates text files into any supported language
Translates text files
.DESCRIPTION
This PowerShell script translates text files into any supported language.
.PARAMETER FilePattern
@ -16,8 +16,8 @@
param([string]$FilePattern = "")
function DetectSourceLang { param([string]$Filename)
if ("$Filename" -like "*Deutsch*") { return "de" }
if ("$Filename" -like "*English*") { return "en" }
if ("$Filename" -like "*Deutsch*") { return "de" }
if ("$Filename" -like "*English*") { return "en" }
if ("$Filename" -like "*Français*") { return "fr" }
return "unknown"
}
@ -27,7 +27,7 @@ function TranslateFilename { param([string]$Filename, [string]$SourceLang, [stri
if ($SourceLang -eq "de") { $SourceLanguage = "Deutsch" }
if ($SourceLang -eq "en") { $SourceLanguage = "English" }
if ($SourceLang -eq "fr") { $SourceLanguage = "Français" }
$TargetLanguage = ("$PSScriptRoot/translate-text.ps1" $SourceLanguage $SourceLang $TargetLang)
$TargetLanguage = ("$PSScriptRoot/translate-text.ps1 $SourceLanguage $SourceLang $TargetLang")
return $Filename.replace($SourceLanguage, $TargetLanguage)
}