Skip to content

feat(studio): add Amharic and popular African languages to Translate (#18723) - #18738

Merged
danielhanchen merged 15 commits into
unslothai:mainfrom
Fahad090NP:fix/18723-translate-amharic-african-languages
Nov 23, 2026
Merged

danielhanchen merged 15 commits into
unslothai:mainfrom
Fahad090NP:fix/18723-translate-amharic-african-languages

Conversation

@Fahad090NP

@Fahad090NP Fahad090NP commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Related to #18723

Summary

Adds official support and automatic script/language detection in Unsloth Translate for Amharic (am) along with popular African continent languages (Swahili sw, Hausa ha, Yoruba yo, Igbo ig, Zulu zu, Afrikaans af, and Somali so).

Changes

  • studio/frontend/src/features/translate/languages.ts
    • Add am (Amharic), sw (Swahili), ha (Hausa), yo (Yoruba), ig (Igbo), zu (Zulu), af (Afrikaans), and so (Somali) to TRANSLATE_LANGUAGES.
  • studio/frontend/src/features/translate/detect-language.ts
    • Add [/\p{Script=Ethiopic}/gu, "am"] to SINGLE_SCRIPT so Ethiopic/Ge'ez script text is recognized as Amharic.
    • Add sw, ha ("ɓɗƙ"), yo ("ẹọṣ"), ig ("ịụṅ"), zu, af, and so entries to LATIN.
    • Exclude the four plain dot-below vowels (ẹ, ị, ọ, ụ) used by Yoruba and Igbo from the Vietnamese /[ơưđăạ-ỹ]/gu shortcut (/(?![ẹịọụ])[ơưđăạ-ỹ]/gu) so Yoruba and Igbo are not misclassified as Vietnamese.
  • studio/frontend/tests/translate-detect-language.test.ts
    • Add sentences and short phrases for am, sw, ha, yo, ig, zu, af, and so to SENTENCES, verifying all supported Translate languages are recognized without collisions.

Before and After

Before

Before (#18723)

After

After (#18723)

Verification

  • node --experimental-strip-types --test tests/translate-*.test.ts (studio/frontend): 54/54 passed
  • npm run typecheck (studio/frontend): passed (0 errors)

Maintainer follow-ups

This branch builds on #18737 (merged in), which marks languages outside Hy-MT2's model card as chatOnly: they are offered and detected only when a chat model translates, and with Hy-MT2 (the default) the page behaves exactly as before. Merge #18737 first.

Detection: the original word lists were built from the test sentences, so everyday text in most of these languages was not detected. Measured on held-out sentences from the Universal Declaration of Human Rights translations (sentence level):

Language main this PR as submitted now
Amharic 0/62 62/62 62/62
Swahili 0/83 25/83 78/83
Hausa 0/82 13/82 80/82
Yoruba 0/86 (85 read as Vietnamese) 84/86 84/86
Igbo 0/72 (71 read as Vietnamese) 50/72 72/72
Zulu 0/69 4/69 61/69
Afrikaans 0/73 (66 read as Dutch) 0/73 (66 read as Dutch) 62/73
Somali 0/78 17/78 74/78
  • The lists now hold each language's common function words; Zulu, Swahili and Somali also score typical word shapes (noun class and verb prefixes, long vowels with x / q / dh).
  • A new language only scores when the text has evidence no Hy-MT2 language's list holds (one of its own words, letters or word shapes), so it can never take a verdict away from English, Dutch, French, Portuguese, Tagalog and the rest. Afrikaans shares only the words already on the Dutch list and wins on its own words.
  • Short Vietnamese phrases ("Mẹ ơi", "Dịch vụ", "Chị bị ho hôm qua") are Vietnamese again, while Yoruba and Igbo text is no longer read as Vietnamese.
  • No verdict moved for any of the 38 existing languages across 42,597 UDHR sentences in 537 translations, nor across 2,945 English sentences from the repo docs.

Before / after, translating with a chat model (picker gains the new languages; Afrikaans was read as Dutch):

chat model

Before / after with Hy-MT2 1.8B, the default (same 38 languages; Afrikaans is no longer misread as Dutch):

Hy-MT2

Tests: node --experimental-strip-types --test tests/translate-*.test.ts 59/59, npm run typecheck clean.

…ained on it

Languages outside Hy-MT2's model card are marked chatOnly: the picker, the
recent tabs and Detect language hide them while Hy-MT2 translates, a
chat-only pick falls back to the last Hy-MT2 target when switching to it,
and the browser-locale default target never picks one. Adds more common
Hmong function words for detection.
…ained on it

Languages outside Hy-MT2's model card are marked chatOnly: the picker, the
recent tabs and Detect language hide them while Hy-MT2 translates, a
chat-only pick falls back to the last Hy-MT2 target when switching to it,
and the browser-locale default target never picks one. Adds more common
Hmong function words for detection.

[skip ci]
…ryday text

The word lists were built from the test sentences, so real text in most of
these languages came back undetected (UDHR sentences: Afrikaans 0/73,
Zulu 4/69, Hausa 13/82). They now hold each language's common function
words, Zulu, Swahili and Somali also score their word shapes, and Dutch and
Afrikaans share their common words so only the ones the other lacks decide.
Short Vietnamese phrases such as "Mẹ ơi" are Vietnamese again: only text with
no Vietnamese-only letter leaves the dot-below vowels to Yoruba and Igbo.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@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: 77258470c8

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


setPrefs: (patch) => {
const prefs = { ...get().prefs, ...patch };
const prefs = fitLanguages({ ...get().prefs, ...patch });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve saved language metadata when restoring history

After translating into a chat-only language, switching to Hy-MT2 and reopening that history entry silently changes its output language metadata. restore() calls setTarget(entry.target), which this new fitting step coerces to a supported fallback, then constructs result from those modified preferences while retaining the original output. For example, a saved Swahili translation can reopen with result.target === "en" and translationIsStale() === false, causing read-aloud and “Use as source” to treat Swahili as English. Preserve the entry's actual language metadata, or select a compatible model, when restoring it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 3109555 (merged here): restore keeps the entry's own languages on the shown result, so it reads as stale instead of relabelling the output.

Comment on lines +240 to +241
const vietnamese = count(text, /(?![ẹịọụ])[ơưđăạ-ỹ]/gu);
if (vietnamese > 0 && vietnamese + countOf(text, "ẹịọụ") >= 2) return "vi";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add Vietnamese disambiguation for shared dot-below vowels

When a Vietnamese phrase's only distinctive characters are the excluded vowels, this condition skips Vietnamese detection entirely, and there is no Vietnamese word scorer in LATIN to recover it. Meanwhile, ị and ụ contribute Igbo scores: Dịch vụ, Dịch vụ công, and Dịch vụ du lịch all return ig in this commit versus vi in its parent. Chat models therefore show the wrong detected language, while the default Hy-MT2 page filters that result to null and disables automatic-source swapping. Add Vietnamese word/context evidence for shared-vowel cases rather than letting those vowels alone select Igbo.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in bbc9cef: a dot-below vowel closed by c, ch, ng, nh, p or t (dịch, lịch) is counted as Vietnamese, so "Dịch vụ" and "Dịch vụ du lịch" are vi again; no verdict moved on any of the 42,597 UDHR sentences otherwise.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 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-22T16:55:43.313258Z 0822119 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.

Restoring a Hmong translation while Hy-MT2 is selected falls the target back
to a Hy-MT2 language; the shown result now keeps the entry's languages, so
it reads as stale and read aloud / use as source still treat it as Hmong.
# Conflicts:
#	studio/frontend/src/features/translate/languages.ts
#	studio/frontend/tests/translate-detect-language.test.ts
#	studio/frontend/tests/translate-page.test.ts
#	studio/frontend/tests/translate-store.test.ts
…mese

"Dịch vụ" has only the dot-below vowels Yoruba and Igbo share, so it read as
Igbo; a dot-below vowel closed by c, ch, ng, nh, p or t is Vietnamese only.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

Only the shown result keeps the entry's languages; the attempt snapshot
matches the settings, so translating as you type leaves the saved output.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 22, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 22, 2026

@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: 5106926f7f

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

],
af: [
words(
`${DUTCH_AFRIKAANS} nie ek jy hy sy hulle julle vir baie sal mekaar hul sê hoekom mense dankie asseblief hom n sodat teen elkeen kry dis my`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Disambiguate English input before selecting Afrikaans

For English input such as My net income is $1000., this entry scores my, net, and is for Afrikaans, while English scores only my and is, so detectTranslateLanguage() now returns af instead of the parent's correct en. With a chat model, the page consequently labels the source as Afrikaans and swapping selects Afrikaans as the reverse target; with Hy-MT2, the new supported-language filter suppresses the result and disables automatic-source swapping. Add distinguishing word or context evidence and regression coverage so these shared tokens do not select Afrikaans on ordinary English input.

Useful? React with 👍 / 👎.

A chat-only language now scores only with evidence no Hy-MT2 language's list
holds (one of its own words, letters or word shapes), the Dutch list is back
to main's, Afrikaans drops my / teen / n / ê, and the Swahili and Somali word
shapes no longer match Tagalog ku- words or English queen / sixteen. Short
Vietnamese with only shared dot-below vowels ("Chị bị ho hôm qua") is scored
by common Vietnamese words. Ethiopic counts letters only. No verdict moves for
any existing language across 42,597 UDHR sentences.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: 5a3658d196

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

Comment on lines +279 to +280
tokens.some(
(token) => known.has(token) && !HY_MT2_WORDS.has(token),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require language-specific evidence before enabling chat-only scores

HY_MT2_WORDS contains only the existing cue lists, so absence from it does not establish that a token is specific to a chat-only language. For example, ordinary Dutch nou passes this gate for Afrikaans: detectTranslateLanguage("Hoe is het nou?") now returns af, versus nl in the parent. Likewise, English game enables Hausa, changing "A game with a ball." from en to null. With automatic source detection and a different target selected, these inputs lose their detected-language label and Swap action under Hy-MT2; a chat model incorrectly labels the Dutch text as Afrikaans and selects Afrikaans when swapping. Require additional discriminating evidence for these shared words and add these cases to the regression tests.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 0822119: words on the chat-only lists that the Hy-MT2 languages also write (nou, game, lub, ces, site, ...) no longer open a chat-only language's score, and Afrikaans drops nou. Both cases are in the regression test; no verdict moves for any existing language across the 42,597 UDHR sentences or 2,945 English sentences from the repo docs.

…guage score

Dutch "nou" let Afrikaans score and English "game" let Hausa score; such
words (from the chat-only lists, found in the other languages' text) no
longer count as a chat-only language's own evidence, and Afrikaans drops nou.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0822119ae1

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

# Conflicts:
#	studio/frontend/src/features/translate/detect-language.ts
#	studio/frontend/src/features/translate/languages.ts
#	studio/frontend/tests/translate-detect-language.test.ts
#	studio/frontend/tests/translate-page.test.ts
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…Run settings close (#18984)

## Summary

`Chat UI Tests (extra)` fails intermittently on unrelated PRs at the
same step of `tests/studio/playwright_model_config.py`:

```
[ui-modelcfg] STEP Hub Run opens run settings on a page loaded at /hub
[ui-modelcfg] OK Hub Run kept run settings open on a page loaded at /hub
[ui-modelcfg] FAIL: composer could not be focused after the Hub Run settings closed
```

Seen on #18871 (09:37) and #18738 (20:00) today. Neither touches the
chat composer or the model picker, and the same suite passes on other
runs.

The step presses Escape, waits for the run settings to hide, then calls
`focus()` on the composer in one `evaluate` and reads
`document.activeElement` in a second. The run settings live in the model
picker, a Radix `Popover`, which returns focus to its trigger as it
closes. A focus move like that, landing between the two calls, makes
this single attempt fail even though the composer is focusable.

The product behaviour this guards is unchanged:
`ChatComposerFocusableContext` lifts the `focus()` gate in the same
commit that closes the picker, and a real click focuses the composer
regardless.

## Fix

The check now retries `focus()` plus the `activeElement` read for up to
5 s (every 250 ms) through the suite's existing `wait_until`, and fails
with the same message if the composer never takes focus. A composer that
stays gated after the settings close still fails the gate.

Only the test changes.

## Testing

- `python -m py_compile` and `ruff check --select F` on the driver:
clean.
- The suites that read this driver (CI wiring and Playwright selftests):
213 passed.
- I could not reproduce the intermittent failure locally, so the timing
explanation above is inferred from the two CI logs and the picker's
focus handling, not observed directly.
@danielhanchen
danielhanchen merged commit 291755d into unslothai:main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants