Skip to content

Commit

Permalink
Make 'deepl-rb' and 'easy_translate' deps optional
Browse files Browse the repository at this point in the history
Fixes #296
  • Loading branch information
glebm committed Aug 20, 2018
1 parent 291e93c commit d94aa85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions i18n-tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ TEXT

s.add_dependency 'activesupport', '>= 4.0.2'
s.add_dependency 'ast', '>= 2.1.0'
s.add_dependency 'deepl-rb', '>= 2.1.0'
s.add_dependency 'easy_translate', '>= 0.5.1'
s.add_dependency 'erubi'
s.add_dependency 'highline', '>= 2.0.0'
s.add_dependency 'i18n'
Expand All @@ -47,6 +45,8 @@ TEXT
s.add_dependency 'terminal-table', '>= 1.5.1'
s.add_development_dependency 'axlsx', '~> 2.0'
s.add_development_dependency 'bundler', '~> 1.3'
s.add_development_dependency 'deepl-rb', '>= 2.1.0'
s.add_development_dependency 'easy_translate', '>= 0.5.1'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 3.3'
s.add_development_dependency 'rubocop', '~> 0.53.0'
Expand Down
6 changes: 5 additions & 1 deletion lib/i18n/tasks/translators/deepl_translator.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# frozen_string_literal: true

require 'deepl'
require 'i18n/tasks/translators/base_translator'

module I18n::Tasks::Translators
class DeeplTranslator < BaseTranslator
def initialize(*)
begin
require 'deepl'
rescue LoadError
fail ::I18n::Tasks::CommandError, "Add gem 'deepl-rb' to your Gemfile to use this command"
end
super
configure_api_key!
end
Expand Down
10 changes: 9 additions & 1 deletion lib/i18n/tasks/translators/google_translator.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# frozen_string_literal: true

require 'easy_translate'
require 'i18n/tasks/translators/base_translator'

module I18n::Tasks::Translators
class GoogleTranslator < BaseTranslator
def initialize(*)
begin
require 'easy_translate'
rescue LoadError
fail ::I18n::Tasks::CommandError, "Add gem 'easy_translate' to your Gemfile to use this command"
end
super
end

protected

def translate_values(list, **options)
Expand Down

0 comments on commit d94aa85

Please sign in to comment.