Compare commits
7 Commits
f0c178cf31
...
38b3f0c272
| Author | SHA1 | Date | |
|---|---|---|---|
| 38b3f0c272 | |||
| e8e7f877e7 | |||
| 0089d22da4 | |||
| 2db0ff06ac | |||
| 0a10a5c12c | |||
| 615e64cbd7 | |||
| bec0e0ae5c |
@ -45,3 +45,25 @@
|
||||
.article a {
|
||||
@apply text-cyan-900;
|
||||
}
|
||||
|
||||
.article ul {
|
||||
@apply pl-6 list-disc my-2;
|
||||
}
|
||||
|
||||
.article ol {
|
||||
@apply pl-8 list-decimal my-2;
|
||||
}
|
||||
|
||||
.article li {
|
||||
@apply text-justify;
|
||||
}
|
||||
|
||||
.article img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.article img + div, a + div {
|
||||
font-size: smaller;
|
||||
margin-bottom: 0.6ex;
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ defmodule Outlook.Articles.InternalTree do
|
||||
def cast(_), do: :error
|
||||
|
||||
def load(tree) when is_binary(tree) do
|
||||
{:ok, Jason.decode!(tree, keys: :atoms!) |> from_json}
|
||||
{:ok, Jason.decode!(tree, keys: :atoms) |> from_json}
|
||||
end
|
||||
|
||||
def dump(tree) when is_list(tree) do
|
||||
|
||||
@ -43,7 +43,7 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
|
||||
} | floki_to_internal(rest) ]
|
||||
end
|
||||
|
||||
def floki_to_internal([ ]), do: ( [ ] )
|
||||
def floki_to_internal([]), do: []
|
||||
|
||||
|
||||
def set_sibling_with([ %{type: :element} = node | rest ]) do
|
||||
@ -61,7 +61,7 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
|
||||
[ %InternalNode{ node | eph: %{sibling_with: sib_with} } | set_sibling_with(rest) ]
|
||||
end
|
||||
|
||||
def set_sibling_with([ ]), do: ( [ ] )
|
||||
def set_sibling_with([]), do: []
|
||||
|
||||
|
||||
def strip_whitespace_textnodes [ %{type: :text} = node | rest] do
|
||||
|
||||
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,9 +56,24 @@ defmodule Outlook.InternalTree do
|
||||
Translation.render_translation(tree, translation)
|
||||
end
|
||||
|
||||
def legacy_export(tree, translation) do
|
||||
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
|
||||
|
||||
@ -13,7 +13,7 @@ defmodule Outlook.Translations.TranslationUnitsMap do
|
||||
|
||||
def load(serialized_map) when is_map(serialized_map) do
|
||||
tumap = for {key, val_str} <- serialized_map do
|
||||
val_map = Jason.decode!(val_str, keys: :atoms!)
|
||||
val_map = Jason.decode!(val_str, keys: :atoms)
|
||||
val_tu = struct(TranslationUnit, %{val_map | status: String.to_atom(val_map.status)})
|
||||
{key, val_tu}
|
||||
end
|
||||
|
||||
@ -58,7 +58,7 @@ defmodule Outlook.Translators.Deepl do
|
||||
%{status: "done"} ->
|
||||
response
|
||||
%{status: status} ->
|
||||
steps = response.seconds_remaining * 5
|
||||
steps = Map.get(response, :seconds_remaining, 1) * 5
|
||||
for n <- 0..steps do
|
||||
send(pid, {:progress, %{progress: 100 * n / steps, status: status}})
|
||||
Process.sleep 200
|
||||
|
||||
@ -164,7 +164,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Translation updated successfully")
|
||||
|> continue_edit(params)}
|
||||
|> continue_edit(:edit, params)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, :changeset, changeset)}
|
||||
@ -173,30 +173,36 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
|
||||
defp save_translation(socket, :new, %{"translation" => translation_params} = params) do
|
||||
case Translations.create_translation(translation_params) do
|
||||
{:ok, _translation} ->
|
||||
{:ok, translation} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Translation created successfully")
|
||||
|> continue_edit(params)}
|
||||
|> continue_edit(:new, Map.put(params,"id", translation.id))}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, changeset: changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp continue_edit(socket, %{"continue_edit" => "true"}) do
|
||||
defp continue_edit(socket, :edit, %{"continue_edit" => "true"}) do
|
||||
socket
|
||||
|> assign(:action, :edit)
|
||||
end
|
||||
defp continue_edit(socket, %{"continue_edit" => "false"}) do
|
||||
defp continue_edit(socket, :new, %{"continue_edit" => "true"} = params) do
|
||||
socket |> push_patch(to: ~p(/translations/#{params["id"]}/edit))
|
||||
end
|
||||
defp continue_edit(socket, _, %{"continue_edit" => "false"}) do
|
||||
socket |> push_navigate(to: socket.assigns.navigate)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@ -24,7 +24,7 @@ defmodule OutlookWeb.TranslationLive.NewEdit do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(%{"article_id" => article_id} = _params, _session, socket) when socket.assigns.live_action == :new do
|
||||
def handle_params(%{"article_id" => article_id} = _params, _session, socket) when socket.assigns.live_action == :new do
|
||||
socket = socket
|
||||
|> assign_new(:translation, fn ->
|
||||
%Translation{
|
||||
@ -33,15 +33,15 @@ defmodule OutlookWeb.TranslationLive.NewEdit do
|
||||
}
|
||||
end)
|
||||
|> common_assigns()
|
||||
{:ok, assign_new(socket, :translation_content, fn ->
|
||||
{:noreply, assign_new(socket, :translation_content, fn ->
|
||||
Basic.internal_tree_to_tunit_map(socket.assigns.translation.article.content) end)}
|
||||
end
|
||||
|
||||
def mount(%{"id" => id} = _params, _session, socket) when socket.assigns.live_action == :edit do
|
||||
def handle_params(%{"id" => id} = _params, _session, socket) when socket.assigns.live_action == :edit do
|
||||
socket = socket
|
||||
|> assign_new(:translation, fn -> Translations.get_translation!(id) end)
|
||||
|> common_assigns()
|
||||
{:ok, assign_new(socket, :translation_content, fn -> socket.assigns.translation.content end)}
|
||||
|> assign(:translation, Translations.get_translation!(id))
|
||||
|> common_assigns()
|
||||
{:noreply, assign(socket, :translation_content, socket.assigns.translation.content)}
|
||||
end
|
||||
|
||||
defp get_article(article_id) do
|
||||
|
||||
Reference in New Issue
Block a user