Skip to content
Ruby Libthai binding for Ruby 1.9.x
C Ruby
Find file
Pull request Compare This branch is 6 commits ahead, 9 commits behind neokain:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Ruby Libthai binding for Ruby 1.9.x.

Original project from: (by Vee Satayamas)

Forked project from: (by Phuwanart Larpmark)

Modification on this version are :

  • update README on adding installation method for Ubuntu users
  • change ruby package name and compiled library to 'libthai4r'
  • change test codes to use String.encode() instead of Iconv which is deprecated in Ruby 1.9

Install Prerequisite Packages

Required-Package: libdatrie

For Ubuntu users

$ sudo apt-get install libdatrie-dev libdatrie1


$ wget
$ tar zxvf libdatrie-0.2.5.tar.gz
$ cd libdatrie-0.2.5
$ ./configure
$ make
$ sudo make install

Required-Package: libthai

For Ubuntu users

$ sudo apt-get install libthai-dev libthai0


$ wget
$ tar zxvf libthai-0.1.18.tar.gz 
$ cd libthai-0.1.18/
$ ./configure 
$ make
$ sudo make install

Install LibThai4R

$ mkdir libthai4r && curl -L | tar xz --strip 1 -C libthai4r
$ cd libthai4r  #( If use rvm, edit libthai4r/.rvmrc to your default ruby version, then re-enter the directory )
$ sudo ruby extconf.rb #( if use rvm ⇒ $ rvmsudo ruby extconf.rb )
$ make
$ sudo make install

You can test with test file in test folder.

$ ruby test/thbrk.rb


#!/usr/bin/env ruby
# encoding: utf-8
require 'libthai4r'

# libthai requires input to be tis620/windows874 (one-byte char)
input = 'ภาษาไทยเป็นภาษาที่ง่ายที่สุดในโลก'
input_windows874 = input.encode('Windows-874', :undef => :replace,:replace => '')

# break words in the line
output_windows874 = LibThai::brk_line(input_windows874)

# encode back to UTF-8
output = output_windows874.encode('UTF-8')

print output




Original Work: Copyright © 2011 Phuwanart Larpmark, released under the MIT license

Modified Work: Copyright © 2012 Phitchayaphong Tantikul, released under the MIT license

Something went wrong with that request. Please try again.