transleet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d863ef00519e186293b7a264a7d0aa151d2f3a2b
4
+ data.tar.gz: 20cb3d61a64ced7cba354bf4e3068b43ee6d7f49
5
+ SHA512:
6
+ metadata.gz: b4e3da3cfc3d01a45abc5c7a35e9e7e04e9af6ac6eb5908203c1f68ec2bc2cff0422afa23c856af648d24b5f0c49d1c234fe7a63e924d364e4e4d7d08d2367c5
7
+ data.tar.gz: b951810b03bb33290b345c357e2c6371f345e744a2d79b43ee746a61be651fb29a79c2654695da6e877af1c7d758956be09ff51526f9ef133ca411a770e54493
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ script: bundle install; bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transleet.gemspec
4
+ gemspec
5
+
6
+ ruby '2.0.0'
7
+
8
+ gem 'httparty'
9
+ gem 'uri-handler'
10
+
11
+ #Test
12
+ gem 'rake'
13
+ gem 'pry'
14
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ajakate
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ [![Build Status](https://travis-ci.org/ajakate/transleet.svg?branch=master)](https://travis-ci.org/ajakate/transleet)
2
+
3
+ # Transleet
4
+
5
+ This gem is an API hack for google translate, allowing translation of all of the supported languages by google.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'transleet'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install transleet
20
+
21
+ ## Usage
22
+
23
+ Transleet creates an object for one way translation using google's two letter abbreviations.
24
+
25
+ require 'transleet'
26
+
27
+ translator = Transleet.new("en","es")
28
+ translator.translate("Go to hell")
29
+ # => "Vete al infierno"
30
+
31
+ It isn't perfect, but I mean, what is? It's online
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
4
+
5
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ class Transleet
2
+ VERSION = "0.1.0"
3
+ end
data/lib/transleet.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "transleet/version"
2
+ require "uri-handler"
3
+ require "httparty"
4
+
5
+ class Transleet
6
+
7
+ GOOGLE_TRANSLATE_TEMPLATE='http://translate.google.com/translate_a/t?client=t&text=[[sentence]]&hl=[[to]]&s' +
8
+ 'l=[[from]]&tl=[[to]]&ie=UTF-8&oe=UTF-8&multires=1&otf=1&pc=1&trs=1&ssel=3&tsel=6&sc=1'
9
+
10
+ def initialize(from_language, to_language)
11
+ @from_language = from_language
12
+ @to_language = to_language
13
+ end
14
+
15
+ def translate(sentence)
16
+ request_string = build_request(@from_language, @to_language, sentence)
17
+ raw_response = HTTParty.get(request_string)
18
+ parse_translation(raw_response)
19
+ end
20
+
21
+ def build_request(from, to, sentence)
22
+ GOOGLE_TRANSLATE_TEMPLATE.gsub("[[sentence]]", sentence.to_uri)
23
+ .gsub("[[to]]", to)
24
+ .gsub("[[from]]", from)
25
+ end
26
+
27
+ def parse_translation(response)
28
+ response.gsub("[","").gsub("\"","").split(',').first
29
+ end
30
+
31
+ end
@@ -0,0 +1,21 @@
1
+ require 'transleet/version'
2
+ require 'transleet'
3
+ # Requires supporting ruby files with custom matchers and macros, etc, in
4
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
5
+ # run as spec files by default. This means that files in spec/support that end
6
+ # in _spec.rb will both be required and run as specs, causing the specs to be
7
+ # run twice. It is recommended that you do not name files matching this glob to
8
+ # end with _spec.rb. You can configure this pattern with with the --pattern
9
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
10
+ # Dir[File.expand_path('spec/support/**/*.rb')].each(&method(:require)) #{ |f| require f }
11
+ RSpec.configure do |config|
12
+ # Spec Filtering
13
+ # config.filter_run focus: true
14
+ # config.run_all_when_everything_filtered = true
15
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
16
+
17
+ # Output
18
+ config.color = true
19
+ config.tty = true
20
+ config.formatter = :documentation
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transleet do
4
+
5
+ describe '#translate' do
6
+
7
+ it 'should return Hola for en -> es translation of hello' do
8
+
9
+ translator = Transleet.new('en','es')
10
+ returned_translation = translator.translate('Hello')
11
+
12
+ expected_result = 'Hola'
13
+
14
+ expect(returned_translation).to eq(expected_result)
15
+ end
16
+
17
+ it 'should return I don\'t like you for fr -> en translation of the french way to say that' do
18
+
19
+ translator = Transleet.new('fr','en')
20
+ returned_translation = translator.translate('Je ne vous aime pas bien')
21
+
22
+ expected_result = 'I do not like you'
23
+
24
+ expect(returned_translation).to eq(expected_result)
25
+ end
26
+ end
27
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
data/transleet.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'transleet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "transleet"
8
+ spec.version = Transleet::VERSION
9
+ spec.authors = ["ajakate"]
10
+ spec.email = ["ajay.jakate@gmail.com"]
11
+ spec.description = %q{An API hack of google translate}
12
+ spec.summary = %q{Translate between languages in Ruby}
13
+ spec.homepage = "https://github.com/ajakate/transleet"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transleet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ajakate
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: pry
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
+ description: An API hack of google translate
70
+ email:
71
+ - ajay.jakate@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/transleet.rb
83
+ - lib/transleet/version.rb
84
+ - spec/spec_helper.rb
85
+ - spec/transleet_integration_spec.rb
86
+ - tasks/rspec.rake
87
+ - transleet.gemspec
88
+ homepage: https://github.com/ajakate/transleet
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Translate between languages in Ruby
112
+ test_files:
113
+ - spec/spec_helper.rb
114
+ - spec/transleet_integration_spec.rb