0
0
Fork 0

Translate CW, poll options and media descriptions (#24175)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Christian Schmidt 2023-06-01 00:10:21 +02:00 committed by GitHub
parent 44cd88adc4
commit 69057467cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 603 additions and 100 deletions

View file

@ -22,7 +22,10 @@ RSpec.describe TranslationService::DeepL do
.with(body: 'text=Hasta+la+vista&source_lang=ES&target_lang=en&tag_handling=html')
.to_return(body: '{"translations":[{"detected_source_language":"ES","text":"See you soon"}]}')
translation = service.translate('Hasta la vista', 'es', 'en')
translations = service.translate(['Hasta la vista'], 'es', 'en')
expect(translations.size).to eq 1
translation = translations.first
expect(translation.detected_source_language).to eq 'es'
expect(translation.provider).to eq 'DeepL.com'
expect(translation.text).to eq 'See you soon'
@ -31,12 +34,27 @@ RSpec.describe TranslationService::DeepL do
it 'returns translation with auto-detected source language' do
stub_request(:post, 'https://api.deepl.com/v2/translate')
.with(body: 'text=Guten+Tag&source_lang&target_lang=en&tag_handling=html')
.to_return(body: '{"translations":[{"detected_source_language":"DE","text":"Good Morning"}]}')
.to_return(body: '{"translations":[{"detected_source_language":"DE","text":"Good morning"}]}')
translation = service.translate('Guten Tag', nil, 'en')
translations = service.translate(['Guten Tag'], nil, 'en')
expect(translations.size).to eq 1
translation = translations.first
expect(translation.detected_source_language).to eq 'de'
expect(translation.provider).to eq 'DeepL.com'
expect(translation.text).to eq 'Good Morning'
expect(translation.text).to eq 'Good morning'
end
it 'returns translation of multiple texts' do
stub_request(:post, 'https://api.deepl.com/v2/translate')
.with(body: 'text=Guten+Morgen&text=Gute+Nacht&source_lang=DE&target_lang=en&tag_handling=html')
.to_return(body: '{"translations":[{"detected_source_language":"DE","text":"Good morning"},{"detected_source_language":"DE","text":"Good night"}]}')
translations = service.translate(['Guten Morgen', 'Gute Nacht'], 'de', 'en')
expect(translations.size).to eq 2
expect(translations.first.text).to eq 'Good morning'
expect(translations.last.text).to eq 'Good night'
end
end