babelphish 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -21,12 +21,15 @@ The contents should look like this:
21
21
 
22
22
  api_key: THE KEY YOU GET FROM GOOGLE GOES HERE
23
23
  version: v2
24
-
24
+ # Optional value specifying the default languages to translate to:
25
+ #translate_tos: es,fr,jp,de
26
+
27
+
25
28
  You can also set the values programmatically:
26
29
 
27
30
  Babelphish.set_settings({"api_key"=>"", "version"=>"v2"})
28
31
 
29
- Google places a 100,000 character limit per day on each API key. Once you hit the limit Google will begin returning 403 errors.
32
+ Google places a 100,000 character limit per day on each API key. Once you hit the limit Google will begin returning 403 errors. (You can hit this limit really quickly.)
30
33
 
31
34
  == USAGE:
32
35
 
data/Rakefile CHANGED
@@ -29,14 +29,10 @@ begin
29
29
  gem.homepage = "http://github.com/jbasdf/babelphish"
30
30
  gem.description = "Babelphish helps you make a quick translation of your application using Google Translate."
31
31
  gem.authors = ["Justin Ball", "Michael Jenik"]
32
- gem.rubyforge_project = "babelphish"
33
32
  gem.add_dependency "ya2yaml"
34
33
  gem.add_dependency "json"
35
34
  end
36
35
  Jeweler::GemcutterTasks.new
37
- Jeweler::RubyforgeTasks.new do |rubyforge|
38
- rubyforge.doc_task = "rdoc"
39
- end
40
36
  rescue LoadError
41
37
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
42
38
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/babelphish.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{babelphish}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Ball", "Michael Jenik"]
@@ -72,7 +72,6 @@ Gem::Specification.new do |s|
72
72
  ]
73
73
  s.homepage = %q{http://github.com/jbasdf/babelphish}
74
74
  s.require_paths = ["lib"]
75
- s.rubyforge_project = %q{babelphish}
76
75
  s.rubygems_version = %q{1.6.0}
77
76
  s.summary = %q{Translate with Google like a fule => 'fool'}
78
77
  s.test_files = [
data/bin/babelphish CHANGED
@@ -12,7 +12,7 @@ OptionParser.new do |opts|
12
12
  opts.on('-l', '--language language', "Required if using 'html' option. This specifies the source language for the html or erb files") { |language| ENV['language'] = language }
13
13
  opts.on('-o', '--overwrite', "Overwrite existing translations(default 'false')") { ENV['overwrite'] = 'yes' }
14
14
  opts.on('-t', '--translate_to to', "Only translate from the source file to a specific language (ie -t es will only translate to Spanish)") { |to| ENV['translate_to'] = to }
15
- opts.on('-s', '--translate_tos tos', "Specify a list of languages to translate to. ie -s en,jp,fr. Language codes can be found on http://babelphish.rubyforge.org/.") { |tos| ENV['translate_tos'] = tos }
15
+ opts.on('-s', '--translate_tos tos', "Specify a list of languages to translate to. ie -s en,jp,fr. Language codes can be found on https://github.com/jbasdf/babelphish.") { |tos| ENV['translate_tos'] = tos }
16
16
  end.parse!
17
17
 
18
18
  if Babelphish.load_tasks
@@ -66,17 +66,23 @@ module Babelphish
66
66
  # Put the code back
67
67
  translations.each_key do |locale|
68
68
  replacements.each do |r|
69
- translations[locale].sub!(holder, r)
69
+ if translations[locale]
70
+ translations[locale].sub!(holder, r)
71
+ else
72
+ STDERR.puts "Unable to location translation for: #{locale} (From was #{from}. If they match then no translation was generated)."
73
+ end
70
74
  end
71
75
  end
72
76
 
73
77
  # Put the newlines back in
74
78
  translations.each_key do |locale|
75
79
  newline_replacements.each do |r|
76
- translations[locale].sub!(newline_holder, r)
77
- if translations[locale]['<html>']
78
- # Google translate can insert '<html>' at the beginning of the result. Remove it.
79
- translations[locale]['<html>']= '' unless begins_with_html
80
+ if translations[locale]
81
+ translations[locale].sub!(newline_holder, r)
82
+ if translations[locale]['<html>']
83
+ # Google translate can insert '<html>' at the beginning of the result. Remove it.
84
+ translations[locale]['<html>']= '' unless begins_with_html
85
+ end
80
86
  end
81
87
  end
82
88
  end
@@ -50,6 +50,14 @@ module Babelphish
50
50
  uri.query = params.map{ |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
51
51
  http = Net::HTTP.new( uri.host, uri.port )
52
52
  http.use_ssl = true if uri.scheme == "https" # enable SSL/TLS
53
+
54
+ # TODO kind of dangerous to turn off all verification. Should try to get a valid cert file at some point.
55
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
+ # cacert_file = File.join(File.expand_path("~"), "cacert.pem")
57
+ # if File.exist?(cacert_file)
58
+ # http.ca_file = cacert_file
59
+ # end
60
+
53
61
  response = nil
54
62
 
55
63
  http.start {|http| response = http.request_get(uri.request_uri) }
@@ -86,10 +94,16 @@ module Babelphish
86
94
  def multiple_translate(text, tos, from = 'en', tries = 0)
87
95
  return {} if text.strip.empty? # Google doesn't like it when you send them an empty string
88
96
 
97
+ tos.each do |to|
98
+ if !Babelphish::GoogleTranslate::LANGUAGES.include?(to)
99
+ raise Exceptions::GoogleResponseError, "#{to} is not a valid Google Translate code. Please be sure language codes are one of: #{Babelphish::GoogleTranslate::LANGUAGES.join(',')}"
100
+ end
101
+ end
102
+
89
103
  if Babelphish.api_version == 'v2'
90
104
  results = {}
91
105
  tos.each do |to|
92
- results[to] = translate( text, to, from )
106
+ results[to] = translate(text, to, from)
93
107
  end
94
108
  results
95
109
  else
@@ -102,9 +116,6 @@ module Babelphish
102
116
  query = params.map{ |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
103
117
 
104
118
  tos.each do |to|
105
- if !Babelphish::GoogleTranslate::LANGUAGES.include?(to)
106
- raise Exceptions::GoogleResponseError, "#{to} is not a valid Google Translate code. Please be sure language codes are one of: #{Babelphish::GoogleTranslate::LANGUAGES.join(',')}"
107
- end
108
119
  query << "&langpair=" + CGI.escape("#{from}|#{to}")
109
120
  end
110
121
 
@@ -138,6 +138,7 @@ module Babelphish
138
138
  end
139
139
 
140
140
  def remove_substitutions(translate_text)
141
+ return '' if !translate_text
141
142
  @replacements.each do |r|
142
143
  translate_text.sub!(SUBSTITUTION_PLACE_HOLDER, r)
143
144
  end
@@ -1,14 +1,21 @@
1
1
  desc "Translate files via Google Translate."
2
2
  task :babelphish do
3
3
  require 'babelphish/translator'
4
+
5
+ babelphish_settings_file = File.join(File.expand_path("~"), ".babelphish.yml")
6
+ if File.exist?(babelphish_settings_file)
7
+ settings = YAML.load_file(babelphish_settings_file)
8
+ translate_tos = settings['translate_tos'] if settings['translate_tos']
9
+ end
10
+
4
11
  options={}
5
12
  yml = ENV['yml']
6
13
  html = ENV['html']
7
14
  language = ENV['language']
8
15
  overwrite = ENV['overwrite'] == 'yes'
9
16
  translate_to = ENV['translate_to'] || nil
10
- translate_tos = ENV['translate_tos'] || nil
11
-
17
+ translate_tos ||= ENV['translate_tos'] || nil
18
+
12
19
  begin
13
20
  translate_tos = translate_tos.split(',') if translate_tos
14
21
  rescue
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babelphish
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Ball
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: "0"
137
137
  requirements: []
138
138
 
139
- rubyforge_project: babelphish
139
+ rubyforge_project:
140
140
  rubygems_version: 1.6.0
141
141
  signing_key:
142
142
  specification_version: 3