Update Deepl translation
Now getting auth-key from db.
This commit is contained in:
@ -63,9 +63,21 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
{:ok, socket |> assign(deepl_progress: progress)}
|
||||
end
|
||||
|
||||
def update(%{deepl_translation: translation}, socket) do
|
||||
tunit_keys = Map.keys(socket.assigns.translation_content)
|
||||
case Outlook.Translators.process_translation_result(translation, tunit_keys) do
|
||||
{:ok, new_translation_content} ->
|
||||
{:ok, socket
|
||||
|> assign(translation_content: new_translation_content)
|
||||
|> update_current_tunit()}
|
||||
{:error, message} ->
|
||||
{:ok, socket |> put_flash(:error, message)}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("translate-deepl", _, socket) do
|
||||
Task.start_link(Outlook.Translators.Deepl, :test, [self()])
|
||||
Outlook.Translators.translate(socket.assigns.translation, socket.assigns.current_user)
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@ -98,11 +110,21 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
|> assign(:current_tunit, socket.assigns.translation_content[uuid])}
|
||||
end
|
||||
|
||||
@doc "updating on browser events"
|
||||
def handle_event("update_current_tunit", %{"content" => content}, socket) do
|
||||
tunit = %TranslationUnit{socket.assigns.current_tunit | content: content}
|
||||
{:noreply, socket |> assign(:current_tunit, tunit)}
|
||||
end
|
||||
|
||||
|
||||
# updating after Deepl translation
|
||||
defp update_current_tunit(socket) when is_struct(socket.assigns.current_tunit) do
|
||||
assign(socket,
|
||||
:current_tunit,
|
||||
socket.assigns.translation_content[socket.assigns.current_tunit.uuid])
|
||||
end
|
||||
defp update_current_tunit(socket), do: socket
|
||||
|
||||
defp update_translation_with_current_tunit(socket) do
|
||||
translation_content = if socket.assigns.current_tunit do
|
||||
socket.assigns.translation_content
|
||||
|
||||
Reference in New Issue
Block a user