Andreas Prang Andreas Prang - 4 months ago 26
Objective-C Question

Detect Language of NSString

somebody told me about a Class for language recognition in Cocoa.
Does anybody know which one it is?

This is not working:

NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
[spellChecker setAutomaticallyIdentifiesLanguages:YES];
NSString *spellCheckText = @"Guten Tag Herr Mustermann. Dies ist ein deutscher Text. Bitte löschen Sie diesen nicht.";
[spellChecker checkSpellingOfString:spellCheckText startingAt:0];
NSLog(@"%@", [spellChecker language]);

The result is 'en' but should be 'de'.



Thats the result:

- (NSString *)languageForString:(NSString *) text{

     if (text.length < 100) {
         return (NSString *) CFStringTokenizerCopyBestStringLanguage((CFStringRef)text, CFRangeMake(0, text.length));
     } else {
         return (NSString *)CFStringTokenizerCopyBestStringLanguage((CFStringRef)text, CFRangeMake(0, 100));