noesya/osuny

View on GitHub
app/controllers/admin/translation_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
F
40%
class Admin::TranslationController < Admin::ApplicationController
  def translate
    @text = translation_params[:text].to_s.strip
    head :ok and return if @text.blank?
    @target = translation_params[:target]
    @response = LibreTranslate.translate(
                  @text, 
                  source: 'auto', 
                  format: 'html',
                  target: @target
                )
    render json: @response
  end

  protected

  def translation_params
    params.permit(:text, :target)
  end
end