forked from glebm/i18n-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translation.rb
26 lines (24 loc) · 938 Bytes
/
translation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true
require 'i18n/tasks/translators/deepl_translator.rb'
require 'i18n/tasks/translators/google_translator.rb'
require 'i18n/tasks/translators/yandex_translator.rb'
module I18n::Tasks
module Translation
# @param [I18n::Tasks::Tree::Siblings] forest to translate to the locales of its root nodes
# @param [String] from locale
# @param [:deepl, :google, :yandex] backend
# @return [I18n::Tasks::Tree::Siblings] translated forest
def translate_forest(forest, from:, backend: :google)
case backend
when :deepl
Translators::DeeplTranslator.new(self).translate_forest(forest, from)
when :google
Translators::GoogleTranslator.new(self).translate_forest(forest, from)
when :yandex
Translators::YandexTranslator.new(self).translate_forest(forest, from)
else
fail CommandError, "invalid backend: #{backend}"
end
end
end
end