Skip to content

Studio: show the detected language in Translate and let swap use it - #18263

Merged
danielhanchen merged 4 commits into
mainfrom
studio-translate-detected-language
Nov 18, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-translate-detected-language

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Addresses items 3 and 4 of #18198 (follow-up to #18220, which covered items 1, 2, 6 and the read aloud fallback).

What changes

  • Detected language on the source pill (item 4). With "Detect language" selected, the pill now reads e.g. Hindi (detected) once the text is clear enough to tell, and goes back to Detect language when it is not. The pill stays in automatic mode; nothing is sent to the model differently.
  • Swap with the detected language (item 3). Swap was disabled in automatic mode. It now works like Google Translate and LibreTranslate: the detected language becomes the target, the old target becomes the source, and a finished translation moves into the text box (an edited draft is still never replaced). With nothing detected, or when the text is already in the target language, the button stays disabled with the same tooltip as before.

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):

  • Scripts only one Translate language uses decide alone: Korean, Thai, Khmer, Burmese, Tibetan, Hebrew, Bengali, Tamil, Telugu, Gujarati. Kana means Japanese.
  • Han text: Cantonese particles, else Traditional vs Simplified character forms (nothing when neither shows up, e.g. 你好).
  • Arabic script: Uyghur and Urdu letters, else Persian vs Arabic letter forms. Cyrillic: Kazakh letters, Mongolian letters and words, else Ukrainian vs Russian letters and words.
  • Latin script and Devanagari: common function words plus letters only one language uses. It returns nothing unless one language clearly beats the runner-up, so a short or ambiguous text shows plain Detect language instead of a wrong guess.

Accuracy

Held-out FLORES-200 devtest (1,012 sentences per language, all 38 Translate languages; the word lists were tuned on dev only):

Input Right Wrong Nothing shown
Full sentence 92.1% 2.7% 5.2%
First 5 words 78.7% 3.4% 17.9%
First 30 characters 76.0% 3.6% 20.4%

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 with TRANSLATE_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 build and npm run bundle:check pass. The new translate.detectedLanguage key 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)
detected

After clicking Swap: source English, target Hindi (before: nothing happens)
after swap

Fixes #18198

@danielhanchen danielhanchen self-assigned this Nov 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T08:51:50.069014Z 1f137c7 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d2c69cb9ac

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 1f137c7238

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 1537201 into main Nov 18, 2026
@danielhanchen
danielhanchen deleted the studio-translate-detected-language branch November 18, 2026 10:14
shimmyshimmer added a commit that referenced this pull request Nov 18, 2026
… 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:

![Translate
page](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/18293/pq_pr_page-0138c394fac9.png)

The selected tab in light mode, before and after:

![Selected
tab](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/18293/pq_tabs_light_before_after-f77f15e2ced5.png)

Glass theme over a wallpaper, light and dark:

![Glass
light](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/18293/pq_glass_after_light-ef57cd699024.png)

![Glass
dark](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/18293/pq_glass_after_dark-d0cd6293b207.png)

The full language list opens under its own pane, at the pane's width and
corners:

![Language
list](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/18293/pq_pr_list-e4d11e9ca8e3.png)

A model that is not on disk asks before downloading:

![Download
prompt](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/18293/pq_pr_dialog-4ff4d2a60755.png)

---------

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Unsloth Desktop Translation Mode Improvements Part 1

1 participant