google-transliterate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec5972da289915636cdb2d2526ae02805f12205a
4
+ data.tar.gz: ff6852dcc110f397ab8d9f0ade3cb19b9e725634
5
+ SHA512:
6
+ metadata.gz: 2745192c02eee8cd45d9521ca6568476f1edfcee0e78f28b9e0923677d292023b8afc709c6bb0b5a51ce61507c82236e154545b3a72c45aa8c7af9d42f212d23
7
+ data.tar.gz: 8b093161d9b3bbb9cf085025c69d46974678706eff715d827498925917cf9139a29a98d16c1c094cc95bab033e5a0114618285b5a5beacaf9ece37a51ce5149d
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google-transliterate.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Wilkie
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Google::Transliterate
2
+
3
+ Uses Google Translate to transliterate from a script into phonetic English. For example, "เดวิดไลกสเบียร์" becomes "Dewid lịks̄ beīyr̒"" and "ដេវិឌលៃកសបៀរ" becomes "de vi d lei k sa bier".
4
+
5
+ Note: This gem does not use that Google Translate API because I want to support Alpha languages such as Khmer. Use at your own risk!
6
+
7
+ [![Build Status](https://travis-ci.org/dwilkie/google-transliterate.png)](https://travis-ci.org/dwilkie/google-transliterate) [![Dependency Status](https://gemnasium.com/dwilkie/google-transliterate.png)](https://gemnasium.com/dwilkie/google-transliterate) [![Code Climate](https://codeclimate.com/github/dwilkie/google-transliterate.png)](https://codeclimate.com/github/dwilkie/google-transliterate)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'google-transliterate'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install google-transliterate
22
+
23
+ ## Usage
24
+
25
+ require 'google/transliterate'
26
+
27
+ transliterator = Google::Transliterate::Transliterator.new
28
+ transliterator.transliterate!("kh", "ដេវិឌលៃកសបៀរ")
29
+ => "de vi d lei k sa bier"
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'google/transliterate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "google-transliterate"
8
+ spec.version = Google::Transliterate::VERSION
9
+ spec.authors = ["David Wilkie"]
10
+ spec.email = ["dwilkie@gmail.com"]
11
+ spec.description = "Transliterates from a script into English phonetical"
12
+ spec.summary = "Transliterates from a script into English phonetical"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "fakeweb"
28
+ end
@@ -0,0 +1 @@
1
+ require "google/transliterate/transliterator"
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module Google
3
+ module Transliterate
4
+ class Transliterator
5
+ require 'httparty'
6
+
7
+ include HTTParty
8
+
9
+ class Parser::Simple < HTTParty::Parser
10
+ require 'csv'
11
+
12
+ def parse
13
+ CSV.parse(body.gsub(/(?:\[|\])/, ""))[0][3]
14
+ end
15
+ end
16
+
17
+ parser Parser::Simple
18
+
19
+ GOOGLE_TRANSLATE_URL = "http://translate.google.com/translate_a/t"
20
+ DEFAULT_USER_AGENT = "Mozilla/5.0"
21
+
22
+ def transliterate!(source_script, text)
23
+ self.class.get(
24
+ GOOGLE_TRANSLATE_URL,
25
+ :query => {
26
+ :client => "t",
27
+ :sl => source_script,
28
+ :ie => "UTF-8",
29
+ :oe => "UTF-8",
30
+ :q => text
31
+ },
32
+ :headers => {"User-Agent" => DEFAULT_USER_AGENT}
33
+ ).parsed_response.force_encoding("UTF-8")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Google
2
+ module Transliterate
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://translate.google.com/translate_a/t?client=t&sl=kh&ie=UTF-8&oe=UTF-8&q=%E1%9E%8A%E1%9F%81%E1%9E%9C%E1%9E%B7%E1%9E%8C%E1%9E%9B%E1%9F%83%E1%9E%80%E1%9E%9F%E1%9E%94%E1%9F%80%E1%9E%9A
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ user-agent:
11
+ - Mozilla/5.0
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ pragma:
18
+ - no-cache
19
+ date:
20
+ - Thu, 11 Jul 2013 17:22:18 GMT
21
+ expires:
22
+ - Thu, 11 Jul 2013 17:22:18 GMT
23
+ cache-control:
24
+ - private, max-age=600
25
+ content-type:
26
+ - text/javascript; charset=UTF-8
27
+ content-language:
28
+ - en
29
+ set-cookie:
30
+ - PREF=ID=fea4ba32c6c5ec37:TM=1373563338:LM=1373563338:S=xPEsSNBt1KMI8n2B; expires=Sat,
31
+ 11-Jul-2015 17:22:18 GMT; path=/; domain=.google.com
32
+ x-content-type-options:
33
+ - nosniff
34
+ content-disposition:
35
+ - attachment
36
+ server:
37
+ - HTTP server (unknown)
38
+ x-xss-protection:
39
+ - 1; mode=block
40
+ connection:
41
+ - close
42
+ body:
43
+ encoding: ASCII-8BIT
44
+ string: !binary |-
45
+ W1tbIkRldmVsb3BtZW50IGFkanVzdGVkIHRlcm1zIiwi4Z6K4Z+B4Z6c4Z63
46
+ 4Z6M4Z6b4Z+D4Z6A4Z6f4Z6U4Z+A4Z6aIiwiIiwiZGUgdmkgZCBsZWkgayBz
47
+ YSBiaWVyIl1dLCwia20iLCxbWyJEZXZlbG9wbWVudCIsWzRdLDAsMCwxMDAw
48
+ LDAsMSwwXSxbImFkanVzdGVkIixbNV0sMSwwLDEwMDAsMSwyLDBdLFsidGVy
49
+ bXMiLFs2XSwxLDAsMTAwMCwyLDMsMF1dLFtbIuGejCIsNCxbWyJEZXZlbG9w
50
+ bWVudCIsMTAwMCwwLDBdLFsicHJvZ3Jlc3MiLDAsMCwwXSxbIndvcmsiLDAs
51
+ MCwwXSxbIm5hdGlvbmFsIGxldmVsIiwwLDAsMF1dLFtbNCw1XV0sIuGeiuGf
52
+ geGenOGet+GejOGem+Gfg+GegOGen+GelOGfgOGemiJdLFsi4Z6b4Z+DIiw1
53
+ LFtbImFkanVzdGVkIiwxMDAwLDEsMF0sWyJBZGp1c3QiLDAsMSwwXSxbIkFk
54
+ anVzdG1lbnQiLDAsMSwwXSxbIkFkanVzdCB0aGUiLDAsMSwwXSxbInJlamVj
55
+ dGVkIiwwLDEsMF1dLFtbNSw3XV0sIiJdLFsi4Z6U4Z+A4Z6aIiw2LFtbInRl
56
+ cm1zIiwxMDAwLDEsMF0sWyJCZWVyIiwwLDEsMF0sWyJzYWxhcnkiLDAsMSww
57
+ XSxbIkVkdWNhdGlvbiIsMCwxLDBdXSxbWzksMTJdXSwiIl1dLCwsW1sia20i
58
+ XV0sMV0=
59
+ http_version: '1.1'
60
+ recorded_at: Thu, 11 Jul 2013 17:22:18 GMT
61
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://translate.google.com/translate_a/t?client=t&sl=th&ie=UTF-8&oe=UTF-8&q=%E0%B9%80%E0%B8%94%E0%B8%A7%E0%B8%B4%E0%B8%94%E0%B9%84%E0%B8%A5%E0%B8%81%E0%B8%AA%E0%B9%80%E0%B8%9A%E0%B8%B5%E0%B8%A2%E0%B8%A3%E0%B9%8C
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ user-agent:
11
+ - Mozilla/5.0
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ pragma:
18
+ - no-cache
19
+ date:
20
+ - Thu, 11 Jul 2013 17:09:30 GMT
21
+ expires:
22
+ - Thu, 11 Jul 2013 17:09:30 GMT
23
+ cache-control:
24
+ - private, max-age=600
25
+ content-type:
26
+ - text/javascript; charset=UTF-8
27
+ content-language:
28
+ - en
29
+ set-cookie:
30
+ - PREF=ID=e40f8e14f23c9b43:TM=1373562569:LM=1373562570:S=eKHsgyxbQxRW6ay_; expires=Sat,
31
+ 11-Jul-2015 17:09:30 GMT; path=/; domain=.google.com
32
+ x-content-type-options:
33
+ - nosniff
34
+ content-disposition:
35
+ - attachment
36
+ server:
37
+ - HTTP server (unknown)
38
+ x-xss-protection:
39
+ - 1; mode=block
40
+ connection:
41
+ - close
42
+ body:
43
+ encoding: ASCII-8BIT
44
+ string: !binary |-
45
+ W1tbIkRhdmlkIEEuIExpZ2h0IEJlZXIgLiIsIuC5gOC4lOC4p+C4tOC4lOC5
46
+ hOC4peC4geC4quC5gOC4muC4teC4ouC4o+C5jCIsIiIsIkRld2lkIGzhu4tr
47
+ c8yEIGJlxKt5csySIl1dLCwidGgiLCxbWyJEYXZpZCIsWzRdLDEsMCw5OTAs
48
+ MCwxLDBdLFsiQS4iLFs1XSwxLDAsNTk1LDEsMiwwXSxbIkxpZ2h0IixbNl0s
49
+ MSwwLDU5MiwyLDMsMF0sWyJCZWVyIixbN10sMSwwLDU5MiwzLDQsMF0sWyIu
50
+ IixbOF0sMCwwLDU5Miw0LDUsMF1dLFtbIuC5gOC4lOC4p+C4tOC4lCIsNCxb
51
+ WyJEYXZpZCIsOTkwLDEsMF0sWyJCeSBEYXZpZCIsMCwxLDBdXSxbWzAsNV1d
52
+ LCLguYDguJTguKfguLTguJTguYTguKXguIHguKrguYDguJrguLXguKLguKPg
53
+ uYwiXSxbIuC4gSIsNSxbWyJBLiIsNTk1LDEsMF0sWyJXIiwxMiwxLDBdLFsi
54
+ TmV3cyIsNiwxLDBdLFsiUmVwdWJsaWMiLDAsMSwwXV0sW1s3LDhdXSwiIl0s
55
+ WyLguYTguKUiLDYsW1siTGlnaHQiLDU5MiwxLDBdLFsiTGl2ZSIsMTUsMSww
56
+ XSxbIkhlYWQiLDIsMSwwXSxbImxpbmUiLDAsMSwwXSxbIkxlaWRlbiIsMCwx
57
+ LDBdXSxbWzUsN11dLCIiXSxbIuC4qiDguYDguJrguLXguKLguKPguYwiLDcs
58
+ W1siQmVlciIsNTkyLDEsMF1dLFtbOCwxNV1dLCIiXSxbIi4iLDgsW1siLiIs
59
+ NTkyLDAsMF1dLFtbOSwxNV1dLCIiXV0sLCxbWyJ0aCJdXSw5N10=
60
+ http_version: '1.1'
61
+ recorded_at: Thu, 11 Jul 2013 17:09:30 GMT
62
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'google/transliterate'
5
+
6
+ module Google
7
+ module Transliterate
8
+ describe Transliterator do
9
+ describe "#transliterate!(source_script, text)" do
10
+ def expect_transliterate(options = {}, &block)
11
+ VCR.use_cassette(options[:cassette]) do
12
+ yield
13
+ end
14
+ end
15
+
16
+ it "should transliterate Thai" do
17
+ expect_transliterate(:cassette => :david_likes_beer_th) do
18
+ subject.transliterate!(
19
+ "th", "เดวิดไลกสเบียร์"
20
+ ).should == "Dewid lịks̄ beīyr̒"
21
+ end
22
+ end
23
+
24
+ it "should transliterate Khmer" do
25
+ expect_transliterate(:cassette => :david_likes_beer_kh) do
26
+ subject.transliterate!(
27
+ "kh", "ដេវិឌលៃកសបៀរ"
28
+ ).should == "de vi d lei k sa bier"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'fake_web'
2
+ FakeWeb.allow_net_connect = false
@@ -0,0 +1,6 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "fixtures/vcr_cassettes"))
5
+ c.hook_into :fakeweb
6
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-transliterate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Wilkie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fakeweb
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Transliterates from a script into English phonetical
98
+ email:
99
+ - dwilkie@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - google-transliterate.gemspec
111
+ - lib/google/transliterate.rb
112
+ - lib/google/transliterate/transliterator.rb
113
+ - lib/google/transliterate/version.rb
114
+ - spec/fixtures/vcr_cassettes/david_likes_beer_kh.yml
115
+ - spec/fixtures/vcr_cassettes/david_likes_beer_th.yml
116
+ - spec/google/transliterate/transliterator_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/fake_web.rb
119
+ - spec/support/vcr.rb
120
+ homepage: ''
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.0.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Transliterates from a script into English phonetical
144
+ test_files:
145
+ - spec/fixtures/vcr_cassettes/david_likes_beer_kh.yml
146
+ - spec/fixtures/vcr_cassettes/david_likes_beer_th.yml
147
+ - spec/google/transliterate/transliterator_spec.rb
148
+ - spec/spec_helper.rb
149
+ - spec/support/fake_web.rb
150
+ - spec/support/vcr.rb