From 91b9e8a730b76df5741fa578640c9f20a69cf9ae Mon Sep 17 00:00:00 2001 From: shibao Date: Wed, 9 Feb 2022 00:49:47 -0500 Subject: [PATCH] gettext containers --- .../live/container_live/container_card.ex | 9 +- .../live/container_live/form_component.ex | 25 +++--- lib/cannery_web/live/container_live/index.ex | 22 +++-- .../live/container_live/index.html.heex | 19 +++-- lib/cannery_web/live/container_live/show.ex | 16 +++- .../live/container_live/show.html.heex | 16 ++-- priv/gettext/actions.pot | 11 +++ priv/gettext/default.pot | 82 +++++++++++++++++++ priv/gettext/errors.pot | 11 +++ priv/gettext/prompts.pot | 19 +++++ 10 files changed, 191 insertions(+), 39 deletions(-) diff --git a/lib/cannery_web/live/container_live/container_card.ex b/lib/cannery_web/live/container_live/container_card.ex index 800b9062..d8cacf0b 100644 --- a/lib/cannery_web/live/container_live/container_card.ex +++ b/lib/cannery_web/live/container_live/container_card.ex @@ -23,17 +23,20 @@ defmodule CanneryWeb.ContainerLive.ContainerCard do <%= if @container.desc do %> - Description: <%= @container.desc %> + <%= gettext("Description:") %> + <%= @container.desc %> <% end %> - Type: <%= @container.type %> + <%= gettext("Type:") %> + <%= @container.type %> <%= if @container.location do %> - Location: <%= @container.location %> + <%= gettext("Location:") %> + <%= @container.location %> <% end %> diff --git a/lib/cannery_web/live/container_live/form_component.ex b/lib/cannery_web/live/container_live/form_component.ex index d7f40923..eedc56d5 100644 --- a/lib/cannery_web/live/container_live/form_component.ex +++ b/lib/cannery_web/live/container_live/form_component.ex @@ -16,7 +16,6 @@ defmodule CanneryWeb.ContainerLive.FormComponent do @impl true def handle_event("validate", %{"container" => container_params}, socket) do - container_params = container_params |> Map.put("user_id", socket.assigns.current_user.id) changeset = socket.assigns.container |> Containers.change_container(container_params) {:noreply, socket |> assign(:changeset, changeset)} end @@ -47,39 +46,39 @@ defmodule CanneryWeb.ContainerLive.FormComponent do <% end %> - <%= label(f, :name, class: "title text-lg text-primary-500") %> + <%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %> <%= text_input(f, :name, class: "input input-primary col-span-2", - placeholder: "My cool ammo can" + placeholder: gettext("My cool ammo can") ) %> <%= error_tag(f, :name, "col-span-3 text-center") %> - <%= label(f, :desc, class: "title text-lg text-primary-500") %> + <%= label(f, :desc, gettext("Description"), class: "title text-lg text-primary-500") %> <%= textarea(f, :desc, class: "input input-primary col-span-2", phx_hook: "MaintainAttrs", - placeholder: "Metal ammo can with the anime girl sticker" + placeholder: gettext("Metal ammo can with the anime girl sticker") ) %> <%= error_tag(f, :desc, "col-span-3 text-center") %> - <%= label(f, :type, class: "title text-lg text-primary-500") %> + <%= label(f, :type, gettext("Type"), class: "title text-lg text-primary-500") %> <%= text_input(f, :type, class: "input input-primary col-span-2", - placeholder: "Magazine, Clip, Ammo Box, etc" + placeholder: gettext("Magazine, Clip, Ammo Box, etc") ) %> <%= error_tag(f, :type, "col-span-3 text-center") %> - <%= label(f, :location, class: "title text-lg text-primary-500") %> + <%= label(f, :location, gettext("Location"), class: "title text-lg text-primary-500") %> <%= textarea(f, :location, class: "input input-primary col-span-2", phx_hook: "MaintainAttrs", - placeholder: "On the bookshelf" + placeholder: gettext("On the bookshelf") ) %> <%= error_tag(f, :location, "col-span-3 text-center") %> - <%= submit("Save", + <%= submit(dgettext("actions", "Save"), class: "mx-auto btn btn-primary col-span-3", - phx_disable_with: "Saving..." + phx_disable_with: dgettext("prompts", "Saving...") ) %> @@ -96,7 +95,7 @@ defmodule CanneryWeb.ContainerLive.FormComponent do {:ok, _container} -> {:noreply, socket - |> put_flash(:info, "Container updated successfully") + |> put_flash(:info, dgettext("prompts", "Container updated successfully")) |> push_redirect(to: socket.assigns.return_to)} {:error, %Changeset{} = changeset} -> @@ -111,7 +110,7 @@ defmodule CanneryWeb.ContainerLive.FormComponent do {:ok, _container} -> {:noreply, socket - |> put_flash(:info, "Container created successfully") + |> put_flash(:info, dgettext("prompts", "Container created successfully")) |> push_redirect(to: socket.assigns.return_to)} {:error, %Changeset{} = changeset} -> diff --git a/lib/cannery_web/live/container_live/index.ex b/lib/cannery_web/live/container_live/index.ex index bb1d6c1e..ab6f95a5 100644 --- a/lib/cannery_web/live/container_live/index.ex +++ b/lib/cannery_web/live/container_live/index.ex @@ -19,19 +19,19 @@ defmodule CanneryWeb.ContainerLive.Index do defp apply_action(socket, :edit, %{"id" => id}) do socket - |> assign(:page_title, "Edit Container") + |> assign(:page_title, gettext("Edit Container")) |> assign(:container, Containers.get_container!(id)) end defp apply_action(socket, :new, _params) do socket - |> assign(:page_title, "New Container") + |> assign(:page_title, gettext("New Container")) |> assign(:container, %Container{}) end defp apply_action(socket, :index, _params) do socket - |> assign(:page_title, "Listing Containers") + |> assign(:page_title, gettext("Listing Containers")) |> assign(:container, nil) end @@ -42,7 +42,7 @@ defmodule CanneryWeb.ContainerLive.Index do |> Enum.find(fn %{id: container_id} -> id == container_id end) |> case do nil -> - socket |> put_flash(:error, "Could not find that container") + socket |> put_flash(:error, dgettext("errors", "Could not find that container")) container -> container @@ -50,12 +50,22 @@ defmodule CanneryWeb.ContainerLive.Index do |> case do {:ok, container} -> socket - |> put_flash(:info, "#{container.name} has been deleted") + |> put_flash( + :info, + dgettext("prompts", "%{name} has been deleted", name: container.name) + ) |> display_containers() {:error, %{action: :delete, errors: [ammo_groups: _error], valid?: false} = changeset} -> ammo_groups_error = changeset |> changeset_errors(:ammo_groups) |> Enum.join(", ") - socket |> put_flash(:error, "Could not delete container: #{ammo_groups_error}") + + socket + |> put_flash( + :error, + dgettext("errors", "Could not delete container: %{error}", + error: ammo_groups_error + ) + ) {:error, changeset} -> socket |> put_flash(:error, changeset |> changeset_errors()) diff --git a/lib/cannery_web/live/container_live/index.html.heex b/lib/cannery_web/live/container_live/index.html.heex index 8a531dc3..a8f99e10 100644 --- a/lib/cannery_web/live/container_live/index.html.heex +++ b/lib/cannery_web/live/container_live/index.html.heex @@ -1,22 +1,22 @@

- Listing Containers + <%= gettext("Listing Containers") %>

<%= if @containers |> Enum.empty?() do %>

- No containers 😔 + <%= gettext("No containers") %> 😔

- <%= live_patch("Add your first container!", + <%= live_patch(dgettext("actions", "Add your first container!"), to: Routes.container_index_path(@socket, :new), class: "btn btn-primary" ) %> <% else %> - <%= live_patch to: Routes.container_index_path(@socket, :new), - class: "btn btn-primary" do %> - New Container - <% end %> + <%= live_patch(dgettext("actions", "New Container"), + to: Routes.container_index_path(@socket, :new), + class: "btn btn-primary" + ) %> <% end %>
@@ -31,7 +31,10 @@ class: "text-primary-500 link", phx_click: "delete", phx_value_id: container.id, - data: [confirm: "Are you sure you want to delete #{container.name}?"] do %> + data: [ + confirm: + dgettext("prompts", "Are you sure you want to delete %{name}?", name: container.name) + ] do %> <% end %> diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex index 254db7a1..0e358519 100644 --- a/lib/cannery_web/live/container_live/show.ex +++ b/lib/cannery_web/live/container_live/show.ex @@ -32,12 +32,20 @@ defmodule CanneryWeb.ContainerLive.Show do |> case do {:ok, container} -> socket - |> put_flash(:info, "#{container.name} has been deleted") + |> put_flash( + :info, + dgettext("prompts", "%{name} has been deleted", name: container.name) + ) |> push_redirect(to: Routes.container_index_path(socket, :index)) {:error, %{action: :delete, errors: [ammo_groups: _error], valid?: false} = changeset} -> ammo_groups_error = changeset |> changeset_errors(:ammo_groups) |> Enum.join(", ") - socket |> put_flash(:error, "Could not delete container: #{ammo_groups_error}") + + socket + |> put_flash( + :error, + dgettext("errors", "Could not delete container: %{error}", error: ammo_groups_error) + ) {:error, changeset} -> socket |> put_flash(:error, changeset |> changeset_errors()) @@ -46,6 +54,6 @@ defmodule CanneryWeb.ContainerLive.Show do {:noreply, socket} end - defp page_title(:show), do: "Show Container" - defp page_title(:edit), do: "Edit Container" + defp page_title(:show), do: gettext("Show Container") + defp page_title(:edit), do: gettext("Edit Container") end diff --git a/lib/cannery_web/live/container_live/show.html.heex b/lib/cannery_web/live/container_live/show.html.heex index cf9ccc76..f2f2987e 100644 --- a/lib/cannery_web/live/container_live/show.html.heex +++ b/lib/cannery_web/live/container_live/show.html.heex @@ -5,17 +5,20 @@ <%= if @container.desc do %> - Description: <%= @container.desc %> + <%= gettext("Description:") %> + <%= @container.desc %> <% end %> - Type: <%= @container.type %> + <%= gettext("Type:") %> + <%= @container.type %> <%= if @container.location do %> - Location: <%= @container.location %> + <%= gettext("Location:") %> + <%= @container.location %> <% end %> @@ -28,7 +31,10 @@ <%= link to: "#", class: "text-primary-500 link", phx_click: "delete", - data: [confirm: "Are you sure you want to delete #{@container.name}?"] do %> + data: [ + confirm: + dgettext("prompts", "Are you sure you want to delete %{name}?", name: @container.name) + ] do %> <% end %>
@@ -37,7 +43,7 @@

<%= if @container.ammo_groups |> Enum.empty?() do %> - No ammo groups in this container + <%= gettext("No ammo groups in this container") %> <% else %> <%= for ammo_group <- @container.ammo_groups do %> <.ammo_group_card ammo_group={ammo_group} /> diff --git a/priv/gettext/actions.pot b/priv/gettext/actions.pot index fa6ec529..617e2919 100644 --- a/priv/gettext/actions.pot +++ b/priv/gettext/actions.pot @@ -93,6 +93,7 @@ msgstr "" #, elixir-format, ex-autogen #: lib/cannery_web/live/ammo_group_live/form_component.ex:90 #: lib/cannery_web/live/ammo_type_live/form_component.ex:155 +#: lib/cannery_web/live/container_live/form_component.ex:79 msgid "Save" msgstr "" @@ -110,3 +111,13 @@ msgstr "" #: lib/cannery_web/live/ammo_type_live/index.html.heex:16 msgid "New Ammo type" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.html.heex:11 +msgid "Add your first container!" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.html.heex:16 +msgid "New Container" +msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index d467e6fb..9deae3ed 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -251,6 +251,7 @@ msgstr "" #, elixir-format, ex-autogen #: lib/cannery_web/live/ammo_type_live/form_component.ex:57 +#: lib/cannery_web/live/container_live/form_component.ex:56 msgid "Description" msgstr "" @@ -302,6 +303,7 @@ msgstr "" #, elixir-format, ex-autogen #: lib/cannery_web/live/ammo_type_live/form_component.ex:53 #: lib/cannery_web/live/ammo_type_live/index.html.heex:26 +#: lib/cannery_web/live/container_live/form_component.ex:49 msgid "Name" msgstr "" @@ -365,3 +367,83 @@ msgstr "" #: lib/cannery_web/live/ammo_type_live/index.html.heex:36 msgid "Tracer" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/container_card.ex:26 +#: lib/cannery_web/live/container_live/show.html.heex:8 +msgid "Description:" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:22 +#: lib/cannery_web/live/container_live/show.ex:58 +msgid "Edit Container" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:34 +#: lib/cannery_web/live/container_live/index.html.heex:3 +msgid "Listing Containers" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:71 +msgid "Location" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/container_card.ex:38 +#: lib/cannery_web/live/container_live/show.html.heex:20 +msgid "Location:" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:67 +msgid "Magazine, Clip, Ammo Box, etc" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:60 +msgid "Metal ammo can with the anime girl sticker" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:52 +msgid "My cool ammo can" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:28 +msgid "New Container" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/show.html.heex:46 +msgid "No ammo groups in this container" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.html.heex:8 +msgid "No containers" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:75 +msgid "On the bookshelf" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/show.ex:57 +msgid "Show Container" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:64 +msgid "Type" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/container_card.ex:32 +#: lib/cannery_web/live/container_live/show.html.heex:14 +msgid "Type:" +msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 30b51d81..be18094c 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -199,3 +199,14 @@ msgstr "" #: lib/cannery_web/controllers/user_auth.ex:145 msgid "You must log in to access this page." msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:65 +#: lib/cannery_web/live/container_live/show.ex:47 +msgid "Could not delete container: %{error}" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:45 +msgid "Could not find that container" +msgstr "" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index f844d392..470a0b92 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -96,6 +96,7 @@ msgstr "" #, elixir-format, ex-autogen #: lib/cannery_web/live/ammo_group_live/form_component.ex:91 #: lib/cannery_web/live/ammo_type_live/form_component.ex:156 +#: lib/cannery_web/live/container_live/form_component.ex:81 msgid "Saving..." msgstr "" @@ -111,5 +112,23 @@ msgstr "" #, elixir-format, ex-autogen #: lib/cannery_web/live/ammo_type_live/show.html.heex:26 +#: lib/cannery_web/live/container_live/index.html.heex:36 +#: lib/cannery_web/live/container_live/show.html.heex:36 msgid "Are you sure you want to delete %{name}?" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:55 +#: lib/cannery_web/live/container_live/show.ex:37 +msgid "%{name} has been deleted" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:113 +msgid "Container created successfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/form_component.ex:98 +msgid "Container updated successfully" +msgstr ""