diff --git a/lib/outlook/translations/translation.ex b/lib/outlook/translations/translation.ex index ba4b59a..6a33ef3 100644 --- a/lib/outlook/translations/translation.ex +++ b/lib/outlook/translations/translation.ex @@ -9,9 +9,10 @@ defmodule Outlook.Translations.Translation do schema "translations" do field :content, TranslationUnitsMap field :date, :utc_datetime - field :lang, :string, default: "DE" + field :language, :string, default: "DE" field :public, :boolean, default: false field :teaser, :string + field :public_content, :string field :title, :string field :unauthorized, :boolean, default: false belongs_to :user, User @@ -23,10 +24,10 @@ defmodule Outlook.Translations.Translation do @doc false def changeset(translation, attrs) do translation - |> cast(attrs, [:lang, :title, :teaser, :date, :public, :unauthorized, :article_id]) + |> cast(attrs, [:language, :title, :teaser, :date, :public, :unauthorized, :article_id]) |> cast(attrs, [:content]) - |> validate_required([:lang, :title, :content, :date, :public, :unauthorized, :article_id]) - |> unique_constraint([:lang, :article_id], + |> validate_required([:language, :title, :content, :date, :public, :unauthorized, :article_id]) + |> unique_constraint([:language, :article_id], message: "translation for this language already exists", name: :article_id_lang_unique_index) |> foreign_key_constraint(:article_id) diff --git a/lib/outlook/translators.ex b/lib/outlook/translators.ex index ca5ab7f..2ea74db 100644 --- a/lib/outlook/translators.ex +++ b/lib/outlook/translators.ex @@ -49,7 +49,7 @@ defmodule Outlook.Translators do end def translate(translation, current_user) do - %{lang: target_lang, + %{language: target_lang, article: %{content: article_tree, language: source_lang} } = translation article_as_html = prepare_article(article_tree) diff --git a/lib/outlook_web/live/article_live/show.html.heex b/lib/outlook_web/live/article_live/show.html.heex index a3acdcf..6d9616c 100644 --- a/lib/outlook_web/live/article_live/show.html.heex +++ b/lib/outlook_web/live/article_live/show.html.heex @@ -17,7 +17,7 @@ <.table id="translations" rows={@article.translations} row_click={&JS.navigate(~p"/translations/#{&1}")}> - <:col :let={translation} label="Lang"><%= translation.lang %> + <:col :let={translation} label="Language"><%= translation.language %> <:col :let={translation} label="Title"><%= translation.title %> <:col :let={translation} label="Teaser"><%= translation.teaser %> <:col :let={translation} label="Date"><%= translation.date %> diff --git a/lib/outlook_web/live/translation_live/form_component.ex b/lib/outlook_web/live/translation_live/form_component.ex index 152a21a..d4f08ec 100644 --- a/lib/outlook_web/live/translation_live/form_component.ex +++ b/lib/outlook_web/live/translation_live/form_component.ex @@ -23,7 +23,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do phx-submit="save" > <.input field={{f, :article_id}} type="hidden" /> - <.input field={{f, :lang}} type="select" label="lang" + <.input field={{f, :language}} type="select" label="language" options={Application.get_env(:outlook,:deepl)[:target_langs]} /> <.input field={{f, :title}} type="text" label="title" /> <.input field={{f, :teaser}} type="textarea" label="teaser" class="h-28" /> diff --git a/lib/outlook_web/live/translation_live/index.html.heex b/lib/outlook_web/live/translation_live/index.html.heex index 46db787..2ab3f21 100644 --- a/lib/outlook_web/live/translation_live/index.html.heex +++ b/lib/outlook_web/live/translation_live/index.html.heex @@ -3,7 +3,7 @@ <.table id="translations" rows={@translations} row_click={&JS.navigate(~p"/translations/#{&1}")}> - <:col :let={translation} label="Lang"><%= translation.lang %> + <:col :let={translation} label="Language"><%= translation.language %> <:col :let={translation} label="Title"><%= translation.title %> <:col :let={translation} label="Teaser"><%= translation.teaser %> <%!-- <:col :let={translation} label="Content"><%= translation.content %> --%> diff --git a/lib/outlook_web/live/translation_live/show.html.heex b/lib/outlook_web/live/translation_live/show.html.heex index 838d0ee..25eeb37 100644 --- a/lib/outlook_web/live/translation_live/show.html.heex +++ b/lib/outlook_web/live/translation_live/show.html.heex @@ -9,7 +9,7 @@ <.list> - <:item title="Lang"><%= @translation.lang %> + <:item title="Language"><%= @translation.language %> <:item title="Title"><%= @translation.title %> <:item title="Teaser"><%= @translation.teaser %> <%!-- <:item title="Content"><%= @translation.content %> --%> diff --git a/priv/repo/migrations/20230115161150_add_public_content_to_translations.exs b/priv/repo/migrations/20230115161150_add_public_content_to_translations.exs new file mode 100644 index 0000000..3f49c42 --- /dev/null +++ b/priv/repo/migrations/20230115161150_add_public_content_to_translations.exs @@ -0,0 +1,10 @@ +defmodule Outlook.Repo.Migrations.AddPublicContentToTranslations do + use Ecto.Migration + + def change do + alter table(:translations) do + add :public_content, :text + end + rename table(:translations), :lang, to: :language + end +end