Add use <tunit> instead of <span> for Deepl translation
To avoid getting results like "... bla."</span>" -> "... bla</span>."" from Deepl we need to set set splitting_tags option to an element name (that's not as common as span).
This commit is contained in:
@ -73,7 +73,7 @@ defmodule Outlook.Translators do
|
||||
|
||||
defp prepare_article(tree) do
|
||||
# Logger.info "so far."
|
||||
HtmlDocComponent.render_doc(%{tree: tree})
|
||||
HtmlDocComponent.render_doc(%{tree: tree, tunit_tag: "tunit"})
|
||||
|> Phoenix.HTML.Safe.to_iodata()
|
||||
|> IO.iodata_to_binary()
|
||||
end
|
||||
@ -86,7 +86,7 @@ defmodule Outlook.Translators do
|
||||
def process_translation(translation, tunit_ids) do
|
||||
tunit_map = translation
|
||||
|> Floki.parse_fragment!
|
||||
|> Floki.find("span.tunit")
|
||||
|> Floki.find("tunit")
|
||||
|> Enum.map(fn {_,atts,cont} ->
|
||||
%TranslationUnit{
|
||||
nid: Enum.find(atts, fn {k,_} -> k == "nid" end) |> Tuple.to_list |> Enum.at(1),
|
||||
|
||||
@ -26,6 +26,8 @@ defmodule Outlook.Translators.Deepl do
|
||||
[
|
||||
{"source_lang", options.source_lang},
|
||||
{"target_lang", options.target_lang},
|
||||
{"tag_handling", "xml"},
|
||||
{"splitting_tags", "tunit"},
|
||||
{"file", content, {"form-data", [{:name, "file"}, {:filename, "datei.html"}]}, []}
|
||||
]
|
||||
)
|
||||
|
||||
@ -9,17 +9,22 @@ defmodule OutlookWeb.HtmlDocComponent do
|
||||
|
||||
attr :tree, :list, required: true
|
||||
|
||||
def render_doc(assigns) do
|
||||
def render_doc(%{tunit_tag: _} = assigns) do
|
||||
~H"""
|
||||
<%= for node <- @tree do %>
|
||||
<.dnode node={node} />
|
||||
<.dnode node={node} tunit_tag={@tunit_tag} />
|
||||
<% end %>
|
||||
"""
|
||||
end
|
||||
def render_doc(assigns) do
|
||||
assigns
|
||||
|> assign(:tunit_tag, "span")
|
||||
|> render_doc()
|
||||
end
|
||||
|
||||
def dnode(%{node: %{status: status}} = assigns) do
|
||||
~H"""
|
||||
<.dynamic_tag name="span" class="tunit" nid={@node.nid} {Map.get(@node.eph, :attributes, %{})}>
|
||||
<.dynamic_tag name={@tunit_tag} class="tunit" nid={@node.nid} {Map.get(@node.eph, :attributes, %{})}>
|
||||
<%= @node.content |> raw %>
|
||||
</.dynamic_tag>
|
||||
"""
|
||||
@ -27,9 +32,9 @@ defmodule OutlookWeb.HtmlDocComponent do
|
||||
|
||||
def dnode(assigns) when assigns.node.type == :element do
|
||||
~H"""
|
||||
<.dynamic_tag name={@node.name} nid={@node.nid} {Map.get(@node.eph, :attributes, %{})}>
|
||||
<.dynamic_tag name={@node.name} nid={@node.nid} {@node.attributes |> Map.merge(Map.get(@node.eph, :attributes, %{}))}>
|
||||
<%= for child_node <- @node.content do %>
|
||||
<.dnode node={child_node} />
|
||||
<.dnode node={child_node} tunit_tag={@tunit_tag} />
|
||||
<% end %>
|
||||
</.dynamic_tag>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user