Add hyphenation and a generalized render_public_content function
This commit is contained in:
31
lib/outlook/hyphenation.ex
Normal file
31
lib/outlook/hyphenation.ex
Normal file
@ -0,0 +1,31 @@
|
||||
defmodule Outlook.Hyphenation do
|
||||
|
||||
def hyphenate(html, lang) do
|
||||
form = get_multipart_form(
|
||||
[
|
||||
{"api-token", System.get_env("HYPH_API_TOKEN")},
|
||||
{"hyph[lang]", String.downcase(lang)},
|
||||
{"hyph[text]", html},
|
||||
]
|
||||
)
|
||||
|
||||
response_raw = HTTPoison.request!(
|
||||
:post,
|
||||
System.get_env("HYPH_URL"),
|
||||
form,
|
||||
get_multipart_headers()
|
||||
)
|
||||
response_raw.body
|
||||
end
|
||||
|
||||
defp get_multipart_form fields do
|
||||
{:multipart, fields}
|
||||
end
|
||||
|
||||
defp get_multipart_headers() do
|
||||
[
|
||||
"Content-Type": "multipart/form-data",
|
||||
"Transfer-Encoding": "chunked",
|
||||
]
|
||||
end
|
||||
end
|
||||
@ -2,6 +2,7 @@ defmodule Outlook.InternalTree do
|
||||
|
||||
alias Outlook.InternalTree.{Html,Modifiers,RawInternalBasic,InternalTree,Translation}
|
||||
alias Outlook.HtmlPreparations.HtmlPreparation
|
||||
alias Outlook.{Hyphenation, Translations}
|
||||
|
||||
def render_html(tree) do
|
||||
tree
|
||||
@ -55,11 +56,24 @@ defmodule Outlook.InternalTree do
|
||||
Translation.render_translation(tree, translation)
|
||||
end
|
||||
|
||||
def legacy_export(tree, translation) do
|
||||
content= Translation.render_translation(tree, translation)
|
||||
def render_public_content(tree, translation, language) do
|
||||
Translation.render_translation(tree, translation)
|
||||
|> Html.render_doc()
|
||||
|> Hyphenation.hyphenate(language)
|
||||
end
|
||||
|
||||
def legacy_export(translation_id) do
|
||||
translation = Translations.get_translation!(translation_id)
|
||||
content= Translation.render_translation(translation.article.content, translation.content)
|
||||
|> garnish(%{tunits: %{class: "ttrans", "data-ttrans-status": fn n -> Map.get(n, :status) end}})
|
||||
|> Html.render_doc
|
||||
|> Hyphenation.hyphenate(translation.language)
|
||||
IO.puts "writing export.html to #{File.cwd!}"
|
||||
File.write("export.html", content)
|
||||
end
|
||||
|
||||
def get_tunit_ids(tree) do
|
||||
InternalTree.collect_tunit_ids(tree)
|
||||
# |> List.flatten()
|
||||
end
|
||||
end
|
||||
|
||||
@ -197,8 +197,12 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
defp publish(translation_params, %{"publish" => "true"}, socket) do
|
||||
translation_params
|
||||
|> Map.put("public_content",
|
||||
InternalTree.render_translation(socket.assigns.translation.article.content, translation_params["content"])
|
||||
|> Html.render_doc())
|
||||
InternalTree.render_public_content(
|
||||
socket.assigns.translation.article.content,
|
||||
socket.assigns.translation_content,
|
||||
socket.assigns.translation.language
|
||||
)
|
||||
)
|
||||
end
|
||||
defp publish(translation_params, %{"publish" => "false"}, _) do
|
||||
translation_params
|
||||
|
||||
Reference in New Issue
Block a user