ggtranslate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.byebug_history +111 -0
- data/.gitignore +8 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ggtranslate.gemspec +45 -0
- data/lib/ggtranslate/result_object.rb +54 -0
- data/lib/ggtranslate/translator.rb +41 -0
- data/lib/ggtranslate/version.rb +3 -0
- data/lib/ggtranslate.rb +7 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c2153cc4eddd3350f19ab724bb6f0a0fd18dad1104cdb42d5aa5631b7e48cc19
|
4
|
+
data.tar.gz: 370840434670315fa5f922a9ba26f08c5d6a52eca6f2a02c8fc50584ae4db165
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9caa19039a5ca6757d02c081e69799152b28ff70d07cbef90d9bb33184864d81a5c6e0f786a0e6b8cf3e5315017be3b29a473687e0f874f09c2414adbb5c685
|
7
|
+
data.tar.gz: c8c1c4108aa63f7342e02daed1fc75dae4cdf4bdc9f327d942639c2e2ced5d70fdc510c5d55ec81c69f02b8ae5a73abf1e200b20ea8da38293ce3c3271292429
|
data/.byebug_history
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
c
|
2
|
+
result.translated_text
|
3
|
+
c
|
4
|
+
build_headers
|
5
|
+
RestClient.get("https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=en&q=xin%20ch%C3%A0o%20m%E1%BB%8Di%20ng%C6%B0%E1%BB%9Di", headers = build_headers)
|
6
|
+
RestClient.get(endpoint + uri.query, headers = build_headers)
|
7
|
+
endpoint + uri.query
|
8
|
+
response
|
9
|
+
c
|
10
|
+
result.class
|
11
|
+
result.translated_text
|
12
|
+
result
|
13
|
+
result.to_json
|
14
|
+
c
|
15
|
+
response = RestClient.get(endpoint + uri.query, headers = build_headers)
|
16
|
+
response = RestClient.get(endpoint + uri.query_values, headers = build_headers)
|
17
|
+
c
|
18
|
+
require 'charlock_holmes/string'
|
19
|
+
CharlockHolmes::EncodingDetector.detect("'«''ịeth World Cup 2011, Nhat Bản Ä'ang Ä'ứng tha»© 13 FIFA - 19 matches»›i Việt Nam ")
|
20
|
+
result.translated_text
|
21
|
+
c
|
22
|
+
CharlockHolmes::EncodingDetector.detect(@http_response.body)
|
23
|
+
require 'charlock_holmes'
|
24
|
+
c
|
25
|
+
CharDet.detect(@http_response.body)
|
26
|
+
require "rchardet"
|
27
|
+
CharDet.detect(@http_response.body)
|
28
|
+
c
|
29
|
+
@http_response.body.force_encoding("Windows-1252")
|
30
|
+
@http_response.body.force_encoding("UTF-8")
|
31
|
+
@http_response.body.force_encoding("Windows-1252")
|
32
|
+
@http_response.body.force_encoding("Windows-1252").encode("UTF-8")
|
33
|
+
c
|
34
|
+
@http_response.body.encode("UTF-8", "Windows-1252")
|
35
|
+
c
|
36
|
+
@http_response.body
|
37
|
+
@http_response.body.encode("UTF-8", "Windows-1252")
|
38
|
+
@http_response.body.encode("ISO-8859-1")
|
39
|
+
Encoding::toUTF8()
|
40
|
+
@http_response.body.encoding
|
41
|
+
@http_response.body
|
42
|
+
@http_response.response
|
43
|
+
@http_response
|
44
|
+
result.translated_text
|
45
|
+
"mỗi ngày tôi chọn 1 niềm vui"
|
46
|
+
"mỗi"
|
47
|
+
c
|
48
|
+
result.translated_text
|
49
|
+
result
|
50
|
+
c
|
51
|
+
@response_data = JSON.load(@http_response.body)
|
52
|
+
c
|
53
|
+
rr
|
54
|
+
rr.encoding
|
55
|
+
@http_response.methods
|
56
|
+
@http_response.uri
|
57
|
+
@http_response.url
|
58
|
+
@http_response.response
|
59
|
+
@http_response.class
|
60
|
+
@http_response
|
61
|
+
rr.encoding.force_encode("UTF-8")
|
62
|
+
rr.encoding.force_encoding("UTF-8")
|
63
|
+
rr.encoding
|
64
|
+
rr = @response_data.dig("sentences", 0, "trans")
|
65
|
+
@response_data.dig("sentences", 0, "trans")
|
66
|
+
@http_response.headers
|
67
|
+
@http_response
|
68
|
+
@response_data = JSON.load(@http_response.body)
|
69
|
+
c
|
70
|
+
@http_response.uri
|
71
|
+
@http_response.response
|
72
|
+
@http_response.read_header
|
73
|
+
@http_response.inspect
|
74
|
+
@http_response.class
|
75
|
+
@http_response.body
|
76
|
+
@http_response.class
|
77
|
+
@http_response.header
|
78
|
+
@http_response.headers
|
79
|
+
@http_response.header
|
80
|
+
@http_response.header.as_json
|
81
|
+
@http_response.header.to_json
|
82
|
+
@http_response.header.to_s
|
83
|
+
@http_response.header
|
84
|
+
@http_response.head
|
85
|
+
@http_response.body.force_encoding("UTF-8").encode("UTF-8")
|
86
|
+
@http_response.body.force_encoding("UTF-8")
|
87
|
+
c
|
88
|
+
result
|
89
|
+
c
|
90
|
+
result
|
91
|
+
c
|
92
|
+
result
|
93
|
+
c
|
94
|
+
@http_response.body.force_encoding("UTF-8")
|
95
|
+
@http_response.body.force_encoding("UTF-8").encode("UTF-8")
|
96
|
+
@http_response.body.force_encoding("ISO-8859-1").encode("UTF-8")
|
97
|
+
@http_response.body.encode("UTF-8")
|
98
|
+
@http_response.body.encoding.encode("UTF-8")
|
99
|
+
@http_response.body.encoding
|
100
|
+
c
|
101
|
+
result.translated_text.force_encoding("utf-8")
|
102
|
+
result.translated_text.encode("iso-8859-1").force_encoding("utf-8")
|
103
|
+
result.translated_text.class
|
104
|
+
result.translated_text.to_utf8
|
105
|
+
result.translated_text.encoding
|
106
|
+
result.translated_text
|
107
|
+
c
|
108
|
+
result.translated_text
|
109
|
+
result
|
110
|
+
results
|
111
|
+
c
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.0.2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +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 webmaster3t@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
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ggtranslate (0.1.0)
|
5
|
+
addressable
|
6
|
+
byebug (~> 11.1.3)
|
7
|
+
charlock_holmes
|
8
|
+
faraday
|
9
|
+
rest-client (~> 2.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.8.0)
|
15
|
+
public_suffix (>= 2.0.2, < 5.0)
|
16
|
+
byebug (11.1.3)
|
17
|
+
charlock_holmes (0.7.7)
|
18
|
+
diff-lcs (1.5.0)
|
19
|
+
domain_name (0.5.20190701)
|
20
|
+
unf (>= 0.0.5, < 1.0.0)
|
21
|
+
faraday (2.1.0)
|
22
|
+
faraday-net_http (~> 2.0)
|
23
|
+
ruby2_keywords (>= 0.0.4)
|
24
|
+
faraday-net_http (2.0.1)
|
25
|
+
http-accept (1.7.0)
|
26
|
+
http-cookie (1.0.4)
|
27
|
+
domain_name (~> 0.5)
|
28
|
+
mime-types (3.4.1)
|
29
|
+
mime-types-data (~> 3.2015)
|
30
|
+
mime-types-data (3.2022.0105)
|
31
|
+
netrc (0.11.0)
|
32
|
+
public_suffix (4.0.6)
|
33
|
+
rake (10.5.0)
|
34
|
+
rest-client (2.1.0)
|
35
|
+
http-accept (>= 1.7.0, < 2.0)
|
36
|
+
http-cookie (>= 1.0.2, < 2.0)
|
37
|
+
mime-types (>= 1.16, < 4.0)
|
38
|
+
netrc (~> 0.8)
|
39
|
+
rspec (3.10.0)
|
40
|
+
rspec-core (~> 3.10.0)
|
41
|
+
rspec-expectations (~> 3.10.0)
|
42
|
+
rspec-mocks (~> 3.10.0)
|
43
|
+
rspec-core (3.10.1)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-expectations (3.10.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-mocks (3.10.2)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.10.0)
|
51
|
+
rspec-support (3.10.3)
|
52
|
+
ruby2_keywords (0.0.5)
|
53
|
+
unf (0.1.4)
|
54
|
+
unf_ext
|
55
|
+
unf_ext (0.0.8)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 2.2.22)
|
62
|
+
byebug (~> 11.1.3)
|
63
|
+
ggtranslate!
|
64
|
+
rake (~> 10.0)
|
65
|
+
rspec (~> 3.2)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.2.24
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Thien Tran
|
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
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# 📝 Ggtranslate
|
2
|
+
|
3
|
+
**NOTE**: `Ggtranslate` is not official supported by Google and not recommended to use in production.
|
4
|
+
|
5
|
+
`Ggtranslate` is a hacked way to use google translate without hassles. You **don't need** to have `API_KEY` to start.
|
6
|
+
|
7
|
+
# 📝 Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ggtranslate'
|
13
|
+
```
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ggtranslate
|
18
|
+
|
19
|
+
# 📝 Usage
|
20
|
+
|
21
|
+
![Quick Example](https://user-images.githubusercontent.com/2922275/150781438-7613e311-2986-4ee2-98da-1f5e06cb02cf.gif)
|
22
|
+
|
23
|
+
Start with translate 1 simple sentence from English to Vietnamese
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'ggtranslate'
|
27
|
+
result = Ggtranslate::Translator.translate("hello", "en", "vi")
|
28
|
+
result.translated_text
|
29
|
+
# => "xin chào"
|
30
|
+
```
|
31
|
+
|
32
|
+
You can query in bulk to make less api calls.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
sentences = [
|
36
|
+
%q{xin chào mọi người},
|
37
|
+
%q{chào buổi sáng},
|
38
|
+
%q{chào buổi tối},
|
39
|
+
]
|
40
|
+
|
41
|
+
result = Ggtranslate::Translator.translate(sentences, "auto", "en")
|
42
|
+
result.translated_text
|
43
|
+
|
44
|
+
# => ["hello everyone", "good morning", "good evening"]
|
45
|
+
```
|
46
|
+
|
47
|
+
you can use `auto` to let Google Translate auto detect source / dest language
|
48
|
+
|
49
|
+
|
50
|
+
# 📝 License
|
51
|
+
The gem is available as open source under the terms of the MIT License.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ggtranslate"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ggtranslate.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ggtranslate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ggtranslate"
|
7
|
+
spec.version = Ggtranslate::VERSION
|
8
|
+
spec.authors = ["Thien Tran"]
|
9
|
+
spec.email = ["webmaster3t@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{ lightweight gem to bypass google translate }
|
12
|
+
spec.description = %q{ use google translate service without struggles}
|
13
|
+
spec.homepage = "https://github.com/thien0291/ggtranslate"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
20
|
+
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["source_code_uri"] = "https://github.com/thien0291/ggtranslate"
|
23
|
+
spec.metadata["changelog_uri"] = "https://github.com/thien0291/ggtranslate/changelogs.md"
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
"public gem pushes."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.2.22"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
41
|
+
spec.add_development_dependency "byebug", "~> 11.1.3"
|
42
|
+
spec.add_dependency "byebug", "~> 11.1.3"
|
43
|
+
spec.add_dependency "rest-client", "~> 2.1"
|
44
|
+
spec.add_dependency "addressable"
|
45
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Ggtranslate
|
2
|
+
class ResultObject
|
3
|
+
def initialize(http_response)
|
4
|
+
@http_response = http_response
|
5
|
+
process_http_response
|
6
|
+
end
|
7
|
+
|
8
|
+
def translated_text
|
9
|
+
result = nil
|
10
|
+
if @response_data.is_a? Hash
|
11
|
+
result = @response_data.dig("sentences", 0, "trans")
|
12
|
+
elsif @response_data.is_a? Array
|
13
|
+
result = @response_data.first
|
14
|
+
else
|
15
|
+
raise "NO RESUL FOUND"
|
16
|
+
end
|
17
|
+
|
18
|
+
result = result.split("----------")
|
19
|
+
result.count == 1 ? result.first : result
|
20
|
+
end
|
21
|
+
|
22
|
+
def source_language
|
23
|
+
@response_data.dig("src")
|
24
|
+
end
|
25
|
+
|
26
|
+
def confidence
|
27
|
+
@response_data.dig("confidence")
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_success?
|
31
|
+
@http_response.code == 200
|
32
|
+
end
|
33
|
+
|
34
|
+
def as_json
|
35
|
+
{
|
36
|
+
translated_text: translated_text,
|
37
|
+
source_language: source_language,
|
38
|
+
confidence: confidence,
|
39
|
+
response_data: @response_data,
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json
|
44
|
+
as_json.to_json
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def process_http_response
|
50
|
+
raise "TRANSLATE_FAILED" unless is_success?
|
51
|
+
@response_data = JSON.load(@http_response.body)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "json"
|
2
|
+
require "rest-client"
|
3
|
+
require "addressable"
|
4
|
+
require_relative "./result_object"
|
5
|
+
|
6
|
+
module Ggtranslate
|
7
|
+
class Translator
|
8
|
+
def self.translate(text_query, source_language = "auto", to_language = "en")
|
9
|
+
endpoint = "https://clients5.google.com/translate_a/t?"
|
10
|
+
# to translate multiple sentences
|
11
|
+
text_query = text_query.join("----------") if text_query.is_a? Array
|
12
|
+
|
13
|
+
query_params = {
|
14
|
+
client: "dict-chrome-ex", # this is a must
|
15
|
+
sl: source_language,
|
16
|
+
tl: to_language,
|
17
|
+
q: text_query,
|
18
|
+
}
|
19
|
+
|
20
|
+
uri = Addressable::URI.new
|
21
|
+
uri.query_values = query_params
|
22
|
+
response = RestClient.get(endpoint + uri.query, headers = build_headers)
|
23
|
+
ResultObject.new(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.build_headers
|
27
|
+
{
|
28
|
+
|
29
|
+
accept: "*/*",
|
30
|
+
"accept-language": "en-US,en;q=0.9,vi;q=0.8",
|
31
|
+
"sec-ch-ua": '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
|
32
|
+
"sec-ch-ua-mobile": "?0",
|
33
|
+
"sec-ch-ua-platform": '"macOS"',
|
34
|
+
"sec-fetch-dest": "empty",
|
35
|
+
"sec-fetch-mode": "cors",
|
36
|
+
"sec-fetch-site": "none",
|
37
|
+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36",
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/ggtranslate.rb
ADDED
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ggtranslate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thien Tran
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-24 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: 2.2.22
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.22
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 11.1.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 11.1.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 11.1.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 11.1.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: addressable
|
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
|
+
description: " use google translate service without struggles"
|
112
|
+
email:
|
113
|
+
- webmaster3t@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".byebug_history"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".ruby-version"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- ggtranslate.gemspec
|
130
|
+
- lib/ggtranslate.rb
|
131
|
+
- lib/ggtranslate/result_object.rb
|
132
|
+
- lib/ggtranslate/translator.rb
|
133
|
+
- lib/ggtranslate/version.rb
|
134
|
+
homepage: https://github.com/thien0291/ggtranslate
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata:
|
138
|
+
allowed_push_host: https://rubygems.org/
|
139
|
+
homepage_uri: https://github.com/thien0291/ggtranslate
|
140
|
+
source_code_uri: https://github.com/thien0291/ggtranslate
|
141
|
+
changelog_uri: https://github.com/thien0291/ggtranslate/changelogs.md
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubygems_version: 3.2.22
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: lightweight gem to bypass google translate
|
161
|
+
test_files: []
|