get_google_translate 0.1.1 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/lib/get_google_translate.rb +11 -4
- data/lib/get_google_translate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3a68876a230f818031b9bcbf512e0cfbae00de
|
4
|
+
data.tar.gz: 081821613a4623af5686614b6e95e50435489100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f2a2b4a088ba1e686da8c9787759a1279f79c9d737a123b457ac9b0a255a565ae9c78b54b37ff98c198c3443a5e2dfd00429009318d58e9416b1794af72b6dd
|
7
|
+
data.tar.gz: 636212097f43d90686db6e4146ec4da4fb085c40664359f9caaa01abd46a8a91bd8e3252168a69081ef1b7bb9def9bd9d764912e0953a9bf746b279a8936c408
|
data/README.md
CHANGED
@@ -4,6 +4,11 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
|
|
4
4
|
|
5
5
|
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
7
|
+
## Before Installation
|
8
|
+
|
9
|
+
Due to Google API payment issue, You have to appy Public API access Key from Google. https://console.developers.google.com
|
10
|
+
After you can use this gem with key.
|
11
|
+
|
7
12
|
## Installation
|
8
13
|
|
9
14
|
Add this line to your application's Gemfile:
|
@@ -22,11 +27,11 @@ Or install it yourself as:
|
|
22
27
|
|
23
28
|
## Usage
|
24
29
|
|
25
|
-
GetGoogleTranslate::Translate.new(soure, target, text)
|
30
|
+
GetGoogleTranslate::Translate.new(key, soure, target, text)
|
26
31
|
|
27
32
|
example:
|
28
33
|
|
29
|
-
GetGoogleTranslate::Translate.new('en', 'ja', "How's the weather today in Tokyo!!")
|
34
|
+
GetGoogleTranslate::Translate.new('AIzaSyAULB3hd-LiCaCHRRvZp_-AJUjoAm2jlJE', 'en', 'ja', "How's the weather today in Tokyo!!")
|
30
35
|
|
31
36
|
どのように天気は東京で、今日です!
|
32
37
|
|
@@ -38,5 +43,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
38
43
|
|
39
44
|
## Contributing
|
40
45
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jct808/get_google_translate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
42
47
|
|
data/lib/get_google_translate.rb
CHANGED
@@ -5,9 +5,9 @@ require 'json'
|
|
5
5
|
module GetGoogleTranslate
|
6
6
|
|
7
7
|
class Translate
|
8
|
-
def self.new(source, target, text)
|
8
|
+
def self.new(key, source, target, text)
|
9
9
|
# Generate Key From Google API console
|
10
|
-
client = Google::APIClient.new(:key =>
|
10
|
+
client = Google::APIClient.new(:key => key,
|
11
11
|
:application_name => "getGoogleTranslate", :application_version => 1, :authorization => nil )
|
12
12
|
|
13
13
|
# Catch Exception if there is something wrong
|
@@ -25,8 +25,15 @@ module GetGoogleTranslate
|
|
25
25
|
# Encoding translate Context
|
26
26
|
result.body.force_encoding("UTF-8")
|
27
27
|
# Get only translateText from query result
|
28
|
-
translatedText = JSON.parse(result.body)
|
29
|
-
|
28
|
+
translatedText = JSON.parse(result.body)
|
29
|
+
|
30
|
+
# Check it does return a error from google server
|
31
|
+
if translatedText["error"] != nil
|
32
|
+
return translatedText["error"]["message"]
|
33
|
+
else
|
34
|
+
return translatedText["data"]["translations"][0]["translatedText"]
|
35
|
+
end
|
36
|
+
|
30
37
|
rescue Exception => e
|
31
38
|
# Output the error message
|
32
39
|
return "Error: #{e}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: get_google_translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Tai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|