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

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Translates text files into any supported language Translates text files
.DESCRIPTION .DESCRIPTION
This PowerShell script translates text files into any supported language. This PowerShell script translates text files into any supported language.
.PARAMETER FilePattern .PARAMETER FilePattern
@ -27,7 +27,7 @@ function TranslateFilename { param([string]$Filename, [string]$SourceLang, [stri
if ($SourceLang -eq "de") { $SourceLanguage = "Deutsch" } if ($SourceLang -eq "de") { $SourceLanguage = "Deutsch" }
if ($SourceLang -eq "en") { $SourceLanguage = "English" } if ($SourceLang -eq "en") { $SourceLanguage = "English" }
if ($SourceLang -eq "fr") { $SourceLanguage = "Français" } 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) return $Filename.replace($SourceLanguage, $TargetLanguage)
} }