Guest User

HP2_Polish_Subtitles_Fix

a guest
Jan 27th, 2026
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # =============================
  2. # 1. Poprawka dźwięków w katalogu Sounds
  3. # =============================
  4. Copy-Item Sounds\AllDialog.pol_uax Sounds\AllDialog.ger_uax
  5.  
  6. # =============================
  7. # 2. Poprawka napisów w katalogu system
  8. # =============================
  9.  
  10. # Funkcja do odczytu pliku z wykrywaniem BOM (UTF-16 LE lub UTF-8)
  11. function Read-FileDetectEncoding($path) {
  12.     $bytes = [System.IO.File]::ReadAllBytes($path)
  13.  
  14.     if ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) {
  15.         # UTF-16 LE BOM
  16.         return [System.IO.File]::ReadAllText($path, [System.Text.Encoding]::Unicode)
  17.     } elseif ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
  18.         # UTF-8 BOM
  19.         return [System.IO.File]::ReadAllText($path, [System.Text.Encoding]::UTF8)
  20.     } else {
  21.         # Domyślnie UTF-8
  22.         return [System.IO.File]::ReadAllText($path, [System.Text.Encoding]::UTF8)
  23.     }
  24. }
  25.  
  26. # Katalog system względem miejsca uruchomienia skryptu
  27. $systemDir = Join-Path $PSScriptRoot 'system'
  28.  
  29. if (-not (Test-Path $systemDir)) {
  30.     Write-Host "❌ Nie znaleziono katalogu: $systemDir"
  31.     exit 1
  32. }
  33.  
  34. # Pobranie plików .pol
  35. $files = Get-ChildItem -Path $systemDir -Filter *.pol
  36.  
  37. Write-Host "Znaleziono plików .pol w system:" $files.Count
  38.  
  39. # Iteracja po każdym pliku
  40. $files | ForEach-Object {
  41.  
  42.     $sourceFile = $_.FullName
  43.     $targetFile = [System.IO.Path]::ChangeExtension($sourceFile, ".ger")
  44.  
  45.     # Odczyt pliku z wykryciem kodowania
  46.     $content = Read-FileDetectEncoding $sourceFile
  47.  
  48.     # Zamiana polskich znaków
  49.     $content = $content `
  50.         -replace 'ą','a' -replace 'ć','c' -replace 'ę','e' -replace 'ł','l' `
  51.         -replace 'ń','n' -replace 'ó','o' -replace 'ś','s' -replace 'ż','z' -replace 'ź','z' `
  52.         -replace 'Ą','A' -replace 'Ć','C' -replace 'Ę','E' -replace 'Ł','L' `
  53.         -replace 'Ń','N' -replace 'Ó','O' -replace 'Ś','S' -replace 'Ż','Z' -replace 'Ź','Z'
  54.  
  55.     # Zapis UTF-16 LE z BOM
  56.     [System.IO.File]::WriteAllText(
  57.         $targetFile,
  58.         $content,
  59.         [System.Text.Encoding]::Unicode
  60.     )
  61.  
  62.     Write-Host "✔ Utworzono:" $targetFile
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment