30 Dec
2009
30 Dec
'09
6:20 a.m.
Curious of seeing if I could use a Cocoa framework to detect the language of a string, I ended up finding a surprisingly clean and easy solution. I decided to post my findings online since I couldn't find anything when I googled the topic: http://merbist.com/2009/12/29/fun-with-macruby/ In less than 10LOC, here is how to implement this feature: framework 'Foundation' class String def language CFStringTokenizerCopyBestStringLanguage(self, CFRangeMake(0, self.size)) end end "bonne année!".language # => "fr" - Matt