<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 12.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NaturalLanguage",
  "identifier" : "/documentation/NaturalLanguage/NLLanguageRecognizer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Natural Language"
    ],
    "preciseIdentifier" : "c:objc(cs)NLLanguageRecognizer"
  },
  "title" : "NLLanguageRecognizer"
}
-->

# NLLanguageRecognizer

The language of a body of text.

```
class NLLanguageRecognizer
```

## Overview

An [`NLLanguageRecognizer`](/documentation/NaturalLanguage/NLLanguageRecognizer) object automatically detects the language of a piece
of text. It performs language identification by:

1. Identifying the dominant script of a piece of text. Some languages have a
   unique script (like Greek), but others share the same script (like English,
   French, and German, which all share the Latin script).
2. Identifying the language itself.

The identification obtained from an [`NLLanguageRecognizer`](/documentation/NaturalLanguage/NLLanguageRecognizer) object can be
either a single most likely language, accessed through [`dominantLanguage`](/documentation/NaturalLanguage/NLLanguageRecognizer/dominantLanguage), or
a set of language candidates with probabilities, using
[`languageHypotheses(withMaximum:)`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHypotheses(withMaximum:)). You can reset the recognizer to its initial
state, to be reused for new analysis.

Use the convenience method, [`dominantLanguage(for:)`](/documentation/NaturalLanguage/NLLanguageRecognizer/dominantLanguage(for:)), to get the most likely
language without creating an [`NLLanguageRecognizer`](/documentation/NaturalLanguage/NLLanguageRecognizer).

Language identification is most reliable for longer passages of text. For very
short inputs of only a few words, accuracy is lower, and for some text
there may be no well-defined answer at all. For example, personal names are
shared across languages and don’t belong definitively to any one of them. When
you work with short or ambiguous text, inspect the full set of
candidates with [`languageHypotheses(withMaximum:)`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHypotheses(withMaximum:)) rather than relying on a
single [`dominantLanguage`](/documentation/NaturalLanguage/NLLanguageRecognizer/dominantLanguage).  When you have prior knowledge about the input, like
a person’s preferred languages, bias the recognizer toward them with
[`languageHints`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHints-3gy00), or limit it to a known set with [`languageConstraints`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageConstraints).

> Important: Don’t use an instance of ``doc://com.apple.naturallanguage/documentation/NaturalLanguage/NLLanguageRecognizer`` from more than
> one thread simultaneously.

## Topics

### Creating a recognizer

[`init()`](/documentation/NaturalLanguage/NLLanguageRecognizer/init())

Creates a recognizer that you can customize.

### Determining the language

[`class func dominantLanguage(for: String) -> NLLanguage?`](/documentation/NaturalLanguage/NLLanguageRecognizer/dominantLanguage(for:))

Finds the most likely language of a piece of text.

[`func processString(String)`](/documentation/NaturalLanguage/NLLanguageRecognizer/processString(_:))

Analyzes the piece of text to determine its dominant language.

[`var dominantLanguage: NLLanguage?`](/documentation/NaturalLanguage/NLLanguageRecognizer/dominantLanguage)

The most likely language for the processed text.

[`func languageHypotheses(withMaximum: Int) -> [NLLanguage : Double]`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHypotheses(withMaximum:))

Generates the probabilities of possible languages for the processed text.

[`- (NSDictionary<NSString *,NSNumber *> *) languageHypothesesWithMaximum:(NSUInteger) maxHypotheses;`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHypothesesWithMaximum:)

Generates the probabilities of possible languages for the processed text.

[`func reset()`](/documentation/NaturalLanguage/NLLanguageRecognizer/reset())

Resets the recognizer to its initial state.

### Guiding the recognizer

[`@property (nonatomic, copy) NSDictionary<NSString *,NSNumber *> * languageHints;`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHints-3gy00)

A dictionary that maps languages to their probabilities in the language identification process.

[`var languageHints: [NLLanguage : Double]`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageHints-7dwgv)

A dictionary that maps languages to their probabilities in the language identification process.

[`var languageConstraints: [NLLanguage]`](/documentation/NaturalLanguage/NLLanguageRecognizer/languageConstraints)

Limits the set of possible languages that the recognizer will return.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)