gettext containers
This commit is contained in:
		| @@ -23,17 +23,20 @@ defmodule CanneryWeb.ContainerLive.ContainerCard do | ||||
|  | ||||
|         <%= if @container.desc do %> | ||||
|           <span class="rounded-lg title text-lg"> | ||||
|             Description: <%= @container.desc %> | ||||
|             <%= gettext("Description:") %> | ||||
|             <%= @container.desc %> | ||||
|           </span> | ||||
|         <% end %> | ||||
|  | ||||
|         <span class="rounded-lg title text-lg"> | ||||
|           Type: <%= @container.type %> | ||||
|           <%= gettext("Type:") %> | ||||
|           <%= @container.type %> | ||||
|         </span> | ||||
|  | ||||
|         <%= if @container.location do %> | ||||
|           <span class="rounded-lg title text-lg"> | ||||
|             Location: <%= @container.location %> | ||||
|             <%= gettext("Location:") %> | ||||
|             <%= @container.location %> | ||||
|           </span> | ||||
|         <% end %> | ||||
|       </div> | ||||
|   | ||||
| @@ -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 | ||||
|           </div> | ||||
|         <% 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...") | ||||
|         ) %> | ||||
|       </.form> | ||||
|     </div> | ||||
| @@ -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} -> | ||||
|   | ||||
| @@ -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()) | ||||
|   | ||||
| @@ -1,22 +1,22 @@ | ||||
| <div class="flex flex-col space-y-8 justify-center items-center"> | ||||
|   <h1 class="title text-2xl title-primary-500"> | ||||
|     Listing Containers | ||||
|     <%= gettext("Listing Containers") %> | ||||
|   </h1> | ||||
|  | ||||
|   <%= if @containers |> Enum.empty?() do %> | ||||
|     <h2 class="title text-xl text-primary-500"> | ||||
|       No containers 😔 | ||||
|       <%= gettext("No containers") %> 😔 | ||||
|     </h2> | ||||
|  | ||||
|     <%= 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 %> | ||||
|  | ||||
|   <div class="flex flex-row flex-wrap"> | ||||
| @@ -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 %> | ||||
|           <i class="fa-fw fa-lg fas fa-trash"></i> | ||||
|         <% end %> | ||||
|       </.container_card> | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -5,17 +5,20 @@ | ||||
|  | ||||
|   <%= if @container.desc do %> | ||||
|     <span class="rounded-lg title text-lg"> | ||||
|       Description: <%= @container.desc %> | ||||
|       <%= gettext("Description:") %> | ||||
|       <%= @container.desc %> | ||||
|     </span> | ||||
|   <% end %> | ||||
|  | ||||
|   <span class="rounded-lg title text-lg"> | ||||
|     Type: <%= @container.type %> | ||||
|     <%= gettext("Type:") %> | ||||
|     <%= @container.type %> | ||||
|   </span> | ||||
|  | ||||
|   <%= if @container.location do %> | ||||
|     <span class="rounded-lg title text-lg"> | ||||
|       Location: <%= @container.location %> | ||||
|       <%= gettext("Location:") %> | ||||
|       <%= @container.location %> | ||||
|     </span> | ||||
|   <% 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 %> | ||||
|       <i class="fa-fw fa-lg fas fa-trash"></i> | ||||
|     <% end %> | ||||
|   </div> | ||||
| @@ -37,7 +43,7 @@ | ||||
|  | ||||
|   <p> | ||||
|     <%= 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} /> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user