SE UI batch convert: add "Try to use source encoding" option - fix #11019#11039
Merged
Conversation
…1019 Restores the WinForms-era "Try to use source encoding" entry to the target-encoding dropdown in batch convert (both the settings dialog and the main view). Also fixes a latent bug where the selected encoding never reached disk: SaveSubtitleFormat was passing the encoding string as the "title" arg to ToText() and then calling File.WriteAllTextAsync without an encoding, so output always landed as UTF-8 without BOM regardless of the user's choice. Encoding is now resolved through EncodingHelper.ResolveEncoding and passed to the write, with the new sentinel detecting per-file via LanguageAutoDetect. Defaults are pinned to UTF-8 with BOM (instead of "first item in the list") so existing installs don't migrate onto the new option. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Restores the Try to use source encoding target-encoding option in the Batch Convert UI and fixes batch-convert output encoding so the user’s selected encoding is actually used when writing converted subtitle files.
Changes:
- Add a stable sentinel string for “Try to use source encoding” and a new
EncodingHelper.ResolveEncoding(...)resolver (including per-file detection viaLanguageAutoDetect). - Insert the new option into both the Batch Convert main view and Settings dialog encoding dropdowns, and pin the default to UTF-8 with BOM when no saved value exists.
- Fix the batch-convert save path to pass a real
titleintoToText(...)and to write output with the resolvedEncoding(instead of always defaulting to UTF-8 without BOM).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ui/Logic/EncodingHelper.cs | Adds the source-encoding sentinel plus a resolver that maps stored display names to a concrete Encoding. |
| src/ui/Features/Tools/BatchConvert/BatchConvertViewModel.cs | Adds the new dropdown option and ensures default selection remains UTF-8 with BOM when unset/unknown. |
| src/ui/Features/Tools/BatchConvert/BatchConvertSettingsViewModel.cs | Mirrors dropdown option + defaulting logic in the settings dialog and avoids defaulting to the new sentinel. |
| src/ui/Features/Tools/BatchConvert/BatchConverter.cs | Fixes ToText argument usage and writes output using the resolved encoding. |
Comment on lines
+51
to
+52
| /// sentinel by detecting the source file's encoding. Falls back to UTF-8 with BOM | ||
| /// when the name is empty, unknown, or detection fails. |
Comment on lines
+76
to
+77
| var match = GetEncodings().FirstOrDefault(e => e.DisplayName == displayName); | ||
| return match?.Encoding ?? new UTF8Encoding(true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SaveSubtitleFormatwas passing_config.TargetEncodingas thetitlearg toToText()and writing viaFile.WriteAllTextAsyncwithout an encoding, so output always landed as UTF-8 without BOM regardless of the user's choice. Encoding is now resolved throughEncodingHelper.ResolveEncodingand passed to the write.LanguageAutoDetect.GetEncodingFromFile(item.FileName).Test plan
Se.Settings.Tools.BatchConvert.TargetEncoding→ default is UTF-8 with BOM, not the new option.dotnet test tests/UI/UITests.csproj— 188/188 passing.🤖 Generated with Claude Code