mirror of
https://github.com/mirego/accent.git
synced 2024-08-16 22:40:36 +03:00
Fix deepl detect source language
This commit is contained in:
parent
e141a3ba55
commit
09338293a6
@ -46,7 +46,7 @@ defmodule Accent.MachineTranslations.Provider.Deepl do
|
||||
def translate(provider, contents, source, target) do
|
||||
with {:ok, {source, target}} <-
|
||||
Accent.MachineTranslations.map_source_and_target(source, target, @supported_languages),
|
||||
params = %{text: contents, source_lang: String.upcase(source), target_lang: String.upcase(target)},
|
||||
params = %{text: contents, source_lang: source && String.upcase(source), target_lang: String.upcase(target)},
|
||||
{:ok, %{body: %{"translations" => translations}}} <-
|
||||
Tesla.post(client(provider.config["key"]), "translate", params) do
|
||||
{:ok, Enum.map(translations, &%TranslatedText{text: &1["text"]})}
|
||||
|
@ -73,5 +73,52 @@ defmodule AccentTest.MachineTranslations do
|
||||
{:error, error} = MachineTranslations.translate(entries, source_language, target_language, config)
|
||||
assert error === "Something"
|
||||
end
|
||||
|
||||
test "deepl" do
|
||||
mock_global(fn
|
||||
%{body: body, url: "https://api-free.deepl.com/v2/translate"} ->
|
||||
assert Jason.decode!(body) === %{"source_lang" => "FR", "target_lang" => "EN", "text" => ["Test"]}
|
||||
|
||||
%Tesla.Env{status: 200, body: %{"translations" => [%{"text" => "Translated"}]}}
|
||||
end)
|
||||
|
||||
entries = [%Langue.Entry{value: "Test", value_type: "string", key: "."}]
|
||||
source_language = "fr"
|
||||
target_language = "en"
|
||||
provider_config = %{"key" => "test"}
|
||||
config = %{"provider" => "deepl", "config" => provider_config}
|
||||
|
||||
[entry] = MachineTranslations.translate(entries, source_language, target_language, config)
|
||||
assert entry.value === "Translated"
|
||||
end
|
||||
|
||||
test "deepl error" do
|
||||
mock_global(fn %{url: "https://api-free.deepl.com/v2/translate"} ->
|
||||
%Tesla.Env{status: 400, body: "Something"}
|
||||
end)
|
||||
|
||||
entries = [%Langue.Entry{value: "Test", value_type: "string", key: "."}]
|
||||
source_language = "fr"
|
||||
target_language = "en"
|
||||
provider_config = %{"key" => "test"}
|
||||
config = %{"provider" => "deepl", "config" => provider_config}
|
||||
|
||||
{:error, error} = MachineTranslations.translate(entries, source_language, target_language, config)
|
||||
assert error === "Something"
|
||||
end
|
||||
|
||||
test "deepl detect source" do
|
||||
mock_global(fn %{url: "https://api-free.deepl.com/v2/translate"} ->
|
||||
%Tesla.Env{status: 400, body: "Something"}
|
||||
end)
|
||||
|
||||
entries = [%Langue.Entry{value: "Test", value_type: "string", key: "."}]
|
||||
target_language = "en"
|
||||
provider_config = %{"key" => "test"}
|
||||
config = %{"provider" => "deepl", "config" => provider_config}
|
||||
|
||||
{:error, error} = MachineTranslations.translate(entries, nil, target_language, config)
|
||||
assert error === "Something"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -43,11 +43,10 @@
|
||||
position: relative;
|
||||
gap: 10px;
|
||||
left: 1px;
|
||||
padding: 5px 12px 4px;
|
||||
padding: 7px 12px 6px;
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
border-radius: var(--border-radius);
|
||||
margin-bottom: 3px;
|
||||
color: var(--text-color-normal);
|
||||
|
||||
&:hover,
|
||||
|
@ -1,6 +1,6 @@
|
||||
.wrapper {
|
||||
display: flex;
|
||||
margin-top: 30px;
|
||||
margin-top: 10px;
|
||||
|
||||
& > div:first-of-type {
|
||||
margin-right: 40px;
|
||||
|
@ -1,19 +1,15 @@
|
||||
.navigation--alt {
|
||||
border-bottom: 1px solid var(--input-border-color);
|
||||
|
||||
.navigation-list-item {
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.navigation-list-item-link {
|
||||
position: relative;
|
||||
top: 1px;
|
||||
padding: 10px 15px 8px 10px;
|
||||
border-bottom: 2px solid transparent;
|
||||
padding: 2px 11px 2px 10px;
|
||||
border-radius: var(--border-radius);
|
||||
|
||||
&:global(.active) {
|
||||
border-bottom-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
background: var(--background-light-highlight);
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,7 +17,6 @@
|
||||
.navigation-list {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
min-height: 40px;
|
||||
position: relative;
|
||||
left: -6px;
|
||||
z-index: 10;
|
||||
@ -45,21 +40,19 @@
|
||||
position: relative;
|
||||
padding: 5px 5px 6px 3px;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--color-black);
|
||||
|
||||
&:focus,
|
||||
&:hover,
|
||||
:global(&.active) {
|
||||
color: var(--color-primary);
|
||||
|
||||
.navigation-list-item-link-text {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.navigation-list-item-link-icon {
|
||||
stroke: var(--color-primary);
|
||||
stroke: currentColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,9 +66,9 @@
|
||||
.navigation-list-item-link-icon {
|
||||
transition: 0.2s ease-in-out;
|
||||
transition-property: stroke;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-right: 7px;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
margin-right: 5px;
|
||||
opacity: 0.6;
|
||||
stroke: var(--color-black);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
||||
@onUpdateText={{fn this.onUpdateText}}
|
||||
/>
|
||||
</div>
|
||||
<AsyncButton @onClick={{fn this.save}} @loading={{this.isSaving}} class='button button--filled button--iconOnly'>
|
||||
<AsyncButton @onClick={{fn this.save}} @loading={{this.isSaving}} class='button button--filled'>
|
||||
{{t 'components.related_translations_list.save_button'}}
|
||||
</AsyncButton>
|
||||
{{/unless}}
|
||||
|
Loading…
Reference in New Issue
Block a user