Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
fix(translation): wire translate route planning in JobQueue and add test connection button
return {name:"chinchi-codes"}80be80fb5868
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex 3a1ac2c2..f85b4505 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -1301,6 +1301,7 @@"presets.translate_content": "Translate document","presets.translate_hint": "Translates the document or book into the target language on your computer.","presets.target_language": "Target language",+ "presets.test_connection": "Test Connection","engines.package.translator.name": "Translator (Offline AI)","engines.package.translator.description": "Translates documents and books locally on your PC without uploading them. Works offline using local Ollama or bundled models.","engines.package.translator.sizes": "Offline Local AI · http://127.0.0.1:11434",diff --git a/src/Filee.App/Services/PresetAvailability.cs b/src/Filee.App/Services/PresetAvailability.csindex e5a0946c..682f9f05 100644--- a/src/Filee.App/Services/PresetAvailability.cs+++ b/src/Filee.App/Services/PresetAvailability.cs@@ -217,6 +217,24 @@ public sealed class PresetAvailability// "Merge videos" / "Merge audio" / "Video from images": FFmpeg joins the files, so a route into the target (or,// for pictures, into PNG and from PNG into a video) says whether it is installed.+ // "Translate": Ollama / Translator translates documents and e-books.+ if (formats.Any(f => preset.TranslatesDocument(f.Id)))+ {+ var docFiles = formats.Where(f => preset.TranslatesDocument(f.Id)).ToList();+ if (docFiles.Count == 0)+ return new(PresetUse.Unusable, _loc["error.unsupported_source"]);+ bool CanTranslate(RoutePlanner planner) => docFiles.Any(f =>+ {+ var target = TargetFor(f);+ return planner.CanConvert(f.Id, target, translate: true);+ });+ if (CanTranslate(installedPlanner()))+ return new(PresetUse.Usable, null);+ return packageEnabling(CanTranslate) is { } needed+ ? new(PresetUse.NeedsPackage, _loc.Format("engine.reason.needs_package", needed.Name))+ : new(PresetUse.Unusable, _loc["error.no_route"]);+ }+if (preset.JoinsIntoOneMedia){var target = preset.TargetFormat;@@ -245,10 +263,11 @@ public sealed class PresetAvailabilityvar motion = preset.ExtractsMotionOf(f.Id);var live = preset.MakesLivePhotoOf(f.Id);var ocr = preset.RecognizesTextOf(f.Id);+ var translate = preset.TranslatesDocument(f.Id);if (!turns)- return planner.CanConvert(f.Id, target, frames, motionPhoto: motion, livePhoto: live, ocr: ocr);+ return planner.CanConvert(f.Id, target, frames, motionPhoto: motion, livePhoto: live, ocr: ocr, translate: translate);// Rotate / flip: a route only counts when an engine on it turns images (not a PDF or a video copied).- if (planner.Plan(f.Id, target, frames, motionPhoto: motion, livePhoto: live, ocr: ocr) is not { } route)+ if (planner.Plan(f.Id, target, frames, motionPhoto: motion, livePhoto: live, ocr: ocr, translate: translate) is not { } route)return false;if (route.FirstTransformStep() >= 0)return true;diff --git a/src/Filee.App/ViewModels/OllamaModelManagerViewModel.cs b/src/Filee.App/ViewModels/OllamaModelManagerViewModel.csindex 18a57b77..26d13ffa 100644--- a/src/Filee.App/ViewModels/OllamaModelManagerViewModel.cs+++ b/src/Filee.App/ViewModels/OllamaModelManagerViewModel.cs@@ -81,6 +81,43 @@ public sealed partial class OllamaModelManagerViewModel : ObservableObject[ObservableProperty]private string _activeModelName = "";+ [ObservableProperty]+ private string _testResultText = "";++ [ObservableProperty]+ private bool _isTesting;++ [ObservableProperty]+ private bool _testHasError;++ [RelayCommand]+ public async Task TestConnectionAsync()+ {+ if (IsTesting) return;+ IsTesting = true;+ TestHasError = false;+ TestResultText = "Testing translation...";++ try+ {+ var service = new TranslationService();+ var targetLang = "es";+ var result = await service.TranslateTextAsync("Hello, world!", targetLang);+ var model = !string.IsNullOrWhiteSpace(ActiveModelName) ? ActiveModelName : await TranslationService.GetPreferredLocalOllamaModelAsync() ?? "local model";+ TestResultText = $"\"Hello, world!\" → \"{result}\" ({model})";+ TestHasError = false;+ }+ catch (Exception ex)+ {+ TestResultText = $"Failed: {ex.Message}";+ TestHasError = true;+ }+ finally+ {+ IsTesting = false;+ }+ }+partial void OnNewModelNameChanged(string value){var trimmed = value.Trim();diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.csindex 1620c7c7..a422fd4b 100644--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs@@ -4,10 +4,12 @@// Works on a clone; Apply() copies the edits back into the original preset (Cancel = just drop the VM).using CommunityToolkit.Mvvm.ComponentModel;+using CommunityToolkit.Mvvm.Input;using Filee.Core.Formats;using Filee.Core.Localization;using Filee.Core.Presets;using Filee.Engines.Ocr;+using Filee.Engines.Translation;namespace Filee.App.ViewModels;@@ -285,6 +287,39 @@ public sealed partial class PresetEditorViewModel : ObservableObjectpublic bool ShowTranslate => _original.Id == "translate" || _edit.Translate.Enabled;+ [ObservableProperty] private string _testTranslationResult = "";+ [ObservableProperty] private bool _isTestingTranslation;+ [ObservableProperty] private bool _testTranslationHasError;++ [RelayCommand]+ public async Task TestTranslationAsync()+ {+ if (IsTestingTranslation) return;+ IsTestingTranslation = true;+ TestTranslationHasError = false;+ TestTranslationResult = "Connecting to Ollama...";++ try+ {+ var targetLang = TargetLanguage?.Value ?? "es";+ var service = new TranslationService(new TranslateOptions { TargetLanguage = targetLang });+ var sample = "Hello, world!";+ var translated = await service.TranslateTextAsync(sample, targetLang);+ var model = await TranslationService.GetPreferredLocalOllamaModelAsync() ?? TranslationService.ActiveOllamaModel ?? "local model";+ TestTranslationResult = $"\"{sample}\" → \"{translated}\" ({model})";+ TestTranslationHasError = false;+ }+ catch (Exception ex)+ {+ TestTranslationResult = $"Error: {ex.Message}";+ TestTranslationHasError = true;+ }+ finally+ {+ IsTestingTranslation = false;+ }+ }+/// <summary>What "Recognize text" needs: Tesseract, or on a Mac Apple Vision (Tesseract only for other languages).</summary>public string OcrHint { get; }@@ -945,6 +980,8 @@ public sealed partial class PresetEditorViewModel : ObservableObject// black and white chosen for PDF and left behind by a DWG target._original.Cad.Version = ShowCad ? CadVersion.Value : default;_original.Cad.Colors = ShowCadColors ? CadColors.Value : default;+ _original.Translate.TargetLanguage = TargetLanguage.Value;+ _original.Translate.Enabled = ShowTranslate;var output = _original.Output;// Asking keeps the location it had: a Filee that can't ask (or one from before it) saves there.diff --git a/src/Filee.App/Views/OllamaModelManagerWindow.axaml b/src/Filee.App/Views/OllamaModelManagerWindow.axamlindex 965d253c..b18ea3de 100644--- a/src/Filee.App/Views/OllamaModelManagerWindow.axaml+++ b/src/Filee.App/Views/OllamaModelManagerWindow.axaml@@ -23,6 +23,8 @@<Border Classes="card" Padding="14,10"><DockPanel LastChildFill="True"><StackPanel DockPanel.Dock="Right" Orientation="Horizontal" Spacing="8">+ <Button Content="{DynamicResource presets.test_connection}" IsVisible="{Binding IsServerRunning}"+ Command="{Binding TestConnectionCommand}" IsEnabled="{Binding !IsTesting}" /><Button Content="{DynamicResource engines.ollama.stop_server}" IsVisible="{Binding IsServerRunning}"Command="{Binding StopServerCommand}" /><Button Classes="accent" Content="{DynamicResource engines.ollama.start_server}" IsVisible="{Binding !IsServerRunning}"@@ -46,6 +48,16 @@</StackPanel></DockPanel></Border>++ <!-- Test Translation Result -->+ <Border IsVisible="{Binding TestResultText, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"+ Background="{DynamicResource CardBackground}" CornerRadius="6" Padding="10,8">+ <StackPanel Orientation="Horizontal" Spacing="8">+ <TextBlock Text="✓" Foreground="#10b981" FontWeight="Bold" IsVisible="{Binding !TestHasError}" />+ <TextBlock Text="⚠" Foreground="#f59e0b" FontWeight="Bold" IsVisible="{Binding TestHasError}" />+ <TextBlock Text="{Binding TestResultText}" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="12" />+ </StackPanel>+ </Border></StackPanel><!-- Main Content -->diff --git a/src/Filee.App/Views/PresetEditorView.axaml b/src/Filee.App/Views/PresetEditorView.axamlindex 370e3b57..85617b29 100644--- a/src/Filee.App/Views/PresetEditorView.axaml+++ b/src/Filee.App/Views/PresetEditorView.axaml@@ -252,7 +252,7 @@<Grid ColumnDefinitions="*,12,*">- <StackPanel>+ <StackPanel Grid.Column="0"><TextBlock Classes="label" Text="{DynamicResource presets.target_language}" />@@ -260,8 +260,28 @@</StackPanel>+ <StackPanel Grid.Column="2" VerticalAlignment="Bottom">++ <Button Classes="secondary" Command="{Binding TestTranslationCommand}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" IsEnabled="{Binding !IsTestingTranslation}">+ <StackPanel Orientation="Horizontal" Spacing="6">+ <TextBlock Text="⚡" />+ <TextBlock Text="{DynamicResource presets.test_connection}" />+ </StackPanel>+ </Button>++ </StackPanel>+</Grid>+ <Border IsVisible="{Binding TestTranslationResult, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"+ Background="{DynamicResource CardBackground}" CornerRadius="6" Padding="10,8">+ <StackPanel Orientation="Horizontal" Spacing="8">+ <TextBlock Text="✓" Foreground="#10b981" FontWeight="Bold" IsVisible="{Binding !TestTranslationHasError}" />+ <TextBlock Text="⚠" Foreground="#f59e0b" FontWeight="Bold" IsVisible="{Binding TestTranslationHasError}" />+ <TextBlock Text="{Binding TestTranslationResult}" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="12" />+ </StackPanel>+ </Border>+</StackPanel></Border>diff --git a/src/Filee.Core/Conversion/ConversionJob.cs b/src/Filee.Core/Conversion/ConversionJob.csindex aea9aa2f..ac1dda7d 100644--- a/src/Filee.Core/Conversion/ConversionJob.cs+++ b/src/Filee.Core/Conversion/ConversionJob.cs@@ -87,7 +87,7 @@ public sealed class FileResult/// <summary>The source, target and constraints of a route planning request.</summary>public sealed record RouteRequest(string Source, string Target, bool Frames = false, bool Shaping = false,- bool MotionPhoto = false, bool LivePhoto = false, bool Ocr = false);+ bool MotionPhoto = false, bool LivePhoto = false, bool Ocr = false, bool Translate = false);/// <summary>A batch of files converted with one preset.</summary>public sealed class ConversionJobdiff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.csindex 7c1c0b8e..fb5c8520 100644--- a/src/Filee.Core/Conversion/JobQueue.cs+++ b/src/Filee.Core/Conversion/JobQueue.cs@@ -771,13 +771,14 @@ public sealed partial class JobQueue : IAsyncDisposablevar motionPhoto = finalOutput && runWith.ExtractsMotionOf(source.Id);var livePhoto = finalOutput && runWith.MakesLivePhotoOf(source.Id);var caption = finalOutput && runWith.CaptionsVideo(source.Id);+ var translate = finalOutput && runWith.TranslatesDocument(source.Id);// "Recognize text": Tesseract writes a searchable PDF first, read on into DOCX, TXT, … from there. Also for the// PDFs that are merged into one.var ocr = (finalOutput || target == "pdf") && runWith.RecognizesTextOf(source.Id);- var route = planner.Plan(source.Id, target, frames, motionPhoto: motionPhoto, livePhoto: livePhoto, ocr: ocr, caption: caption);+ var route = planner.Plan(source.Id, target, frames, motionPhoto: motionPhoto, livePhoto: livePhoto, ocr: ocr, caption: caption, translate: translate);if (route is null)return Fail(file, "error.no_route", $"{source.Id} → {target}",- new RouteRequest(source.Id, target, Frames: frames, MotionPhoto: motionPhoto, LivePhoto: livePhoto, Ocr: ocr));+ new RouteRequest(source.Id, target, Frames: frames, MotionPhoto: motionPhoto, LivePhoto: livePhoto, Ocr: ocr, Translate: translate));// A step that draws text without shaping (rhwp) would break Arabic, Hebrew, Indic or Thai text: such a file// takes a route without it (LibreOffice), or is refused with the reason rather than written broken. Onediff --git a/src/Filee.Core/Conversion/RoutePlanner.cs b/src/Filee.Core/Conversion/RoutePlanner.csindex 796058f0..a157d956 100644--- a/src/Filee.Core/Conversion/RoutePlanner.cs+++ b/src/Filee.Core/Conversion/RoutePlanner.cs@@ -98,7 +98,7 @@ public sealed class RoutePlannercaption &= !frames && !motionPhoto && !livePhoto;translate &= !frames && !motionPhoto && !livePhoto && !caption;var special = EdgesFrom(from)- .Where(e => e.Edge.To == to && (frames ? e.Edge.FrameSequence : motionPhoto ? e.Edge.MotionPhoto : livePhoto ? e.Edge.LivePhoto : caption ? e.Edge.Caption : e.Edge.Translate))+ .Where(e => e.Edge.To == to && (frames ? e.Edge.FrameSequence : motionPhoto ? e.Edge.MotionPhoto : livePhoto ? e.Edge.LivePhoto : caption ? e.Edge.Caption : translate ? e.Edge.Translate : false)).OrderBy(e => e.Cost).FirstOrDefault();return special.Converter is null@@ -173,7 +173,7 @@ public sealed class RoutePlanner/// <param name="ocr">Recognize the text first (see <see cref="Plan"/>).</param>/// <param name="caption">Transcribe speech to SRT subtitles using Whisper (see <see cref="Plan"/>).</param>public bool CanConvert(string from, string to, bool frames = false, bool motionPhoto = false, bool livePhoto = false, bool ocr = false, bool caption = false, bool translate = false) =>- Plan(from, to, frames, motionPhoto: motionPhoto, livePhoto: livePhoto, ocr: ocr, caption: caption) is not null;+ Plan(from, to, frames, motionPhoto: motionPhoto, livePhoto: livePhoto, ocr: ocr, caption: caption, translate: translate) is not null;private Route? PlanWithOcr(string from, string to, bool shaping){diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.csindex 4c13b701..b5434f83 100644--- a/src/Filee.Core/Presets/Preset.cs+++ b/src/Filee.Core/Presets/Preset.cs@@ -1310,7 +1310,7 @@ public sealed class TranslateOptions{- public bool Enabled { get; set; } = true;+ public bool Enabled { get; set; } = false;public string TargetLanguage { get; set; } = "en";diff --git a/src/Filee.Engines/Translation/TranslationService.cs b/src/Filee.Engines/Translation/TranslationService.csindex 9c20e55b..d814ab38 100644--- a/src/Filee.Engines/Translation/TranslationService.cs+++ b/src/Filee.Engines/Translation/TranslationService.cs@@ -94,11 +94,11 @@ public sealed class TranslationService : ITranslationServiceif (names.Count == 0)return null;- if (!string.IsNullOrWhiteSpace(ActiveOllamaModel) && names.Contains(ActiveOllamaModel, StringComparer.OrdinalIgnoreCase))- return ActiveOllamaModel;+ if (!string.IsNullOrWhiteSpace(ActiveOllamaModel) && names.Any(n => string.Equals(n, ActiveOllamaModel, StringComparison.OrdinalIgnoreCase) || n.StartsWith(ActiveOllamaModel + ":", StringComparison.OrdinalIgnoreCase)))+ return names.First(n => string.Equals(n, ActiveOllamaModel, StringComparison.OrdinalIgnoreCase) || n.StartsWith(ActiveOllamaModel + ":", StringComparison.OrdinalIgnoreCase));// Prefer specialized or standard instruction models- string[] preferred = ["qwen2.5", "llama3.2", "llama3", "mistral", "gemma2", "phi3", "phi4"];+ string[] preferred = ["translategemma", "qwen2.5", "llama3.2", "llama3", "mistral", "gemma2", "phi3", "phi4"];foreach (var p in preferred){var match = names.FirstOrDefault(n => n.StartsWith(p, StringComparison.OrdinalIgnoreCase));diff --git a/src/Filee.Engines/Translation/TranslatorConverter.cs b/src/Filee.Engines/Translation/TranslatorConverter.csindex b0a09180..8d497c6e 100644--- a/src/Filee.Engines/Translation/TranslatorConverter.cs+++ b/src/Filee.Engines/Translation/TranslatorConverter.cs@@ -48,23 +48,38 @@ public sealed class TranslatorConverter : IConverterDocumentFormats.Select(to => new ConversionEdge(from, to, from == to ? 10 : 12, Translate: true))).ToList();+ private static readonly HttpClient SharedStatusClient = new() { Timeout = TimeSpan.FromMilliseconds(200) };+ private static (DateTime CheckedAt, bool Available) _cachedOllama;+public EngineStatus GetStatus(){if (_translationService is not null)return EngineStatus.Available("embedded", "Test Translator");- try+ var now = DateTime.UtcNow;+ bool isAvailable;+ if (now - _cachedOllama.CheckedAt < TimeSpan.FromSeconds(3)){- using var client = new HttpClient { Timeout = TimeSpan.FromMilliseconds(300) };- var res = client.GetAsync("http://127.0.0.1:11434/api/tags").GetAwaiter().GetResult();- if (res.IsSuccessStatusCode)- return EngineStatus.Available("http://127.0.0.1:11434", "Ollama (Local Offline)");+ isAvailable = _cachedOllama.Available;}- catch+ else{- // Local Ollama not running+ try+ {+ using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(150));+ using var res = SharedStatusClient.GetAsync("http://127.0.0.1:11434/api/tags", cts.Token).GetAwaiter().GetResult();+ isAvailable = res.IsSuccessStatusCode;+ }+ catch+ {+ isAvailable = false;+ }+ _cachedOllama = (now, isAvailable);}+ if (isAvailable)+ return EngineStatus.Available("http://127.0.0.1:11434", "Ollama (Local Offline)");+if (TranslationService.LocateLocalEngine() is { } cli && File.Exists(cli))return EngineStatus.Available(cli, "Translator (Local)");