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
_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to