Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for translations of long text

  • Loading branch information...
commit ba1fb8bd05ad73700e8c2aff571ab3034754c311 1 parent 716509d
Noel Rappin authored
Showing with 4 additions and 6 deletions.
  1. +0 −1  babelphish.gemspec
  2. +4 −5 lib/babelphish/translator.rb
View
1  babelphish.gemspec
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Justin Ball", "Michael Jenik"]
s.date = %q{2011-03-15}
- s.default_executable = %q{babelphish}
s.description = %q{Babelphish helps you make a quick translation of your application using Google Translate.}
s.email = %q{justinball@gmail.com}
s.executables = ["babelphish"]
View
9 lib/babelphish/translator.rb
@@ -10,15 +10,14 @@ def translate(text, to, from = 'en', tries = 0)
if text.is_a? Symbol
return text
end
-
if text.length > 1000 #actually the USI length limit is 2000
text_now = ""
text_rem = ""
- text.split(".") do |text_chunk|
- if text_now.length < 1000
- text_now += (text_now.length == 0 ? "" : ".") + text_chunk
+ text.split(".").each do |text_chunk|
+ if text_now.length + text_chunk.length < 1000
+ text_now += (text_chunk + ".")
else
- text_rem += (text_now.length == 0 ? "" : ".") + text_chunk
+ text_rem += (text_chunk + ".")
end
end
return translate(text_now, to, from) + "." + translate(text_rem, to, from)
Please sign in to comment.
Something went wrong with that request. Please try again.