From d86dd067ceb1dc05e67417fa1d7f1e84519b2fca Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Wed, 28 Sep 2022 06:33:56 +0900 Subject: Fix auto detect language for translate service (#19244) --- app/lib/translation_service/deepl.rb | 2 +- app/lib/translation_service/libre_translate.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/lib/translation_service/deepl.rb b/app/lib/translation_service/deepl.rb index 89ccf01e5..b75b604a8 100644 --- a/app/lib/translation_service/deepl.rb +++ b/app/lib/translation_service/deepl.rb @@ -28,7 +28,7 @@ class TranslationService::DeepL < TranslationService private def request(text, source_language, target_language) - req = Request.new(:post, endpoint_url, form: { text: text, source_lang: source_language.upcase, target_lang: target_language, tag_handling: 'html' }) + req = Request.new(:post, endpoint_url, form: { text: text, source_lang: source_language&.upcase, target_lang: target_language, tag_handling: 'html' }) req.add_headers('Authorization': "DeepL-Auth-Key #{@api_key}") req end diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb index 66acdeed7..8cf26f868 100644 --- a/app/lib/translation_service/libre_translate.rb +++ b/app/lib/translation_service/libre_translate.rb @@ -26,7 +26,8 @@ class TranslationService::LibreTranslate < TranslationService private def request(text, source_language, target_language) - req = Request.new(:post, "#{@base_url}/translate", body: Oj.dump(q: text, source: source_language, target: target_language, format: 'html', api_key: @api_key)) + body = Oj.dump(q: text, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key) + req = Request.new(:post, "#{@base_url}/translate", body: body) req.add_headers('Content-Type': 'application/json') req end -- cgit