Repository navigation
Studio: show the detected language in Translate and let swap use it - #18263
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1d9827365
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…es, reads NFD text, and skips a same-language swap [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… uploads (#18293) ## Summary Translate is laid out like a familiar translation app: language tabs over two side-by-side panes, every action inside the panes, and documents or images can be opened or dropped onto the page. It builds on #18263 (detected language), which is now in `main`, so this diff is the redesign only. ## Changes **Languages** - Each pane has a row of pill tabs: Detect language plus up to three recent source languages, and up to three recent targets. Picking a tab never reorders or drops them; a language from the full list joins at the front. - With Detect language selected, the tab reads e.g. "English - Detected". - In light mode the selected tab is the white, softly shadowed pill of Studio's other segmented controls. - The chevron opens the full list under that pane only, at the pane's exact width and corners: a search row on top, languages in columns, the current one highlighted and ticked. - The swap button sits between the two rows. **Panes** - The page is wider (up to 96rem, following the UI scale). - Both panes start at the same height and grow with the longer text until the bottom of the window, then scroll, with the last lines fading while more text is below. - A classic page scrollbar no longer narrows them. - With the glass theme and a wallpaper, both panes and the model chip frost like the rest of Studio. **Source pane footer** - Dictate, open file, the character count, a Style · Tone menu and the Translate button. - Paste is gone; Ctrl/Cmd+V still works. - The count shows only the number typed; the 50,000 limit appears on hover and in a tooltip. - An empty box keeps the Translate button as a faded pill. - In a narrow pane the count hides and the style menu shortens, so the Translate button is never cut off. **Translation pane footer:** read aloud, chat, use as source and copy, at the same size as the source pane's icons. **Voice** - The mic is always offered. Where this browser cannot dictate, a click explains why or offers local dictation, as in chat. - With Detect language, local and custom transcription let the model identify the spoken language (Japanese speech used to come back as English romaji). The browser's own engine cannot detect and keeps the user's language. - Read aloud and dictation ask for a regional voice: the user's own region when they list one, else the language's main one (French was read by a Canadian voice on macOS). **Files** - Open file and drag and drop (anywhere on the page) accept text, PDF, Word, Excel, PowerPoint, OpenDocument, RTF, EPUB, email and images. - Documents use the existing `/api/rag/extract-text` reader. - `extract-text` now also reads images, through the loaded vision model, else local Tesseract. Images are decoded with Pillow at their own pixels (WebP included, on white, upright), shrunk to a letter page at the OCR DPI, and refused over 50 MP before decoding. When nothing can read one it returns a 422 that says so. - While a file is read the text box is read-only and a second drop is refused; a result that arrives after the text was replaced another way is dropped. **Model download** - A first translation with a model that is not on disk asks first, in the same dialog style as dictation: "Download Hy-MT2 7B?" with its size. A click before the page's model check has answered runs the check itself. - Progress stays in the shared downloads toast. The in-page progress bar and the "loading" bar while translating are removed; an empty translation pane shows a short status instead. **Sidebar:** Translate's big BETA chip in the More menu is the small "New" tag Settings uses. On the page, the Beta tag is larger and centred on the title. New and changed strings are translated for all 25 locales. ## Verification In a running Studio (Chromium; WebKit for the layout and scrollbar checks): - Tabs keep their order; picking Japanese from the list puts it first; Detect language keeps a tab saved before recent sources existed. - The list matches its pane: same x, width, top and corners. - Pane heights grow, then cap near the window bottom; the fade shows only while more text is below. - A test PDF and DOCX opened into the box, including a PDF dropped outside the box. A PNG without a vision model gave the 422 message. - The download dialog appeared for the 7B model (not on disk) and Cancel started nothing. - Glass light and dark with a wallpaper: both panes take the page glass fill and blur (computed styles checked). - Read aloud with macOS voices: Japanese by Kyoko (ja-JP), French by Jacques (fr-FR), Stop and the end of speech reset the button. - Local dictation with Whisper Tiny and a fake microphone: the download prompt, then English and Japanese speech transcribed into the box, Japanese with Detect language. - A 1024px window: the source footer fits with the Translate button whole. `npm run typecheck`, `npm test` and `npm run build` pass. Backend `tests/test_rag_extract_text.py` (WebP, DPI tags, the pixel budget, transparency, EXIF orientation, the decode cap, Tesseract at 1:1), `test_pdf_local_ocr.py` and `test_middleware.py` pass. Biome reports nothing new compared with `main`. ## Not covered - Image reading with a real vision model loaded was not run on this CPU host; it is covered by tests with the model call stubbed. Tesseract is not installed here either. - Browser (Web Speech) dictation needs Google's servers and was not run; read aloud through a Studio speech model was not run. - The Desktop (Tauri) webview and native file drops were not run from this host. ## Screenshots The page with English detected, recent languages as tabs and every action inside the panes:  The selected tab in light mode, before and after:  Glass theme over a wallpaper, light and dark:   The full language list opens under its own pane, at the pane's width and corners:  A model that is not on disk asks before downloading:  --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Unsloth <[email protected]>
Addresses items 3 and 4 of #18198 (follow-up to #18220, which covered items 1, 2, 6 and the read aloud fallback).
What changes
Hindi (detected)once the text is clear enough to tell, and goes back toDetect languagewhen it is not. The pill stays in automatic mode; nothing is sent to the model differently.How detection works
detect-language.ts, no new dependency, runs on the first 2,000 characters on each edit (about 0.2 to 0.4 ms per call here):你好).Detect languageinstead of a wrong guess.Accuracy
Held-out FLORES-200
devtest(1,012 sentences per language, all 38 Translate languages; the word lists were tuned ondevonly):Most of the "wrong" row is FLORES Cantonese, which is written as formal Chinese and comes back as Traditional Chinese (971 of 1,012). Without it, full sentences are wrong 0.2% of the time. Kazakh fragments that only show ө or ү plus і read as Kazakh, not Mongolian. Indonesian and Malay share most of their words, so those two usually show nothing rather than risk the other one.
Tests
tests/translate-detect-language.test.ts: a sentence and a short phrase for every Translate language, the list kept in sync withTRANSLATE_LANGUAGES, and short / ambiguous inputs returning nothing.tests/translate-store.test.ts: swap in automatic mode is a no-op without a detected language and swaps with one; it fails on main.npm run typecheck,npm run i18n:check:strict,vite buildandnpm run bundle:checkpass. The newtranslate.detectedLanguagekey is in all 25 locales.Before / after (merge base ff6c71b vs head a1d9827, Chromium)
Detect language selected, target English, a Hindi sentence typed. No model loaded, so only the pills and the Swap button are under test.
Source pill names the detected language; Swap is enabled (before:

Detect language, Swap disabled)After clicking Swap: source English, target Hindi (before: nothing happens)

Fixes #18198