Sha256: cdf4d866be320dc45a7c0d7777caf4a70effd0729c82922d087ef7acab24e16f

Contents?: true

Size: 1.09 KB

Versions: 19

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Aws::Translate
  module Plugins
    # @api private
    # The translated_documented returned by the translate_document api is modeled
    # as a blob, since it may contain binary data (eg: word doc).  However,
    # when the input document is text (eg: text/plain or text/html) the encoding
    # should be preserved.
    class TranslateDocumentEncoding < Seahorse::Client::Plugin
      class Handler < Seahorse::Client::Handler
        def call(context)
          # detect encoding
          document = context.params[:document]
          encoding =
            if document[:content_type].start_with?('text/') && document[:content].is_a?(String)
              document[:content].encoding
            end
          resp = @handler.call(context)
          if encoding
            resp.translated_document.content = resp.translated_document.content.force_encoding(encoding)
          end
          resp
        end
      end
      def add_handlers(handlers, _config)
        handlers.add(Handler, step: :initialize, operations: [:translate_document])
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
aws-sdk-translate-1.77.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.76.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.75.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.74.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.73.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.72.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.71.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.70.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.69.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.68.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.67.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.66.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.64.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.63.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.62.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.61.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.60.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.59.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb
aws-sdk-translate-1.58.0 lib/aws-sdk-translate/plugins/translate_document_encoding.rb