-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'i18n/tasks/translators/base_translator' | ||
|
||
module I18n::Tasks::Translators | ||
class AwsTranslator < BaseTranslator | ||
def initialize(*) | ||
begin | ||
require 'aws-sdk-translate' | ||
rescue LoadError | ||
raise ::I18n::Tasks::CommandError, "Add gem 'aws-sdk-translate' to your Gemfile to use this command" | ||
end | ||
super | ||
end | ||
|
||
protected | ||
|
||
def translate_values(list, **options) | ||
list.map do |str| | ||
aws_translate_client.translate_text( | ||
options.merge( text: str ) | ||
Check failure on line 21 in lib/i18n/tasks/translators/aws_translator.rb GitHub Actions / lint
|
||
).translated_text | ||
end | ||
end | ||
|
||
def options_for_translate_values(from:, to:, **options) | ||
options.merge( | ||
source_language_code: from, | ||
target_language_code: to, | ||
) | ||
end | ||
|
||
def options_for_html | ||
{} | ||
end | ||
|
||
def options_for_plain | ||
{} | ||
end | ||
|
||
def no_results_error_message | ||
I18n.t('i18n_tasks.aws_translate.errors.no_results') | ||
end | ||
|
||
private | ||
|
||
def aws_translate_client | ||
@aws_translate_client ||= Aws::Translate::Client.new(region: region, credentials: credentials) | ||
end | ||
|
||
def region | ||
@region ||= @i18n_tasks.translation_config[:aws_region] | ||
end | ||
|
||
def credentials | ||
@credentials ||= begin | ||
aws_access_key_id = @i18n_tasks.translation_config[:aws_access_key_id] | ||
aws_secret_access_key = @i18n_tasks.translation_config[:aws_secret_access_key] | ||
fail ::I18n::Tasks::CommandError, I18n.t('i18n_tasks.aws_translate.errors.no_api_key') if aws_access_key_id.blank? || aws_secret_access_key.blank? | ||
Check failure on line 59 in lib/i18n/tasks/translators/aws_translator.rb GitHub Actions / lint
|
||
Aws::Credentials.new(aws_access_key_id, aws_secret_access_key) | ||
end | ||
Check warning on line 61 in lib/i18n/tasks/translators/aws_translator.rb GitHub Actions / lint
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters