go_translator 0.2.0 → 0.2.1
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/lib/go_translator/version.rb +1 -1
- data/lib/go_translator.rb +1 -1
- data/spec/go_translator_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8984f09b6adf6c28425013be0f31e13df4ed0bc1
|
4
|
+
data.tar.gz: 51dd4e9526cd41154119bf27d10b3a968bf33cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f273c03f3aa35091010c9f23d180122ac20662b4b58d5793cf0fe7642d4d4f24b3828575218948db90e479000ec857a8efd7d686b44381a03397fd4db479731
|
7
|
+
data.tar.gz: 74ba4686635c5aed8e319c2bbabb8861484b5f95bf9490fd308342cc744d6f42c0c875da857ea53a3cee357c654bbde15649d21cc03fb3cdf1f5bb7c34909cbd
|
data/lib/go_translator.rb
CHANGED
@@ -6,7 +6,7 @@ require "uri"
|
|
6
6
|
module GoTranslator
|
7
7
|
def self.translate(text, options = {})
|
8
8
|
options = default_options.merge(options)
|
9
|
-
uri = URI.parse("#{GOOGLE_TRANSLATE_URL}/single?client=z&sl=#{options[:from]}&tl=#{options[:to]}&ie=#{options[:in_encoding]}&oe=#{options[:out_encoding]}&dt=t&dt=rm&q=#{text}")
|
9
|
+
uri = URI.parse(URI.encode("#{GOOGLE_TRANSLATE_URL}/single?client=z&sl=#{options[:from]}&tl=#{options[:to]}&ie=#{options[:in_encoding]}&oe=#{options[:out_encoding]}&dt=t&dt=rm&q=#{text}"))
|
10
10
|
response = Net::HTTP.get(uri)
|
11
11
|
response.nil? || response.empty? ? '' : response.split(SPLITTER)[0].gsub(/[\[|\"]/, '')
|
12
12
|
rescue
|
data/spec/go_translator_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe GoTranslator do
|
|
9
9
|
context 'valid response from server' do
|
10
10
|
it 'translates successfully' do
|
11
11
|
expect(Net::HTTP).to receive(:get).and_return("[[[\"\xE4\xBD\xA0\xE5\xA5\xBD\xE4\xB8\x96\xE7\x95\x8C\",\"hello world\",,,0],[,,\"N\xC7\x90 h\xC7\x8Eo sh\xC3\xACji\xC3\xA8\"]],,\"en\"]")
|
12
|
-
expect(GoTranslator.translate('random')).to eq "你好世界"
|
12
|
+
expect(GoTranslator.translate('random abc')).to eq "你好世界"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|