You can use the zlib library for this as does deplate:

from: http://deplate.sourceforge.net/Modules.html#hd008001001
> The algorithm of this plugin is based on D Benedetto & E Caglioti
> & V Loreto ?Language Trees and Zipping?[1]. It?s a direct port of
> Dirk Holtwick?s ?Guess language of text using ZIP?[2].

[1] http://xxx.uni-augsburg.de/format/cond-mat/0108530
[2] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/355807

Ruby code:
http://deplate.cvs.sourceforge.net/deplate/deplate/lib/deplate/guesslanguage.rb?view=markup

Works quite well for me.

Thomas.