[MacRuby-devel] detect the language of a string

Conrad Taylor conradwt at gmail.com
Tue Dec 29 22:46:07 PST 2009


On Tue, Dec 29, 2009 at 10:20 PM, Matt Aimonetti <mattaimonetti at 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 at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20091229/28aa9d63/attachment-0001.html>


More information about the MacRuby-devel mailing list