Add rendering the translation with title tags
This commit is contained in:
35
lib/outlook/internal_tree/translation.ex
Normal file
35
lib/outlook/internal_tree/translation.ex
Normal file
@ -0,0 +1,35 @@
|
||||
defmodule Outlook.InternalTree.Translation do
|
||||
|
||||
alias Outlook.InternalTree.{InternalNode,TranslationUnit}
|
||||
|
||||
def render_translation([%TranslationUnit{} = tunit | rest], translation) do
|
||||
[ %TranslationUnit{tunit |
|
||||
eph: add_title_attribute(tunit.eph, tunit.content),
|
||||
content: Map.get(translation, tunit.nid, %{content: "ERROR!!! Missing Tunit in translation!"})
|
||||
|> Map.get(:content)
|
||||
} | render_translation(rest, translation) ]
|
||||
end
|
||||
|
||||
def render_translation([%InternalNode{type: :element} = node | rest], translation) do
|
||||
[ %InternalNode{node |
|
||||
content: render_translation(node.content, translation)
|
||||
} | render_translation(rest, translation) ]
|
||||
end
|
||||
|
||||
def render_translation([node | rest], translation) do
|
||||
[ node | render_translation(rest, translation) ]
|
||||
end
|
||||
|
||||
def render_translation([], _), do: []
|
||||
|
||||
|
||||
defp add_title_attribute(eph, html_string) do
|
||||
attributes = Map.get(eph, :attributes, %{})
|
||||
|> Map.put(:title,
|
||||
html_string
|
||||
|> Floki.parse_fragment!()
|
||||
|> Floki.text()
|
||||
)
|
||||
Map.put(eph, :attributes, attributes)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user