[MacRuby-devel] detect the language of a string

Matt Aimonetti mattaimonetti at gmail.com
Tue Dec 29 22:20:26 PST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20091230/d2366100/attachment.html>


More information about the MacRuby-devel mailing list