gettext topbar

This commit is contained in:
shibao 2022-02-08 23:38:20 -05:00
parent 185d8598da
commit e3b94477db
8 changed files with 86 additions and 30 deletions

View File

@ -41,8 +41,9 @@ If you're multilingual, this project can use your translations! Visit
- When adding text, please use `gettext` macros to enable things to be - When adding text, please use `gettext` macros to enable things to be
translated in the future. After adding `gettext` macros, run `mix format` in translated in the future. After adding `gettext` macros, run `mix format` in
order to add your new text strings to the files in `priv/gettext`. order to add your new text strings to the files in `priv/gettext`.
- Existing domains: `"default"` (for anything general), `"prompts"`, - Existing domains: `"default"` (for anything general), `"prompts"` (as a
`"emails"`, and `"errors"` result of the user doing an action), `"actions"` (actions that the user can
take), `"emails"`, and `"errors"`
- Before submitting a PR, please make sure all tests are passing using `mix test`. - Before submitting a PR, please make sure all tests are passing using `mix test`.
And as always, thank you! And as always, thank you!

View File

@ -32,32 +32,32 @@ defmodule CanneryWeb.Component.Topbar do
space-x-4 text-lg text-white text-ellipsis"> space-x-4 text-lg text-white text-ellipsis">
<%= if @current_user do %> <%= if @current_user do %>
<li> <li>
<%= link("Tags", <%= link(gettext("Tags"),
class: "hover:underline", class: "hover:underline",
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index) to: Routes.tag_index_path(CanneryWeb.Endpoint, :index)
) %> ) %>
</li> </li>
<li> <li>
<%= link("Containers", <%= link(gettext("Containers"),
class: "hover:underline", class: "hover:underline",
to: Routes.container_index_path(CanneryWeb.Endpoint, :index) to: Routes.container_index_path(CanneryWeb.Endpoint, :index)
) %> ) %>
</li> </li>
<li> <li>
<%= link("Ammo", <%= link(gettext("Ammo"),
class: "hover:underline", class: "hover:underline",
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index) to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index)
) %> ) %>
</li> </li>
<li> <li>
<%= link("Manage", <%= link(gettext("Manage"),
class: "hover:underline", class: "hover:underline",
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index) to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index)
) %> ) %>
</li> </li>
<%= if @current_user.role == :admin do %> <%= if @current_user.role == :admin do %>
<li> <li>
<%= link("Invites", <%= link(gettext("Invites"),
class: "hover:underline", class: "hover:underline",
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index) to: Routes.invite_index_path(CanneryWeb.Endpoint, :index)
) %> ) %>
@ -72,7 +72,7 @@ defmodule CanneryWeb.Component.Topbar do
<li> <li>
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete), <%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete),
method: :delete, method: :delete,
data: [confirm: "Are you sure you want to log out?"] do %> data: [confirm: dgettext("prompts", "Are you sure you want to log out?")] do %>
<i class="fas fa-sign-out-alt"></i> <i class="fas fa-sign-out-alt"></i>
<% end %> <% end %>
</li> </li>
@ -86,14 +86,14 @@ defmodule CanneryWeb.Component.Topbar do
<% else %> <% else %>
<%= if Accounts.allow_registration?() do %> <%= if Accounts.allow_registration?() do %>
<li> <li>
<%= link("Register", <%= link(dgettext("actions", "Register"),
class: "hover:underline", class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new) to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %> ) %>
</li> </li>
<% end %> <% end %>
<li> <li>
<%= link("Log in", <%= link(dgettext("actions", "Log in"),
class: "hover:underline", class: "hover:underline",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new) to: Routes.user_session_path(CanneryWeb.Endpoint, :new)
) %> ) %>
@ -102,16 +102,6 @@ defmodule CanneryWeb.Component.Topbar do
</ul> </ul>
</div> </div>
</nav> </nav>
<%= if @flash && @flash |> Map.has_key?(:info) do %>
<p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
<%= live_flash(@flash, :info) %>
</p>
<% end %>
<%= if @flash && @flash |> Map.has_key?(:error) do %>
<p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
<%= live_flash(@flash, :error) %>
</p>
<% end %>
</header> </header>
""" """
end end

View File

@ -2,6 +2,7 @@
<header class="mb-4 px-8 py-4 w-full bg-primary-400"> <header class="mb-4 px-8 py-4 w-full bg-primary-400">
<%= render("topbar.html", assigns) %> <%= render("topbar.html", assigns) %>
</header> </header>
<div class="mx-8 my-2 flex flex-col space-y-4 text-center"> <div class="mx-8 my-2 flex flex-col space-y-4 text-center">
<%= if get_flash(@conn, :info) do %> <%= if get_flash(@conn, :info) do %>
<p class="alert alert-info" role="alert"> <p class="alert alert-info" role="alert">
@ -14,5 +15,6 @@
</p> </p>
<% end %> <% end %>
</div> </div>
<%= @inner_content %> <%= @inner_content %>
</main> </main>

View File

@ -15,6 +15,7 @@
> >
</script> </script>
</head> </head>
<body class="m-0 p-0 w-full h-full"> <body class="m-0 p-0 w-full h-full">
<%= @inner_content %> <%= @inner_content %>
</body> </body>

View File

@ -1,34 +1,42 @@
<nav role="navigation"> <nav role="navigation">
<div class="flex flex-row justify-between items-center space-x-4 overflow-x-hidden"> <div class="flex flex-row justify-between items-center space-x-4 overflow-x-hidden">
<%= link to: Routes.live_path(CanneryWeb.Endpoint, HomeLive) do %> <%= link to: Routes.live_path(CanneryWeb.Endpoint, HomeLive) do %>
<h1 class="leading-5 text-xl text-white hover:underline">Cannery</h1> <h1 class="leading-5 text-xl text-white hover:underline">
Cannery
</h1>
<% end %> <% end %>
<ul class="flex flex-col sm:flex-row flex-wrap justify-center items-center <ul class="flex flex-col sm:flex-row flex-wrap justify-center items-center
space-x-4 text-lg text-white text-ellipsis"> space-x-4 text-lg text-white text-ellipsis">
<%# user settings %>
<%= if assigns |> Map.has_key?(:current_user) && @current_user do %> <%= if assigns |> Map.has_key?(:current_user) && @current_user do %>
<li> <li>
<%= link @current_user.email, class: "hover:underline", <%= link(@current_user.email,
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit) %> class: "hover:underline",
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit)
) %>
</li> </li>
<li> <li>
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete), method: :delete, <%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete),
data: [confirm: "Are you sure you want to log out?"] do %> method: :delete,
data: [confirm: dgettext("prompts", "Are you sure you want to log out?")] do %>
<i class="fas fa-sign-out-alt"></i> <i class="fas fa-sign-out-alt"></i>
<% end %> <% end %>
</li> </li>
<% else %> <% else %>
<%= if Accounts.allow_registration?() do %> <%= if Accounts.allow_registration?() do %>
<li> <li>
<%= link "Register", class: "hover:underline", <%= link(dgettext("actions", "Register"),
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new) %> class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %>
</li> </li>
<% end %> <% end %>
<li> <li>
<%= link "Log in", class: "hover:underline", <%= link(dgettext("actions", "Log in"),
to: Routes.user_session_path(CanneryWeb.Endpoint, :new) %> class: "hover:underline",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new)
) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>

23
priv/gettext/actions.pot Normal file
View File

@ -0,0 +1,23 @@
## This file is a PO Template file.
##
## "msgid"s here are often extracted from source code.
## Add new translations manually only if they're dynamic
## translations that can't be statically extracted.
##
## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead.
msgid ""
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:96
#: lib/cannery_web/templates/layout/topbar.html.heex:36
msgid "Log in"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:89
#: lib/cannery_web/templates/layout/topbar.html.heex:28
msgid "Register"
msgstr ""

View File

@ -74,3 +74,28 @@ msgstr ""
#: lib/cannery_web/live/home_live.ex:66 #: lib/cannery_web/live/home_live.ex:66
msgid "Self-host your own instance, or use an instance from someone you trust." msgid "Self-host your own instance, or use an instance from someone you trust."
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:47
msgid "Ammo"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:41
msgid "Containers"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:60
msgid "Invites"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:53
msgid "Manage"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:35
msgid "Tags"
msgstr ""

View File

@ -14,3 +14,9 @@ msgstr ""
#: lib/cannery_web/live/home_live.ex:94 #: lib/cannery_web/live/home_live.ex:94
msgid "Register to setup %{name}" msgid "Register to setup %{name}"
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/component/topbar.ex:75
#: lib/cannery_web/templates/layout/topbar.html.heex:21
msgid "Are you sure you want to log out?"
msgstr ""