From c8f36c9c25a81787f56e90753d47a53bfce9a941 Mon Sep 17 00:00:00 2001 From: yusufipk Date: Fri, 12 Jun 2026 22:56:36 +0200 Subject: [PATCH] Fix provider selection bug and polish PR before merge. Define provider in startTranslation, restore README screenshot, document optional pre-processing and provider behavior, and remove leftover debug logging. --- README.md | 27 ++++++++++++++++++++++++++- src/app.js | 7 +------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 03e69e1..f032f3d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A powerful, browser-based tool for translating SRT subtitle files using AI. Built for speed, accuracy, and ease of use. +![SRT Translator UI](assets/ui.webp) + ## 🎯 What Problem Does It Solve? Translating subtitles is tedious and expensive: @@ -10,7 +12,7 @@ Translating subtitles is tedious and expensive: - **Existing tools** don't handle the unique challenges of SRT format (split sentences, timing markers, etc.) **SRT Translator** solves this by: -1. Preserving all timestamps exactly as-is +1. Preserving original timestamps by default (optional timing extension is available) 2. Using a smart marker system to maintain line-by-line correspondence 3. Processing chunks in parallel for maximum speed 4. Allowing custom instructions for domain-specific terminology @@ -126,6 +128,29 @@ Actual: 23 blocks (because sentence ends at block 23) 2. **Natural Translation** - Idiomatic, not word-for-word 3. **Word Count** (Soft) - Similar length per line when possible +### Optional Pre-processing (Off by Default) + +These checkboxes change subtitle blocks **before** translation. They are disabled by default so the core chunking and marker logic stays unchanged unless you opt in. + +| Option | What it does | Important notes | +|--------|--------------|-----------------| +| **Merge short split sentences** | Joins very short trailing blocks (e.g. a single word) into the previous block when they look like the same sentence | Reduces block count, which also changes chunk boundaries. Heuristics are tuned for Latin-script subtitles (punctuation + capital-letter checks). Test on your language before relying on it. | +| **Extend short subtitles** | Extends blocks shorter than ~1.3s, keeping a 50ms gap before the next subtitle | Modifies timestamps. Useful for readability, but no longer a byte-for-byte timing copy. | + +### API Provider Notes + +- **Google AI Studio** and **OpenRouter** use separate API keys, each stored in `localStorage` under its own key. +- Default model IDs differ by provider: `gemini-3.1-flash-lite` (Google) vs `google/gemini-3.1-flash-lite` (OpenRouter). +- If you switch providers, clear or update the custom model field when the model ID format does not match the new provider. +- API keys are trimmed on save, load, and request to avoid accidental whitespace causing auth failures. +- On Gemini free tier, keep **Parallel Requests** at `5` (default) to stay under typical RPM quotas. Increase only if your plan allows it. + +### RTL Output (Arabic & Persian) + +For Arabic and Persian targets, translated lines receive: +- RTL punctuation normalization (`،`, `؟`, `؛`) +- Unicode bidirectional markers (RLM, RLE, PDF) so mixed English/RTL text renders correctly in players like VLC + ## 📁 Project Structure ``` diff --git a/src/app.js b/src/app.js index 697b1a4..5935176 100644 --- a/src/app.js +++ b/src/app.js @@ -638,6 +638,7 @@ async function startTranslation() { if (!apiKey || !srtContent) return; // Get settings + const provider = elements.apiProvider.value; const defaultModel = provider === 'openrouter' ? DEFAULT_MODEL_OPENROUTER : DEFAULT_MODEL_GEMINI; const model = elements.customModel.value.trim() || defaultModel; const targetLanguage = elements.targetLanguage.value; @@ -680,12 +681,6 @@ async function startTranslation() { const blockCount = chunk.length; const textLength = chunk.reduce((sum, b) => sum + b.text.join(' ').length, 0); - // Debug for problematic chunks - if (index === 107) { - log(`⚠️ CHUNK 108 DEBUG: ${blockCount} blocks, ${textLength} chars`, 'error'); - console.log('Chunk 108 content:', chunk); - } - try { log(`Chunk ${index + 1} starting (${blockCount} blocks, ${textLength} chars)...`, 'info');