phuwanart / libthai4r

Ruby Libthai binding for Ruby.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libthai4r

Ruby Libthai binding for Ruby.

Original project: libthai4r

Lib source code: libthai

Install

libdatrie

wget http://linux.thai.net/pub/thailinux/software/libthai/libdatrie-0.2.5.tar.gz
tar -zxvf libdatrie-0.2.5.tar.gz
cd libdatrie-0.2.5
./configure
make
sudo make install

libthai

sudo apt-get install pkg-config
wget http://linux.thai.net/pub/thailinux/software/libthai/libthai-0.1.18.tar.gz
tar zxvf libthai-0.1.18.tar.gz
cd libthai-0.1.18/
./configure
make
sudo make install

ruby-libthai

mkdir libthai4r && curl -L https://github.com/phuwanart/libthai4r/tarball/master | tar xz --strip 1 -C libthai4r
cd libthai4r
ruby extconf.rb
make
sudo make install

In command $ make if you found error like this (I found this problem when compile in Linux)

$ make
./libthai.so: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [libthai.so] Error 1

Because can't make libthai.so. The way of fix it you mush modify Makfile.

Find 2 line in Makefile

LLIB = $(TARGET).so

and

CLEANLIBS     = $(TARGET).so

Change extension name form .so to .sox. Then run $ make again. You must have libthai.sox.

Run $ sudo make install. You have message like this:

usr/bin/install -c -m 0755 libthai.sox [PATH]
installing default libthai libraries

atfer that goto [PATH] and change file name extension back to .so:

$ mv libthai.sox libthai.so

You can test with test file in test folder of source:

$ ruby test/thbrk.rb
ภาษา|ไทย|เป็น|ภาษา|ที่|ง่าย|ที่สุด|ใน|โลก

Usage

You much install iconv.

$ gem install iconv

Example:

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

utf8_to_tis620 = Iconv.new('TIS620', 'UTF-8')

a = LibThai.brk_line(utf8_to_tis620.iconv('ภาษาไทยเป็นภาษาที่ง่ายที่สุดในโลก'))

tis620_to_utf8 = Iconv.new('UTF-8', 'TIS620')

o = tis620_to_utf8.iconv(a)

puts o

Result:

ภาษา|ไทย|เป็น|ภาษา|ที่|ง่าย|ที่สุด|ใน|โลก

License

Copyright © 2013 Phuwanart Larpmark, released under the MIT license

About

Ruby Libthai binding for Ruby.


Languages

Language:C 56.2%Language:Ruby 43.8%