google_web_translate 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -14
- data/.rspec +3 -3
- data/.rubocop.yml +9 -0
- data/.travis.yml +7 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +0 -0
- data/LICENSE.txt +21 -21
- data/README.md +53 -49
- data/Rakefile +0 -0
- data/google-web-translate.gemspec +0 -1
- data/lib/google_web_translate/api.rb +9 -20
- data/lib/google_web_translate/cli.rb +3 -1
- data/lib/google_web_translate/http_client.rb +26 -0
- data/lib/google_web_translate/result.rb +17 -11
- data/lib/google_web_translate/string_escaping.rb +0 -0
- data/lib/google_web_translate/version.rb +1 -1
- data/lib/google_web_translate.rb +1 -0
- data/lib/js/window.js +17 -17
- metadata +5 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a801716622f94a6f87ac50ea1e348d0c9d91e155
|
4
|
+
data.tar.gz: 4913fdab2c0ee17de89447b7292d13d1730ddf87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8741be3763bc8f09111bf2f9fd7fb7dc00c75b6304ce9fe4e447a29fabba1d3c3553b7019e9012269d80ea88ab7d49ef51c1744c65d1b8b7f1a76da1063cc2cf
|
7
|
+
data.tar.gz: 7c440c5f7fb0a4f21efb82b4cd0bcc6322ad3ed003713b0650f7b2864a0fd712830a97eac637aa9517a84be1e8e10960d4d2cc028f5c6bb0e8a862a578214598
|
data/.gitignore
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
9
|
-
/generated.js
|
10
|
-
/spec.out
|
11
|
-
/Gemfile.lock
|
12
|
-
|
13
|
-
# rspec failure tracking
|
14
|
-
.rspec_status
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
/generated.js
|
10
|
+
/spec.out
|
11
|
+
/Gemfile.lock
|
12
|
+
|
13
|
+
# rspec failure tracking
|
14
|
+
.rspec_status
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
3
|
-
--require spec_helper
|
1
|
+
--format documentation
|
2
|
+
--color
|
3
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at sobakasu@gmail.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sobakasu@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2018 Andrew
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Andrew
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,49 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
$
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
###
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
##
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
##
|
48
|
-
|
49
|
-
|
1
|
+
[![Documentation](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/google_web_translate)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/google_web_translate.svg)](https://badge.fury.io/rb/google_web_translate)
|
3
|
+
[![Build Status](https://travis-ci.org/sobakasu/google_web_translate.svg?branch=master)](https://travis-ci.org/sobakasu/google_web_translate)
|
4
|
+
|
5
|
+
# GoogleWebTranslate
|
6
|
+
|
7
|
+
Translates text using the Google translate web interface.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'google_web_translate'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install google_web_translate
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Command line
|
28
|
+
|
29
|
+
google_web_translate "Hello" en de
|
30
|
+
|
31
|
+
### API
|
32
|
+
|
33
|
+
api = GoogleWebTranslate::API.new
|
34
|
+
result = api.translate("Hello", "en", "de")
|
35
|
+
puts result.translation
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sobakasu/google_web_translate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the GoogleWebTranslate project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sobakasu/google_web_translate/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
File without changes
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'execjs'
|
2
2
|
require 'json'
|
3
|
-
require 'rest-client'
|
4
3
|
|
5
4
|
module GoogleWebTranslate
|
5
|
+
# interface to the google web translation api
|
6
6
|
class API
|
7
7
|
def initialize(options = {})
|
8
8
|
@dt = options[:dt] || DEFAULT_DT
|
9
9
|
@token_ttl = options[:token_ttl] || DEFAULT_TOKEN_TTL
|
10
10
|
@debug = options[:debug]
|
11
|
-
@
|
11
|
+
@http_client = options[:http_client] || HTTPClient.new(options)
|
12
12
|
end
|
13
13
|
|
14
14
|
def translate(string, from, to)
|
@@ -22,7 +22,6 @@ module GoogleWebTranslate
|
|
22
22
|
URL_TRANSLATE_1 = URL_MAIN + '/translate_a/single'.freeze
|
23
23
|
DEFAULT_DT = %w[at bd ex ld md qca rw rm ss t].freeze
|
24
24
|
DEFAULT_TOKEN_TTL = 3600
|
25
|
-
DEFAULT_USER_AGENT = "GoogleWebTranslate #{VERSION}".freeze
|
26
25
|
|
27
26
|
def fetch_translation(string, from, to)
|
28
27
|
json = fetch_url_body(translate_url(string, from, to))
|
@@ -31,7 +30,7 @@ module GoogleWebTranslate
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def fetch_url_response(url)
|
34
|
-
|
33
|
+
@http_client.get(url.to_s)
|
35
34
|
end
|
36
35
|
|
37
36
|
def fetch_url_body(url)
|
@@ -95,13 +94,13 @@ module GoogleWebTranslate
|
|
95
94
|
end
|
96
95
|
|
97
96
|
def extract_tkk(html)
|
98
|
-
raise 'TKK not found' unless html =~ /TKK
|
97
|
+
raise 'TKK not found' unless html =~ /TKK=eval\('(.*?)'\);/
|
99
98
|
tkk_code = Regexp.last_match(1)
|
100
99
|
# tkk_code = Translatomatic::StringEscaping.unescape(tkk_code)
|
101
100
|
tkk_code = StringEscaping.unescape(tkk_code)
|
102
101
|
debug("tkk code unescaped: #{tkk_code}")
|
103
|
-
|
104
|
-
tkk = context.call(nil)
|
102
|
+
tkk = ExecJS.eval(tkk_code)
|
103
|
+
# tkk = context.call(nil)
|
105
104
|
debug("evaluated tkk: #{tkk}")
|
106
105
|
tkk
|
107
106
|
end
|
@@ -110,20 +109,10 @@ module GoogleWebTranslate
|
|
110
109
|
tk = tk(string)
|
111
110
|
debug("tk: #{tk}")
|
112
111
|
query = {
|
113
|
-
sl: from,
|
114
|
-
|
115
|
-
ie: 'UTF-8',
|
116
|
-
oe: 'UTF-8',
|
117
|
-
q: string,
|
118
|
-
dt: @dt,
|
119
|
-
tk: tk,
|
112
|
+
sl: from, tl: to, ie: 'UTF-8', oe: 'UTF-8',
|
113
|
+
q: string, dt: @dt, tk: tk,
|
120
114
|
# not sure what these are for
|
121
|
-
client: 't',
|
122
|
-
hl: 'en',
|
123
|
-
otf: 1,
|
124
|
-
ssel: 4,
|
125
|
-
tsel: 6,
|
126
|
-
kc: 5
|
115
|
+
client: 't', hl: 'en', otf: 1, ssel: 4, tsel: 6, kc: 5
|
127
116
|
}
|
128
117
|
url = URI.parse(URL_TRANSLATE_1)
|
129
118
|
url.query = URI.encode_www_form(query)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'pp'
|
2
3
|
|
3
4
|
module GoogleWebTranslate
|
5
|
+
# Command line interface
|
4
6
|
class CLI < Thor
|
5
7
|
desc 'string from to', 'translate a string from one language to another'
|
6
8
|
method_option :dt, type: :array, desc: 'data types'
|
@@ -10,7 +12,7 @@ module GoogleWebTranslate
|
|
10
12
|
|
11
13
|
api = API.new(api_options)
|
12
14
|
result = api.translate(string, from, to)
|
13
|
-
|
15
|
+
pp result.to_h
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module GoogleWebTranslate
|
4
|
+
# HTTP client functionality
|
5
|
+
class HTTPClient
|
6
|
+
def self.user_agent
|
7
|
+
gem_version = "GoogleWebTranslate/#{VERSION}"
|
8
|
+
platform_version = "(#{RUBY_PLATFORM}) #{RUBY_ENGINE}/#{RUBY_VERSION}"
|
9
|
+
gem_version + ' ' + platform_version
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@user_agent = options[:user_agent] || self.class.user_agent
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(url)
|
17
|
+
uri = URI.parse(url)
|
18
|
+
request = Net::HTTP::Get.new(uri)
|
19
|
+
request['User-Agent'] = @user_agent
|
20
|
+
options = { use_ssl: uri.scheme == 'https' }
|
21
|
+
Net::HTTP.start(uri.host, uri.port, options) do |http|
|
22
|
+
http.request(request)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,24 +1,30 @@
|
|
1
1
|
module GoogleWebTranslate
|
2
|
+
# Translation results
|
2
3
|
class Result
|
3
4
|
attr_reader :raw
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# @private
|
7
|
+
DATA_INDICES = {
|
8
|
+
translation: [0, 0, 0], # dt:t
|
9
|
+
alternatives: [5, 0, 2], # dt:at
|
10
|
+
dictionary: [1], # dt: bd
|
11
|
+
synonyms: [11], # dt:ss
|
12
|
+
definitions: [12, 0], # dt:md
|
13
|
+
examples: [13, 0], # dt:ex
|
14
|
+
see_also: [14, 0], # dt:rw
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
DATA_INDICES.each_key { |key| attr_reader key }
|
9
18
|
|
10
19
|
def initialize(data)
|
11
20
|
@raw = data
|
12
21
|
@keys = []
|
13
22
|
@properties = {}
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
extract_data(:definitions, 12, 0) # dt:md
|
20
|
-
extract_data(:examples, 13, 0) # dt:ex
|
21
|
-
extract_data(:see_also, 14, 0) # dt:rw
|
24
|
+
DATA_INDICES.each do |key, indices|
|
25
|
+
indices = indices.dup
|
26
|
+
extract_data(key, *indices)
|
27
|
+
end
|
22
28
|
|
23
29
|
@alternatives = @alternatives.collect { |i| i[0] } if @alternatives
|
24
30
|
@keys.each { |key| @properties[key] = instance_variable_get("@#{key}") }
|
File without changes
|
data/lib/google_web_translate.rb
CHANGED
data/lib/js/window.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
var window = {
|
2
|
-
jstiming: {
|
3
|
-
load: {
|
4
|
-
tick: function() {}
|
5
|
-
}
|
6
|
-
}
|
7
|
-
};
|
8
|
-
var navigator = {};
|
9
|
-
var document = {};
|
10
|
-
|
11
|
-
function setWindowProperty(key, value) {
|
12
|
-
window[key] = value;
|
13
|
-
}
|
14
|
-
function generateToken(string, tkk) {
|
15
|
-
setWindowProperty("TKK", tkk);
|
16
|
-
return wq(string);
|
17
|
-
}
|
1
|
+
var window = {
|
2
|
+
jstiming: {
|
3
|
+
load: {
|
4
|
+
tick: function() {}
|
5
|
+
}
|
6
|
+
}
|
7
|
+
};
|
8
|
+
var navigator = {};
|
9
|
+
var document = {};
|
10
|
+
|
11
|
+
function setWindowProperty(key, value) {
|
12
|
+
window[key] = value;
|
13
|
+
}
|
14
|
+
function generateToken(string, tkk) {
|
15
|
+
setWindowProperty("TKK", tkk);
|
16
|
+
return wq(string);
|
17
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_web_translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rest-client
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: thor
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +118,7 @@ extra_rdoc_files: []
|
|
132
118
|
files:
|
133
119
|
- ".gitignore"
|
134
120
|
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
135
122
|
- ".travis.yml"
|
136
123
|
- CODE_OF_CONDUCT.md
|
137
124
|
- Gemfile
|
@@ -145,6 +132,7 @@ files:
|
|
145
132
|
- lib/google_web_translate.rb
|
146
133
|
- lib/google_web_translate/api.rb
|
147
134
|
- lib/google_web_translate/cli.rb
|
135
|
+
- lib/google_web_translate/http_client.rb
|
148
136
|
- lib/google_web_translate/result.rb
|
149
137
|
- lib/google_web_translate/string_escaping.rb
|
150
138
|
- lib/google_web_translate/version.rb
|
@@ -169,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
157
|
version: '0'
|
170
158
|
requirements: []
|
171
159
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.6.
|
160
|
+
rubygems_version: 2.6.11
|
173
161
|
signing_key:
|
174
162
|
specification_version: 4
|
175
163
|
summary: Text translation using the google web interface
|