From 5451728541ad44500141cf7e18f7f13b960ff831 Mon Sep 17 00:00:00 2001 From: shibao Date: Wed, 9 Feb 2022 00:58:53 -0500 Subject: [PATCH] gettext invites and tags --- .../live/invite_live/form_component.ex | 12 +-- lib/cannery_web/live/invite_live/index.ex | 6 +- .../live/invite_live/index.html.leex | 33 ++++--- .../live/tag_live/form_component.ex | 22 ++--- lib/cannery_web/live/tag_live/index.ex | 8 +- lib/cannery_web/live/tag_live/index.html.heex | 10 +-- lib/cannery_web/live/tag_live/tag_card.ex | 4 +- priv/gettext/actions.pot | 22 +++++ priv/gettext/default.pot | 89 +++++++++++++++++++ priv/gettext/prompts.pot | 33 +++++++ 10 files changed, 192 insertions(+), 47 deletions(-) diff --git a/lib/cannery_web/live/invite_live/form_component.ex b/lib/cannery_web/live/invite_live/form_component.ex index 32385c5..8145b3c 100644 --- a/lib/cannery_web/live/invite_live/form_component.ex +++ b/lib/cannery_web/live/invite_live/form_component.ex @@ -50,17 +50,17 @@ defmodule CanneryWeb.InviteLive.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") %> <%= error_tag(f, :name, "col-span-3") %> - <%= label(f, :uses_left, class: "title text-lg text-primary-500") %> + <%= label(f, :uses_left, gettext("Uses left"), class: "title text-lg text-primary-500") %> <%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %> <%= error_tag(f, :uses_left, "col-span-3") %> - <%= 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...") ) %> @@ -72,7 +72,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do {:ok, _invite} -> {:noreply, socket - |> put_flash(:info, "Invite updated successfully") + |> put_flash(:info, dgettext("prompts", "Invite updated successfully")) |> push_redirect(to: socket.assigns.return_to)} {:error, %Changeset{} = changeset} -> @@ -85,7 +85,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do {:ok, _invite} -> {:noreply, socket - |> put_flash(:info, "Invite created successfully") + |> put_flash(:info, dgettext("prompts", "Invite created successfully")) |> push_redirect(to: socket.assigns.return_to)} {:error, %Changeset{} = changeset} -> diff --git a/lib/cannery_web/live/invite_live/index.ex b/lib/cannery_web/live/invite_live/index.ex index f13f5d5..647f4ee 100644 --- a/lib/cannery_web/live/invite_live/index.ex +++ b/lib/cannery_web/live/invite_live/index.ex @@ -20,17 +20,17 @@ defmodule CanneryWeb.InviteLive.Index do defp apply_action(socket, :edit, %{"id" => id}) do socket - |> assign(page_title: "Edit Invite", invite: Invites.get_invite!(id)) + |> assign(page_title: gettext("Edit Invite"), invite: Invites.get_invite!(id)) end defp apply_action(socket, :new, _params) do socket - |> assign(page_title: "New Invite", invite: %Invite{}) + |> assign(page_title: gettext("New Invite"), invite: %Invite{}) end defp apply_action(socket, :index, _params) do socket - |> assign(page_title: "Listing Invites", invite: nil) + |> assign(page_title: gettext("Listing Invites"), invite: nil) end @impl true diff --git a/lib/cannery_web/live/invite_live/index.html.leex b/lib/cannery_web/live/invite_live/index.html.leex index e983020..c099082 100644 --- a/lib/cannery_web/live/invite_live/index.html.leex +++ b/lib/cannery_web/live/invite_live/index.html.leex @@ -1,22 +1,20 @@

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

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

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

- <%= live_patch to: Routes.invite_index_path(@socket, :new), - class: "btn btn-primary" do %> - Invite someone new! - <% end %> + <%= live_patch dgettext("actions", "Invite someone new!"), + to: Routes.invite_index_path(@socket, :new), + class: "btn btn-primary" %> <% else %> - <%= live_patch to: Routes.invite_index_path(@socket, :new), - class: "btn btn-primary" do %> - Create Invite - <% end %> + <%= live_patch dgettext("actions", "Create Invite"), + to: Routes.invite_index_path(@socket, :new), + class: "btn btn-primary" %> <% end %>
@@ -29,11 +27,12 @@ <%= if invite.disabled_at |> is_nil() do %>

- Uses Left: <%= invite.uses_left || "Unlimited" %> + <%= gettext("Uses Left:") %> + <%= invite.uses_left || "Unlimited" %>

<% else %>

- Invite Disabled + <%= gettext("Invite Disabled") %>

<% end %> @@ -51,27 +50,27 @@ class: "text-primary-500 link", phx_click: "delete", phx_value_id: invite.id, - data: [confirm: "Are you sure you want to delete the invite for #{invite.name}?"] do %> + data: [confirm: dgettext("prompts", "Are you sure you want to delete the invite for %{name}?", name: invite.name)] do %> <% end %> <%= if invite.disabled_at |> is_nil() do %> - Disable + <%= gettext("Disable") %> <% else %> - Enable + <%= gettext("Enable") %> <% end %> <%= if invite.disabled_at |> is_nil() and not(invite.uses_left |> is_nil()) do %> - Set Unlimited + data-confirm={dgettext("prompts", "Are you sure you want to make this invite unlimited?")}> + <%= gettext("Set Unlimited") %> <% end %>
diff --git a/lib/cannery_web/live/tag_live/form_component.ex b/lib/cannery_web/live/tag_live/form_component.ex index 9dbc1dd..4035eb3 100644 --- a/lib/cannery_web/live/tag_live/form_component.ex +++ b/lib/cannery_web/live/tag_live/form_component.ex @@ -21,14 +21,11 @@ defmodule CanneryWeb.TagLive.FormComponent do @impl true def handle_event("validate", %{"tag" => tag_params}, socket) do tag_params = tag_params |> Map.put("user_id", socket.assigns.current_user.id) - changeset = socket.assigns.tag |> Tags.change_tag(tag_params) - {:noreply, socket |> assign(:changeset, changeset)} end def handle_event("save", %{"tag" => tag_params}, socket) do - tag_params = tag_params |> Map.put("user_id", socket.assigns.current_user.id) save_tag(socket, socket.assigns.action, tag_params) end @@ -54,25 +51,25 @@ defmodule CanneryWeb.TagLive.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") %> <%= error_tag(f, :name, "col-span-3") %> - <%= label(f, :bg_color, class: "title text-lg text-primary-500") %> + <%= label(f, :bg_color, gettext("Background color"), class: "title text-lg text-primary-500") %> <%= color_input(f, :bg_color) %> <%= error_tag(f, :bg_color, "col-span-3") %> - <%= label(f, :text_color, class: "title text-lg text-primary-500") %> + <%= label(f, :text_color, gettext("Text color"), class: "title text-lg text-primary-500") %> <%= color_input(f, :text_color) %> <%= error_tag(f, :text_color, "col-span-3") %> - <%= 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...") ) %> @@ -84,7 +81,7 @@ defmodule CanneryWeb.TagLive.FormComponent do {:ok, _tag} -> {:noreply, socket - |> put_flash(:info, "Tag updated successfully") + |> put_flash(:info, dgettext("prompts", "Tag updated successfully")) |> push_redirect(to: socket.assigns.return_to)} {:error, %Changeset{} = changeset} -> @@ -93,11 +90,14 @@ defmodule CanneryWeb.TagLive.FormComponent do end defp save_tag(socket, :new, tag_params) do - case Tags.create_tag(tag_params) do + tag_params + |> Map.put("user_id", socket.assigns.current_user.id) + |> Tags.create_tag() + |> case do {:ok, _tag} -> {:noreply, socket - |> put_flash(:info, "Tag created successfully") + |> put_flash(:info, dgettext("prompts", "Tag created successfully")) |> push_redirect(to: socket.assigns.return_to)} {:error, %Changeset{} = changeset} -> diff --git a/lib/cannery_web/live/tag_live/index.ex b/lib/cannery_web/live/tag_live/index.ex index 04607e8..642e058 100644 --- a/lib/cannery_web/live/tag_live/index.ex +++ b/lib/cannery_web/live/tag_live/index.ex @@ -20,19 +20,19 @@ defmodule CanneryWeb.TagLive.Index do defp apply_action(socket, :edit, %{"id" => id}) do socket - |> assign(:page_title, "Edit Tag") + |> assign(:page_title, gettext("Edit Tag")) |> assign(:tag, Tags.get_tag!(id)) end defp apply_action(socket, :new, _params) do socket - |> assign(:page_title, "New Tag") + |> assign(:page_title, gettext("New Tag")) |> assign(:tag, %Tag{bg_color: Tags.random_bg_color(), text_color: "#ffffff"}) end defp apply_action(socket, :index, _params) do socket - |> assign(:page_title, "Listing Tags") + |> assign(:page_title, gettext("Listing Tags")) |> assign(:tag, nil) end @@ -40,7 +40,7 @@ defmodule CanneryWeb.TagLive.Index do def handle_event("delete", %{"id" => id}, socket) do tag = Tags.get_tag!(id) {:ok, _} = Tags.delete_tag(tag) - socket = socket |> put_flash(:info, "Tag deleted succesfully") + socket = socket |> put_flash(:info, dgettext("prompts", "Tag deleted succesfully")) {:noreply, socket |> display_tags()} end diff --git a/lib/cannery_web/live/tag_live/index.html.heex b/lib/cannery_web/live/tag_live/index.html.heex index ee4d9e9..50589eb 100644 --- a/lib/cannery_web/live/tag_live/index.html.heex +++ b/lib/cannery_web/live/tag_live/index.html.heex @@ -1,21 +1,21 @@

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

- Tags can be added to your containers to help you organize + <%= gettext("Tags can be added to your containers to help you organize") %>

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

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

- <%= live_patch("Make your first tag!", + <%= live_patch(dgettext("actions", "Make your first tag!"), to: Routes.tag_index_path(@socket, :new), class: "btn btn-primary" ) %> <% else %> - <%= live_patch("New Tag", + <%= live_patch(dgettext("actions", "New Tag"), to: Routes.tag_index_path(@socket, :new), class: "btn btn-primary" ) %> diff --git a/lib/cannery_web/live/tag_live/tag_card.ex b/lib/cannery_web/live/tag_live/tag_card.ex index 4abceeb..e5b2b3f 100644 --- a/lib/cannery_web/live/tag_live/tag_card.ex +++ b/lib/cannery_web/live/tag_live/tag_card.ex @@ -29,7 +29,9 @@ defmodule CanneryWeb.TagLive.TagCard do class: "text-primary-500 link", phx_click: "delete", phx_value_id: @tag.id, - data: [confirm: "Are you sure you want to delete #{@tag.name}?"] do %> + data: [ + confirm: dgettext("prompts", "Are you sure you want to delete %{name}?", name: @tag.name) + ] do %> <% end %>
diff --git a/priv/gettext/actions.pot b/priv/gettext/actions.pot index 617e291..362807b 100644 --- a/priv/gettext/actions.pot +++ b/priv/gettext/actions.pot @@ -94,6 +94,8 @@ msgstr "" #: 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 +#: lib/cannery_web/live/invite_live/form_component.ex:61 +#: lib/cannery_web/live/tag_live/form_component.ex:70 msgid "Save" msgstr "" @@ -121,3 +123,23 @@ msgstr "" #: lib/cannery_web/live/container_live/index.html.heex:16 msgid "New Container" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:15 +msgid "Create Invite" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:11 +msgid "Invite someone new!" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.html.heex:18 +msgid "New Tag" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.html.heex:13 +msgid "Make your first tag!" +msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 9deae3e..e1e6516 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -304,6 +304,8 @@ msgstr "" #: 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 +#: lib/cannery_web/live/invite_live/form_component.ex:53 +#: lib/cannery_web/live/tag_live/form_component.ex:54 msgid "Name" msgstr "" @@ -447,3 +449,90 @@ msgstr "" #: lib/cannery_web/live/container_live/show.html.heex:14 msgid "Type:" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/form_component.ex:58 +msgid "Background color" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:60 +msgid "Disable" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.ex:23 +msgid "Edit Invite" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.ex:23 +msgid "Edit Tag" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:65 +msgid "Enable" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:35 +msgid "Invite Disabled" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.ex:33 +#: lib/cannery_web/live/invite_live/index.html.leex:3 +msgid "Listing Invites" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.ex:35 +#: lib/cannery_web/live/tag_live/index.html.heex:3 +msgid "Listing Tags" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.ex:28 +msgid "New Invite" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.ex:29 +msgid "New Tag" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:8 +msgid "No invites" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.html.heex:10 +msgid "No tags" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:73 +msgid "Set Unlimited" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.html.heex:6 +msgid "Tags can be added to your containers to help you organize" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/form_component.ex:64 +msgid "Text color" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:30 +msgid "Uses Left:" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/form_component.ex:57 +msgid "Uses left" +msgstr "" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index 470a0b9..fbb8770 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -97,6 +97,8 @@ msgstr "" #: 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 +#: lib/cannery_web/live/invite_live/form_component.ex:63 +#: lib/cannery_web/live/tag_live/form_component.ex:72 msgid "Saving..." msgstr "" @@ -114,6 +116,7 @@ msgstr "" #: 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 +#: lib/cannery_web/live/tag_live/tag_card.ex:33 msgid "Are you sure you want to delete %{name}?" msgstr "" @@ -132,3 +135,33 @@ msgstr "" #: lib/cannery_web/live/container_live/form_component.ex:98 msgid "Container updated successfully" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.html.leex:53 +msgid "Are you sure you want to delete the invite for %{name}?" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/form_component.ex:88 +msgid "Invite created successfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/form_component.ex:75 +msgid "Invite updated successfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/form_component.ex:100 +msgid "Tag created successfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/index.ex:43 +msgid "Tag deleted succesfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/tag_live/form_component.ex:84 +msgid "Tag updated successfully" +msgstr ""