Skip to content

Commit

Permalink
[Feature] Allow the automatic detection of the source language #60
Browse files Browse the repository at this point in the history
Issue: #60

This commit adds :DETECT as a supported language. This allows the DeepL API
to detect the source language automatically.
  • Loading branch information
nwittstruck committed Aug 20, 2024
1 parent ee26d94 commit 9969177
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
6 changes: 0 additions & 6 deletions config/config.exs

This file was deleted.

43 changes: 0 additions & 43 deletions test/deepl_ex_test.exs
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

0 comments on commit 9969177

Please sign in to comment.