public
Description: Translate text between two languages using www.tranexp.com
Homepage: http://tranexp.rubyforge.org
Clone URL: git://github.com/drnic/tranexp.git
Fixed unicode issues; cp1252->utf-8 conversion included
drnic (author)
Wed Apr 16 04:41:00 -0700 2008
commit  f1ea314846e408c67576393ba4f55bf30c791695
tree    84b59776c739ec90f8024593518227a3fd748dcd
parent  a56a81452d816ca8e1e18e44f519beddebef612b
...
6
7
8
9
 
10
 
 
11
12
 
13
14
15
...
6
7
8
 
9
10
11
12
13
 
14
15
16
17
0
@@ -6,10 +6,12 @@ $KCODE='u'
0
 module Tranexp; end
0
 
0
 begin
0
- require 'mechanize'
0
+ require 'rubygems'
0
   require "active_support"
0
+ $:.unshift "/Users/nicwilliams/gems/mechanize/lib"
0
+ require 'mechanize'
0
 rescue LoadError
0
- require 'rubygems'
0
+ # require 'rubygems'
0
   gem 'mechanize', '>=0.7.5'
0
   require 'mechanize'
0
 end
...
13
14
15
16
 
17
18
19
...
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
...
13
14
15
 
16
17
18
19
...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -13,7 +13,7 @@ class Tranexp::Http
0
       "Submit.y" => 9,
0
       :translation => ""
0
     })
0
- page.forms[1]['translation']
0
+ clean_up page.forms[1]['translation']
0
   end
0
 
0
   # Support calls like #from_nor_to_eng, or #from_eng_to_
0
@@ -24,5 +24,21 @@ class Tranexp::Http
0
     end
0
     super
0
   end
0
+
0
+ protected
0
+ def clean_up dirty_text
0
+ newstr = ""
0
+ dirty_text.length.times do |i|
0
+ character = dirty_text[i]
0
+ newstr += if character < 0x80
0
+ character.chr
0
+ elsif character < 0xC0
0
+ "\xC2" + character.chr
0
+ else
0
+ "\xC3" + (character - 64).chr
0
+ end
0
+ end
0
+ newstr
0
+ end
0
 end
0
 
...
2
3
4
5
 
6
7
8
9
 
10
11
12
...
15
16
17
18
 
19
20
21
22
23
24
25
 
26
27
28
...
2
3
4
 
5
6
7
8
 
9
10
11
12
...
15
16
17
 
18
19
20
21
22
 
 
 
23
24
25
26
0
@@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/test_helper.rb'
0
 
0
 class TestTranexpHttp < Test::Unit::TestCase
0
   attr_reader :translate
0
-
0
+
0
   def setup
0
     @translate = Tranexp::Http.new
0
   end
0
-
0
+
0
   def test_english_to_norwegian
0
     if_connected do
0
       assert_nothing_thrown do
0
@@ -15,14 +15,12 @@ class TestTranexpHttp < Test::Unit::TestCase
0
       end
0
     end
0
   end
0
-
0
+
0
   def test_utf8
0
     if_connected do
0
       assert_nothing_thrown do
0
         english = translate.translate("i would like to learn Norwegian", Tranexp::Http::English, Tranexp::Http::Norwegian)
0
- require 'iconv'
0
- # actual = Iconv.new('utf-16', 'utf-8').iconv(english)
0
- assert_equal("jeg ville like å høre Norsk.", english)
0
+ assert_equal("jeg ville like å høre Norsk", english)
0
       end
0
     end
0
   end

Comments

    No one has commented yet.