-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Allow the automatic detection of the source language #60
Issue: #60 This commit adds :DETECT as a supported language. This allows the DeepL API to detect the source language automatically.
- Loading branch information
1 parent
ee26d94
commit 9969177
Showing
2 changed files
with
0 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,46 +1,3 @@ | ||
defmodule DeeplExTest do | ||
use ExUnit.Case | ||
|
||
import Tesla.Mock | ||
|
||
describe "translate/4" do | ||
setup do | ||
text = "Hoje vou comer." | ||
translated_text = "Today I'm going to eat." | ||
{:ok, text: text, translated_text: translated_text} | ||
end | ||
|
||
test "translates text with source language present", %{ | ||
text: text, | ||
translated_text: translated_text | ||
} do | ||
params = %{text: [text], source_lang: "PT", target_lang: "EN"} | ||
|
||
mock_translate_request(params, translated_text) | ||
|
||
assert {:ok, translation} = DeeplEx.translate(text, :PT, :EN) | ||
assert translation == translated_text | ||
end | ||
|
||
test "translates text with source language set to :DETECT", %{ | ||
text: text, | ||
translated_text: translated_text | ||
} do | ||
params = %{text: [text], target_lang: "EN"} | ||
|
||
mock_translate_request(params, translated_text) | ||
|
||
assert {:ok, translation} = DeeplEx.translate(text, :DETECT, :EN) | ||
assert translation == translated_text | ||
end | ||
end | ||
|
||
def mock_translate_request(params, translated_text) do | ||
body = Jason.encode!(params) | ||
|
||
mock(fn | ||
%{method: :post, url: "https://api.deepl.com/v2/translate", body: ^body} -> | ||
json(%{"translations" => [%{"text" => translated_text}]}) | ||
end) | ||
end | ||
end |