babelphish 0.1.3 → 0.1.4

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.
data/bin/babelphish CHANGED
@@ -7,8 +7,9 @@ task = :babelphish
7
7
 
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: babelphish [options]"
10
- opts.on('-y', '--yaml yml', "Required. Path to the yml file to be translated") {|yml| ENV['yml'] = yml }
10
+ opts.on('-y', '--yaml yml', "Required. Path to the yml file to be translated") { |yml| ENV['yml'] = yml }
11
11
  opts.on('-o', '--overwrite', "Overwrite existing translations(default 'false')") { ENV['overwrite'] = 'yes' }
12
+ 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 }
12
13
  end.parse!
13
14
 
14
15
  if Babelphish.load_tasks
@@ -7,15 +7,24 @@ module Babelphish
7
7
  module Translator
8
8
  class << self
9
9
 
10
- def translate_yaml(yml, overwrite = false)
10
+ def translate_yaml(yml, overwrite = false, translate_to = nil)
11
+ @yml = yml
11
12
  $KCODE = 'UTF8'
12
13
  language = File.basename(yml, ".yml")
13
14
  if !Babelphish::GoogleTranslate::LANGUAGES.include?(language)
14
15
  STDERR.puts "#{language} is not one of the available languages. Please choose a standard localized yml file. i.e. en.yml."
15
16
  return
16
17
  end
17
- Babelphish::GoogleTranslate::LANGUAGES.each do |to|
18
- translate_and_write_yml(yml, to, language, overwrite)
18
+ if translate_to
19
+ puts "Translating #{language} to #{translate_to}"
20
+ translate_and_write_yml(yml, translate_to, language, overwrite)
21
+ puts "Finished translating #{language} to #{translate_to}"
22
+ else
23
+ Babelphish::GoogleTranslate::LANGUAGES.each do |to|
24
+ puts "Translating #{language} to #{to}"
25
+ translate_and_write_yml(yml, to, language, overwrite)
26
+ puts "Finished translating #{language} to #{to}"
27
+ end
19
28
  end
20
29
  end
21
30
 
@@ -81,10 +90,7 @@ module Babelphish
81
90
  if json['responseStatus'] == 200
82
91
  json['responseData']['translatedText']
83
92
  else
84
- puts response
85
- puts to
86
- puts from
87
- raise StandardError, response['responseDetails']
93
+ puts "A problem occured while translating from #{from} to #{to}. To retry only this translation try: babelphish -o -y #{@yml} -t #{to} to babelphish. Response: #{response}"
88
94
  end
89
95
  end
90
96
 
data/lib/babelphish.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Babelphish
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
 
7
7
  def self.load_tasks
8
8
  if File.exists?('Rakefile')
@@ -4,9 +4,10 @@ task :babelphish do
4
4
  options={}
5
5
  yml = ENV['yml']
6
6
  overwrite = ENV['overwrite'] == 'yes'
7
+ translate_to = ENV['translate_to'] || nil
7
8
 
8
9
  if yml
9
- Babelphish::Translator.translate_yaml(yml, overwrite)
10
+ Babelphish::Translator.translate_yaml(yml, overwrite, translate_to)
10
11
  else
11
12
  STDERR.puts "Please specify the directory where your files live. i.e. babelphish -d ./my/locales"
12
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babelphish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball