Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Stop using translate API, start using scraping google translate

  • Loading branch information...
commit 330d253e083177b60a11132ea1a4bf0628abcb48 1 parent 911e20d
Alexander Shvets authored
View
155 .idea/workspace.xml
@@ -3,8 +3,9 @@
<component name="ChangeListManager">
<list default="true" id="27826e27-f211-4f38-bd71-88309e7ed342" name="Default" comment="Renamed language lookup methods (to have more descriptive names).&#10;(cherry picked from commit 4a5e9875dc0bda29cc5cdb1e45bfb38a0970db44)&#10;">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/CHANGES" afterPath="$PROJECT_DIR$/CHANGES" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/VERSION" afterPath="$PROJECT_DIR$/VERSION" />
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/bin/t" afterPath="$PROJECT_DIR$/bin/t" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/bin/translate" afterPath="$PROJECT_DIR$/bin/translate" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/google_translate.rb" afterPath="$PROJECT_DIR$/lib/google_translate.rb" />
</list>
<list id="8bceb49d-7e0c-4091-bde9-7ac2cd7ef145" name="Translate method now does POSTs rather than GETs (allows you to send up to 5,000 characters) to translate rather than being imposed by the GET query string limits.&#10;(cherry picked from commit c5e221ad627b74ca4afe932cf553196ca0be7c19)&#10;" comment="Translate method now does POSTs rather than GETs (allows you to send up to 5,000 characters) to translate rather than being imposed by the GET query string limits.&#10;(cherry picked from commit c5e221ad627b74ca4afe932cf553196ca0be7c19)&#10;" />
@@ -33,7 +34,7 @@
<file leaf-file-name="translate_spec.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/spec/translate_spec.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="28" column="55" selection-start="659" selection-end="659" vertical-scroll-proportion="0.0">
+ <state line="13" column="10" selection-start="212" selection-end="212" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -60,7 +61,7 @@
<file leaf-file-name="google_translate.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/google_translate.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="32" column="86" selection-start="878" selection-end="878" vertical-scroll-proportion="-1.5384616">
+ <state line="46" column="30" selection-start="1394" selection-end="1394" vertical-scroll-proportion="-16.923077">
<folding />
</state>
</provider>
@@ -75,7 +76,7 @@
</provider>
</entry>
</file>
- <file leaf-file-name="VERSION" pinned="false" current="true" current-in-tab="true">
+ <file leaf-file-name="VERSION" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/VERSION">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="5" selection-start="5" selection-end="5" vertical-scroll-proportion="0.0">
@@ -102,10 +103,10 @@
</provider>
</entry>
</file>
- <file leaf-file-name="CHANGES" pinned="false" current="false" current-in-tab="false">
+ <file leaf-file-name="CHANGES" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/CHANGES">
<provider selected="true" editor-type-id="text-editor">
- <state line="41" column="63" selection-start="594" selection-end="594" vertical-scroll-proportion="0.0">
+ <state line="45" column="71" selection-start="616" selection-end="679" vertical-scroll-proportion="0.83419687">
<folding />
</state>
</provider>
@@ -114,7 +115,7 @@
<file leaf-file-name="translate" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/bin/translate">
<provider selected="true" editor-type-id="text-editor">
- <state line="9" column="10" selection-start="193" selection-end="193" vertical-scroll-proportion="0.0">
+ <state line="24" column="169" selection-start="603" selection-end="603" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -159,12 +160,12 @@
<option value="$PROJECT_DIR$/.rvmrc" />
<option value="$PROJECT_DIR$/Rakefile" />
<option value="$PROJECT_DIR$/Gemfile" />
- <option value="$PROJECT_DIR$/CHANGES" />
<option value="$PROJECT_DIR$/README" />
- <option value="$PROJECT_DIR$/bin/translate" />
- <option value="$PROJECT_DIR$/lib/google_translate.rb" />
<option value="$PROJECT_DIR$/spec/translate_spec.rb" />
+ <option value="$PROJECT_DIR$/lib/google_translate.rb" />
+ <option value="$PROJECT_DIR$/bin/translate" />
<option value="$PROJECT_DIR$/VERSION" />
+ <option value="$PROJECT_DIR$/CHANGES" />
</list>
</option>
</component>
@@ -203,102 +204,6 @@
<option name="myItemId" value="google-translate" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="External Libraries" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode" />
- </PATH_ELEMENT>
- </PATH>
- <PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="External Libraries" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="&lt; RVM: ruby-1.8.7-p352 [google-translate] &gt;" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode" />
- </PATH_ELEMENT>
- </PATH>
- <PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="External Libraries" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="&lt; RVM: ruby-1.8.7-p352 [google-translate] &gt;" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="1.8" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- </PATH>
- <PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="External Libraries" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="&lt; RVM: ruby-1.8.7-p352 [google-translate] &gt;" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="1.8" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="net" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- </PATH>
- <PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- </PATH>
- <PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="spec" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- </PATH>
- <PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="google-translate" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="lib" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
@@ -309,10 +214,6 @@
<option name="myItemId" value="google-translate" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
- <PATH_ELEMENT>
- <option name="myItemId" value="bin" />
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
- </PATH_ELEMENT>
</PATH>
</subPane>
</pane>
@@ -778,13 +679,6 @@
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/CHANGES">
- <provider selected="true" editor-type-id="text-editor">
- <state line="41" column="63" selection-start="594" selection-end="594" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
<entry file="file://$PROJECT_DIR$/Rakefile">
<provider selected="true" editor-type-id="text-editor">
<state line="48" column="31" selection-start="1406" selection-end="1406" vertical-scroll-proportion="0.0">
@@ -804,37 +698,37 @@
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/bin/translate">
+ <entry file="file://$USER_HOME$/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/http.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="9" column="10" selection-start="193" selection-end="193" vertical-scroll-proportion="0.0">
+ <state line="1594" column="8" selection-start="47690" selection-end="47690" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$USER_HOME$/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/http.rb">
+ <entry file="file://$PROJECT_DIR$/README">
<provider selected="true" editor-type-id="text-editor">
- <state line="1594" column="8" selection-start="47690" selection-end="47690" vertical-scroll-proportion="0.0">
+ <state line="10" column="33" selection-start="265" selection-end="265" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/lib/google_translate.rb">
+ <entry file="file://$PROJECT_DIR$/spec/translate_spec.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="32" column="86" selection-start="878" selection-end="878" vertical-scroll-proportion="-1.5384616">
+ <state line="13" column="10" selection-start="212" selection-end="212" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/spec/translate_spec.rb">
+ <entry file="file://$PROJECT_DIR$/lib/google_translate.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="28" column="55" selection-start="659" selection-end="659" vertical-scroll-proportion="0.0">
+ <state line="46" column="30" selection-start="1394" selection-end="1394" vertical-scroll-proportion="-16.923077">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/README">
+ <entry file="file://$PROJECT_DIR$/bin/translate">
<provider selected="true" editor-type-id="text-editor">
- <state line="10" column="33" selection-start="265" selection-end="265" vertical-scroll-proportion="0.0">
+ <state line="24" column="169" selection-start="603" selection-end="603" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -846,6 +740,13 @@
</state>
</provider>
</entry>
+ <entry file="file://$PROJECT_DIR$/CHANGES">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="45" column="71" selection-start="616" selection-end="679" vertical-scroll-proportion="0.83419687">
+ <folding />
+ </state>
+ </provider>
+ </entry>
</component>
</project>
View
2  CHANGES
@@ -41,6 +41,6 @@
* Ruby 1.9.2 ready
-== Version 0.8.0
+== Version 0.8.4
* Stop using translate API, start using scraping google translate
View
2  VERSION
@@ -1 +1 @@
-0.8.3
+0.8.4
View
12 bin/translate
@@ -25,12 +25,16 @@ class Translate
puts list.join(', ')
end
- def display text
+ def display result
+ r1, r2 = *result
+
if RUBY_PLATFORM =~ /mswin32/
- File.open("temp.txt", "w") {|f| f.write text }
- %x[notepad temp.txt]
+ # File.open("temp.txt", "w") {|f| f.write text }
+ # %x[notepad temp.txt]
+
+ puts (r2.empty? ? r1 : r2 )
else
- puts text
+ puts r1
end
end
View
2  google-translate.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{google-translate}
- s.version = "0.8.3"
+ s.version = "0.8.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Alexander Shvets}]
View
4 lib/google_translate.rb
@@ -45,8 +45,8 @@ def translate(from, to, from_text, options={})
r1 = result[0][0][0]
r2 = result[0][0][2]
- to_text = r2.empty? ? r1 : r2
- (options[:html]) ? CGI.unescapeHTML(to_text) : to_text
+
+ [r1, r2]
end
rescue Exception => e
raise(TranslateServerIsDown)
Please sign in to comment.
Something went wrong with that request. Please try again.