Somebody told me about a class for language recognition in Cocoa. Does anybody know which one it is?
This is not working:
NSSpellCh
You can use -requestCheckingOfString:…
instead. NSTextCheckingTypeOrthography
attempts to identify the language used in the string, and the completion handler receives an NSOrthography
parameter that can be used to get information about the orthography in the string, including its dominant language.
The following example outputs dominant language = de
:
NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
[spellChecker setAutomaticallyIdentifiesLanguages:YES];
NSString *spellCheckText = @"Guten Herr Mustermann. Dies ist ein deutscher Text. Bitte löschen Sie diesen nicht.";
[spellChecker requestCheckingOfString:spellCheckText
range:(NSRange){0, [spellCheckText length]}
types:NSTextCheckingTypeOrthography
options:nil
inSpellDocumentWithTag:0
completionHandler:^(NSInteger sequenceNumber, NSArray *results, NSOrthography *orthography, NSInteger wordCount) {
NSLog(@"dominant language = %@", orthography.dominantLanguage);
}];