Skip to content

Mixed Language

Rumen Damyanov edited this page Dec 4, 2026 · 1 revision

Mixed languages

Text is split on sentence boundaries into chunks of about 280 letters. Each chunk is compared with the languages that use its writing system, using ranked character trigrams. The chunk's letters go to the closest language. When the top two distances are within 5% of each other, the letters are shared.

Those letter counts become shares:

  • One language, when the top share is at least 55% and the lead is at least 15 points.
  • A distribution, when either test fails.

A short quotation inside a long document stays a small share. The sample used in the tests is an English paragraph plus one French sentence: decisive English, displayed as 75% English and 25% French. An English paragraph followed by a French paragraph of similar length is displayed as 52 and 48 and is inconclusive.

Percent rounding uses the largest-remainder method. The decisive check still sees the basis-point values, so a displayed gap of 4 points can be inside the 15-point margin.

Closely related languages, such as Bosnian and Croatian or Danish and Norwegian Bokmål, can share a document that is actually one of them. The top language is still correct on held-out Declaration text for all 52 profiles. Raise withMinMargin when that kind of pair should stay a distribution. withOnlyLanguages removes the neighbors you do not want considered.

The 52 profiles cover Latin, Cyrillic, Greek, Arabic, Hebrew, Han, Japanese, Hangul, Devanagari, Bengali, Thai, Georgian, and Armenian. languages() returns code, name, and script for each one.

See Configuration to change the thresholds.

Clone this wiki locally