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
On Tue, Dec 29, 2009 at 10:20 PM, Matt Aimonetti <mattaimonetti@gmail.com>wrote:
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
Matt, this is very cool and thanks for the post. -Conrad
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (2)
-
Conrad Taylor
-
Matt Aimonetti