class TextLanguage : Parcelable

Represents the result of language detection of a piece of text.

This contains a list of locales, each paired with a confidence score, sorted in decreasing order of those scores. E.g., for a given input text, the model may return [<"en", 0.85>, <"fr", 0.15>]. This sample result means the model reports that it is 85% likely that the entire text is in English and 15% likely that the entire text is in French, etc. It does not mean that 85% of the input is in English and 15% is in French.

Summary

Nested classes

Builder used to build TextLanguage objects.

A request object for detecting the language of a piece of text.

Inherited constants

From class Parcelable

Int CONTENTS_FILE_DESCRIPTOR

Descriptor bit used with describeContents(): indicates that the Parcelable object's flattened representation includes a file descriptor.

Int PARCELABLE_WRITE_RETURN_VALUE

Flag for use with writeToParcel: the object being written is a return value, that is the result of a function such as "Parcelable someFunction()", "void someFunction(out Parcelable)", or "void someFunction(inout Parcelable)". Some implementations may want to release resources at this point.

Public methods
Int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

Float

Returns the confidence score for the specified language locale.

Bundle

getExtras()

Returns a bundle containing non-structured extra information about this result.

String?

getId()

Returns the id, if one exists, for this object.

ULocale

getLocale(index: Int)

Returns the language locale at the specified index.

Int

Returns the number of possible locales for the processed text.

String

toString()

Returns a string representation of the object.

Unit

writeToParcel(dest: Parcel, flags: Int)

Flatten this object in to a Parcel.

Properties
static Parcelable.Creator<TextLanguage!>

Public methods

describeContents

fun describeContents(): Int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel,int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
Value is either 0 or

getConfidenceScore

fun getConfidenceScore(locale: ULocale): Float

Returns the confidence score for the specified language locale. The value ranges from 0 (low confidence) to 1 (high confidence). 0 indicates that the locale was not found for the processed text.

Parameters
locale ULocale: This value cannot be null.
Return
Float Value is between 0.0f and 1.0f inclusive
fun getExtras(): Bundle

Returns a bundle containing non-structured extra information about this result. What is returned in the extras is specific to the TextClassifier implementation.

NOTE: Do not modify this bundle.

Return
Bundle This value cannot be null.

getId

fun getId(): String?

Returns the id, if one exists, for this object.

Return
String? This value may be null.

getLocale

fun getLocale(index: Int): ULocale

Returns the language locale at the specified index. Locales are ordered from high confidence to low confidence.

See getLocaleHypothesisCount() for the number of locales available.

Return
ULocale This value cannot be null.
Exceptions
java.lang.IndexOutOfBoundsException if the specified index is out of range.

getLocaleHypothesisCount

fun getLocaleHypothesisCount(): Int

Returns the number of possible locales for the processed text.

Return
Int Value is 0 or greater

toString

fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.

Properties

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-26 UTC.