Task architecture

Route Short Android Text to a Translation Direction

Use whole-input ML Kit Language ID only to suggest a source direction for a bounded single-language snippet; preserve user choice, undetermined outcomes, and separate translator readiness.

Review status: Fact and editorial QA complete; owner review pending · 2026-10-08 · Fact IDs: MLKIT-LANGUAGE-ID-2026-10, ARCH-01, BENCHMARK-01

Direct answer

Automatic language identification can suggest a source-language route for a short, single-language snippet, but it should not silently replace the user's source-language choice or claim to solve mixed-language text. ML Kit Language ID on Android provides identifyLanguage(), which returns a most-likely BCP-47 language tag or undetermined when its confidence threshold is not met. Its default threshold is 0.5. identifyPossibleLanguages() returns candidates and scores for the whole input under a separate default threshold of 0.01; if nothing meets that threshold, the list contains an undetermined result. These API cutoffs describe candidate filtering; they do not establish calibration evidence for an app-specific input domain, translation confidence, or evidence that the selected translation model supports that language. The short-input boundary is concrete. ML Kit documents that input longer than 200 characters is truncated to 200 for identification, but does not expose the internal window details. For reproducible routing, choose and version an app-owned snippet of at most 200 characters, test the actual SDK's counting behavior at Unicode boundaries, and pass exactly that snippet. Keep the full source, app-selected window, and submitted snippet distinct. If a longer value is sent directly and the SDK truncates internally, mark the detector window as API-limited/unknown rather than claiming to observe it. A ranking from a bounded snippet is not a decision over an entire document. Empty strings, punctuation, numbers, names, shared loanwords, and romanized text can offer little language evidence; the right behavior may be und or manual choice. Choose the method based on the UI decision. If the app needs one proposed source-language selection, identifyLanguage() provides a single tag or und. If it needs to show alternative candidates for a user to choose among, identifyPossibleLanguages() provides a list of language tags and confidence values after applying its threshold. The latter still assumes the entire string belongs to one language; ML Kit explicitly says it does not identify multiple languages in one string. Do not interpret a list as token-level spans or use its first entry to rewrite a mixed sentence. Route mixed-script or code-switched content to a separate review workflow or ask the user to select a source language. A language tag is not a translation route by itself. Keep detected BCP-47 tag, user-selected source, target language, app mapping, translator-supported directions, and ready assets as separate fields. A detector may return a language the translator does not support, supports in one direction, or has not downloaded offline. Map regional or script-qualified tags using a versioned rule, not a string-prefix fallback. Identification is asynchronous: at the actual apply point, compare request ID, input revision, and manual-override revision with current state on the same owner-controlled serialized or atomic event path. A check in the callback before it enqueues a state update can race with a newer selection. If mapping is missing or ambiguous, keep the tag as a suggestion and let the user choose. Readiness is another separate result. ML Kit offers bundled and unbundled Android libraries; in the unbundled option, the model is delivered through Google Play services and may not be ready at first launch. The guide states that requests before the model download completes produce no results. Distinguish that availability or task failure from a successful und result. Do not treat no result as und, and do not assume that a ready language-ID model provides the translation model's language pack. If identification fails, preserve the source snippet and allow manual direction selection without destroying an existing draft. Treat scores cautiously. ML Kit exposes confidence values and method-specific cutoffs, but those API cutoffs do not establish calibration evidence for the application's domain, text length, or language pairs. A score is not an accuracy guarantee. Select a threshold from the product's consequence and independently labeled examples, report its exact value, and retain und/ambiguous outcomes. Avoid showing a correctness percentage unless a separate calibration study supports it for the intended input population. Evaluate the route, not translation quality, with synthetic snippets grouped by length and shape: clear sentences, short names, numbers, punctuation-only input, romanized examples only for documented language support, and mixed-language controls that must not be auto-routed as span-aware text. Compare single-tag mode and possible-language mode, test threshold boundaries, and simulate an unbundled model that has not installed. Record the exact SDK artifact, Android API, delivery mode, submitted character count, detector output, manual override, translation-direction mapping, and asset readiness. Keep all content synthetic or consented and out of logs. This is a method for one-language source routing, not a benchmark, Cove integration claim, dictionary workflow, or mixed-language detector.

A selected phrase needs a suggested translation direction

An Android writing workflow receives a short text selection with no language metadata. The user wants to translate it offline, but the selection may be a name or a brief phrase and the translator has separate source-language and asset choices.

Decision

Ask ML Kit for a single-language suggestion, preserve und or ambiguity as a manual choice, then independently map the selected BCP-47 tag to a supported direction and ready translation resource.

Expected outcome

The interface can propose a source language without treating the detector score as translation quality or implying that a language-ID model is a translation pack.

Evidence to collect

The claim becomes reviewable only when the following evidence is attached to the same artifact and test run:

  • Pinned ML Kit API and bundled/unbundled mode
  • At-most-200-character snippet and Unicode boundary cases
  • Detector result, explicit direction mapping, and current owner revision

Task quality needs a versioned corpus and acceptance rules. Fluent sample output is not an accuracy result.

Implementation workflow

  1. Capture and version the single-language selection. Keep full source text, selection boundaries, input revision, and request ID together. Choose and version an app-owned window of at most 200 characters, test its counting behavior at Unicode boundaries against the actual SDK, and pass that exact snippet. Keep the full source, selected window, and submitted snippet distinct.
  2. Choose a detector method and threshold. Record identifyLanguage or identifyPossibleLanguages, its configured threshold, and the default if unset. Test und results; API cutoffs do not establish domain calibration and scores are not accuracy guarantees or language spans.
  3. Handle unknown, short, and mixed inputs. Offer manual source selection for und, names, numbers, very short text, or mixed-language input. Do not route individual spans from a whole-string language guess.
  4. Map the tag to a translation capability. Use an explicit versioned mapping from detected BCP-47 tag to the product source-language option. Check target direction, translator support, and required translation assets independently; preserve unknown mappings.
  5. Verify model readiness and recovery. For unbundled ML Kit, distinguish model-not-ready/no-result and task failure from a successful und response. Preserve the original snippet and manual selection if detection is unavailable.
  6. Run length and routing fixtures. Test inputs around the SDK limit with Unicode boundary cases, plus punctuation, numerals, names, romanized text, and mixed-language controls. Prefer a versioned app-owned bounded snippet. If a longer value is submitted and the SDK truncates internally, label its exact detector window unknown; record the submitted snippet and final route separately.

Keep each transition observable. A failure should identify the stage, artifact, runtime, and recovery action without logging private user content.

Acceptance criteria

  • The implementation records the exact ML Kit method and threshold; identifyLanguage default 0.5 and identifyPossibleLanguages default 0.01 are not conflated.
  • Use a versioned app-owned input window of at most 200 characters when exact detector-input provenance is needed, and test Unicode boundary counting against the actual SDK. A longer directly submitted string has an API-limited/unknown internal window. API cutoffs do not establish domain calibration and scores are not presented as accuracy guarantees.
  • The detector is used only to suggest one language for single-language input; und, mixed text, unknown tags, and unsupported directions have manual fallback. At application time, recheck request ID, input revision, and manual-override revision on the same owner-controlled serialized or atomic path; a callback-only precheck is insufficient.
  • Bundled/unbundled model readiness and asynchronous failure are distinct from a successful und result and from translator-language asset readiness.
  • No claim is made that Cove integrates ML Kit Language ID or that this method recognizes all scripts or language pairs.

Decision table

DimensionChoice or evidenceHow to interpret it
identifyLanguage()Suggest one BCP-47 language tag or und for the whole snippet.Default threshold 0.5; not a span detector or proof of translation support.
identifyPossibleLanguages()Show whole-string alternatives for explicit user choice.Default threshold 0.01; values are detector confidence scores, not calibration guarantees.
Manual source languageLet the user choose or correct source direction.Avoids forced routing when the snippet is short, ambiguous, mixed, or outside the tag map.
Translator asset stateCheck direction support and translation resource readiness after language selection.Language identification readiness does not imply a translation model or offline language pack is ready.

Failure patterns to prevent

  • Treating candidates as mixed-language spans or calibrated translation confidence
  • Confusing language-ID readiness with translation assets
  • Applying an asynchronous result after a newer manual selection

Also prevent silent fallback, unpinned artifacts, missing cancellation, and conclusions that combine unlike configurations. Store unsuccessful runs alongside successful ones.

Minimum reproducibility record

LayerRecord
DeviceManufacturer, model, chipset, RAM class, operating-system build
SoftwareApplication version and git commit
ModelFamily, variant, revision, format, file length, hash, quantization
RuntimeName, revision, requested backend, observed backend evidence
WorkloadFixture revision, input hash, prompt hash, output policy
OutcomeCompleted, failed, cancelled, fallback, and privacy-safe diagnostics

Release checklist

  • ☐ The primary query is answered without an unsupported number.
  • ☐ Every artifact and runtime is pinned.
  • ☐ The representative task and failure policy are explicit.
  • ☐ Lifecycle, cancellation, cleanup, and fallback are tested.
  • ☐ User-content and network boundaries are documented.
  • ☐ Result wording applies only to the recorded configuration.
  • ☐ The page links to raw method or evidence when results are added.

Sources and related evidence

Chinese deployment and troubleshooting content is organized in the .奇连 AI 端侧专题.

Frequently asked questions

Does ML Kit identify language spans in a mixed sentence?

No. The Android documentation says the API assumes one language for the whole input and does not identify multiple languages in a string. Mixed text needs separate span logic or user review.

Do confidence scores establish accuracy for my app?

No. The API documents confidence values and method-specific cutoffs, not calibration for your app domain or an accuracy guarantee. Evaluate against independently labeled examples before showing a correctness percentage or automating a consequential route.

What happens to text longer than 200 characters?

The API says longer input is truncated to 200 characters but does not expose the internal window details. For reproducible routing, choose a versioned app-owned snippet no longer than 200 characters and test Unicode boundary behavior with the SDK. If passing longer input directly, label the detector window unknown.

How should an asynchronous result avoid replacing a newer choice?

At the actual apply point, compare request ID, input revision, and manual-override revision on the same owner-controlled serialized or atomic path. Checking in the callback before enqueueing the state update can race with a newer selection.

Does an unbundled model returning no results mean und?

No. ML Kit says requests made before the unbundled model download completes produce no results. Keep readiness or task failure distinct from a successful und result.