forked from shibao/cannery
gettext controllers
This commit is contained in:
parent
9972299fc4
commit
3675d0b4f4
@ -41,9 +41,11 @@ 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"` (as a
|
- Existing domains: `"default"` (for anything general), `"prompts"`
|
||||||
result of the user doing an action), `"actions"` (actions that the user can
|
(informational messages as a result of the user doing an action, i.e. in
|
||||||
take), `"emails"`, and `"errors"`
|
flashes), `"actions"` (actions that the user can take), `"emails"`, and
|
||||||
|
`"errors"`. Using these domains accurately will let translators know which
|
||||||
|
messages are higher and lower priority. Thank you!
|
||||||
- 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!
|
||||||
|
@ -5,7 +5,7 @@ defmodule CanneryWeb.UserAuth do
|
|||||||
|
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
import Phoenix.Controller
|
import Phoenix.Controller
|
||||||
|
import CanneryWeb.Gettext
|
||||||
alias Cannery.Accounts
|
alias Cannery.Accounts
|
||||||
alias CanneryWeb.HomeLive
|
alias CanneryWeb.HomeLive
|
||||||
alias CanneryWeb.Router.Helpers, as: Routes
|
alias CanneryWeb.Router.Helpers, as: Routes
|
||||||
@ -142,7 +142,7 @@ defmodule CanneryWeb.UserAuth do
|
|||||||
conn
|
conn
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "You must log in to access this page.")
|
|> put_flash(:error, dgettext("errors", "You must log in to access this page."))
|
||||||
|> maybe_store_return_to()
|
|> maybe_store_return_to()
|
||||||
|> redirect(to: Routes.user_session_path(conn, :new))
|
|> redirect(to: Routes.user_session_path(conn, :new))
|
||||||
|> halt()
|
|> halt()
|
||||||
@ -157,7 +157,7 @@ defmodule CanneryWeb.UserAuth do
|
|||||||
conn
|
conn
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "You are not authorized to view this page.")
|
|> put_flash(:error, dgettext("errors", "You are not authorized to view this page."))
|
||||||
|> maybe_store_return_to()
|
|> maybe_store_return_to()
|
||||||
|> redirect(to: Routes.live_path(conn, HomeLive))
|
|> redirect(to: Routes.live_path(conn, HomeLive))
|
||||||
|> halt()
|
|> halt()
|
||||||
|
@ -19,8 +19,11 @@ defmodule CanneryWeb.UserConfirmationController do
|
|||||||
conn
|
conn
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:info,
|
:info,
|
||||||
"If your email is in our system and it has not been confirmed yet, " <>
|
dgettext(
|
||||||
"you will receive an email with instructions shortly."
|
"prompts",
|
||||||
|
"If your email is in our system and it has not been confirmed yet, " <>
|
||||||
|
"you will receive an email with instructions shortly."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
end
|
end
|
||||||
@ -31,7 +34,7 @@ defmodule CanneryWeb.UserConfirmationController do
|
|||||||
case Accounts.confirm_user(token) do
|
case Accounts.confirm_user(token) do
|
||||||
{:ok, _} ->
|
{:ok, _} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "User confirmed successfully.")
|
|> put_flash(:info, dgettext("prompts", "User confirmed successfully."))
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
|
|
||||||
:error ->
|
:error ->
|
||||||
@ -45,7 +48,10 @@ defmodule CanneryWeb.UserConfirmationController do
|
|||||||
|
|
||||||
%{} ->
|
%{} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "User confirmation link is invalid or it has expired.")
|
|> put_flash(
|
||||||
|
:error,
|
||||||
|
dgettext("errors", "User confirmation link is invalid or it has expired.")
|
||||||
|
)
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
defmodule CanneryWeb.UserRegistrationController do
|
defmodule CanneryWeb.UserRegistrationController do
|
||||||
use CanneryWeb, :controller
|
use CanneryWeb, :controller
|
||||||
|
import CanneryWeb.Gettext
|
||||||
alias Cannery.{Accounts, Invites}
|
alias Cannery.{Accounts, Invites}
|
||||||
alias Cannery.Accounts.User
|
alias Cannery.Accounts.User
|
||||||
alias CanneryWeb.{HomeLive, UserAuth}
|
alias CanneryWeb.{HomeLive, UserAuth}
|
||||||
@ -12,7 +12,7 @@ defmodule CanneryWeb.UserRegistrationController do
|
|||||||
conn |> render_new(invite)
|
conn |> render_new(invite)
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Sorry, this invite was not found or expired")
|
|> put_flash(:error, dgettext("errors", "Sorry, this invite was not found or expired"))
|
||||||
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -22,7 +22,7 @@ defmodule CanneryWeb.UserRegistrationController do
|
|||||||
conn |> render_new()
|
conn |> render_new()
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Sorry, public registration is disabled")
|
|> put_flash(:error, dgettext("errors", "Sorry, public registration is disabled"))
|
||||||
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -40,7 +40,7 @@ defmodule CanneryWeb.UserRegistrationController do
|
|||||||
conn |> create_user(attrs, invite)
|
conn |> create_user(attrs, invite)
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Sorry, this invite was not found or expired")
|
|> put_flash(:error, dgettext("errors", "Sorry, this invite was not found or expired"))
|
||||||
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -50,7 +50,7 @@ defmodule CanneryWeb.UserRegistrationController do
|
|||||||
conn |> create_user(attrs)
|
conn |> create_user(attrs)
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Sorry, public registration is disabled")
|
|> put_flash(:error, dgettext("errors", "Sorry, public registration is disabled"))
|
||||||
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
|> redirect(to: Routes.live_path(CanneryWeb.Endpoint, HomeLive))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -69,7 +69,7 @@ defmodule CanneryWeb.UserRegistrationController do
|
|||||||
)
|
)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "User created successfully.")
|
|> put_flash(:info, dgettext("prompts", "User created successfully."))
|
||||||
|> UserAuth.log_in_user(user)
|
|> UserAuth.log_in_user(user)
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
@ -21,7 +21,11 @@ defmodule CanneryWeb.UserResetPasswordController do
|
|||||||
conn
|
conn
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:info,
|
:info,
|
||||||
"If your email is in our system, you will receive instructions to reset your password shortly."
|
dgettext(
|
||||||
|
"prompts",
|
||||||
|
"If your email is in our system, you will receive instructions to " <>
|
||||||
|
"reset your password shortly."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
end
|
end
|
||||||
@ -36,7 +40,7 @@ defmodule CanneryWeb.UserResetPasswordController do
|
|||||||
case Accounts.reset_user_password(conn.assigns.user, user_params) do
|
case Accounts.reset_user_password(conn.assigns.user, user_params) do
|
||||||
{:ok, _} ->
|
{:ok, _} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Password reset successfully.")
|
|> put_flash(:info, dgettext("prompts", "Password reset successfully."))
|
||||||
|> redirect(to: Routes.user_session_path(conn, :new))
|
|> redirect(to: Routes.user_session_path(conn, :new))
|
||||||
|
|
||||||
{:error, changeset} ->
|
{:error, changeset} ->
|
||||||
@ -51,7 +55,10 @@ defmodule CanneryWeb.UserResetPasswordController do
|
|||||||
conn |> assign(:user, user) |> assign(:token, token)
|
conn |> assign(:user, user) |> assign(:token, token)
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Reset password link is invalid or it has expired.")
|
|> put_flash(
|
||||||
|
:error,
|
||||||
|
dgettext("errors", "Reset password link is invalid or it has expired.")
|
||||||
|
)
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
|> halt()
|
|> halt()
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ defmodule CanneryWeb.UserSessionController do
|
|||||||
|
|
||||||
def delete(conn, _params) do
|
def delete(conn, _params) do
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, gettext("Logged out successfully."))
|
|> put_flash(:info, dgettext("prompts", "Logged out successfully."))
|
||||||
|> UserAuth.log_out_user()
|
|> UserAuth.log_out_user()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,10 @@ defmodule CanneryWeb.UserSettingsController do
|
|||||||
conn
|
conn
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:info,
|
:info,
|
||||||
"A link to confirm your email change has been sent to the new address."
|
dgettext(
|
||||||
|
"prompts",
|
||||||
|
"A link to confirm your email change has been sent to the new address."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
||||||
|
|
||||||
@ -41,7 +44,7 @@ defmodule CanneryWeb.UserSettingsController do
|
|||||||
case Accounts.update_user_password(user, password, user_params) do
|
case Accounts.update_user_password(user, password, user_params) do
|
||||||
{:ok, user} ->
|
{:ok, user} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Password updated successfully.")
|
|> put_flash(:info, dgettext("prompts", "Password updated successfully."))
|
||||||
|> put_session(:user_return_to, Routes.user_settings_path(conn, :edit))
|
|> put_session(:user_return_to, Routes.user_settings_path(conn, :edit))
|
||||||
|> UserAuth.log_in_user(user)
|
|> UserAuth.log_in_user(user)
|
||||||
|
|
||||||
@ -54,12 +57,15 @@ defmodule CanneryWeb.UserSettingsController do
|
|||||||
case Accounts.update_user_email(conn.assigns.current_user, token) do
|
case Accounts.update_user_email(conn.assigns.current_user, token) do
|
||||||
:ok ->
|
:ok ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Email changed successfully.")
|
|> put_flash(:info, dgettext("prompts", "Email changed successfully."))
|
||||||
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
||||||
|
|
||||||
:error ->
|
:error ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Email change link is invalid or it has expired.")
|
|> put_flash(
|
||||||
|
:error,
|
||||||
|
dgettext("errors", "Email change link is invalid or it has expired.")
|
||||||
|
)
|
||||||
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -69,11 +75,11 @@ defmodule CanneryWeb.UserSettingsController do
|
|||||||
Accounts.delete_user!(conn.assigns.current_user)
|
Accounts.delete_user!(conn.assigns.current_user)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Your account has been deleted")
|
|> put_flash(:error, dgettext("prompts", "Your account has been deleted"))
|
||||||
|> redirect(to: Routes.live_path(conn, HomeLive))
|
|> redirect(to: Routes.live_path(conn, HomeLive))
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Unable to delete user")
|
|> put_flash(:error, dgettext("errors", "Unable to delete user"))
|
||||||
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -109,8 +109,3 @@ msgstr ""
|
|||||||
#: lib/cannery_web/templates/user_settings/edit.html.heex:3
|
#: lib/cannery_web/templates/user_settings/edit.html.heex:3
|
||||||
msgid "Settings"
|
msgid "Settings"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#, elixir-format, ex-autogen
|
|
||||||
#: lib/cannery_web/controllers/user_session_controller.ex:23
|
|
||||||
msgid "Logged out successfully."
|
|
||||||
msgstr ""
|
|
||||||
|
@ -157,3 +157,45 @@ msgstr ""
|
|||||||
#: lib/cannery_web/controllers/user_session_controller.ex:17
|
#: lib/cannery_web/controllers/user_session_controller.ex:17
|
||||||
msgid "Invalid email or password"
|
msgid "Invalid email or password"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_settings_controller.ex:67
|
||||||
|
msgid "Email change link is invalid or it has expired."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_reset_password_controller.ex:60
|
||||||
|
msgid "Reset password link is invalid or it has expired."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_registration_controller.ex:25
|
||||||
|
#: lib/cannery_web/controllers/user_registration_controller.ex:53
|
||||||
|
msgid "Sorry, public registration is disabled"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_registration_controller.ex:15
|
||||||
|
#: lib/cannery_web/controllers/user_registration_controller.ex:43
|
||||||
|
msgid "Sorry, this invite was not found or expired"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_settings_controller.ex:82
|
||||||
|
msgid "Unable to delete user"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_confirmation_controller.ex:53
|
||||||
|
msgid "User confirmation link is invalid or it has expired."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_auth.ex:160
|
||||||
|
msgid "You are not authorized to view this page."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_auth.ex:145
|
||||||
|
msgid "You must log in to access this page."
|
||||||
|
msgstr ""
|
||||||
|
@ -25,3 +25,53 @@ msgstr ""
|
|||||||
#: lib/cannery_web/templates/user_settings/edit.html.heex:104
|
#: lib/cannery_web/templates/user_settings/edit.html.heex:104
|
||||||
msgid "Are you sure you want to delete your account?"
|
msgid "Are you sure you want to delete your account?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_settings_controller.ex:28
|
||||||
|
msgid "A link to confirm your email change has been sent to the new address."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_settings_controller.ex:60
|
||||||
|
msgid "Email changed successfully."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_confirmation_controller.ex:22
|
||||||
|
msgid "If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_reset_password_controller.ex:24
|
||||||
|
msgid "If your email is in our system, you will receive instructions to reset your password shortly."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_session_controller.ex:23
|
||||||
|
msgid "Logged out successfully."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_reset_password_controller.ex:43
|
||||||
|
msgid "Password reset successfully."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_settings_controller.ex:47
|
||||||
|
msgid "Password updated successfully."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_confirmation_controller.ex:37
|
||||||
|
msgid "User confirmed successfully."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_registration_controller.ex:72
|
||||||
|
msgid "User created successfully."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#, elixir-format, ex-autogen
|
||||||
|
#: lib/cannery_web/controllers/user_settings_controller.ex:78
|
||||||
|
msgid "Your account has been deleted"
|
||||||
|
msgstr ""
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
defmodule CanneryWeb.ErrorViewTest do
|
defmodule CanneryWeb.ErrorViewTest do
|
||||||
use CanneryWeb.ConnCase, async: true
|
use CanneryWeb.ConnCase, async: true
|
||||||
|
import CanneryWeb.Gettext
|
||||||
|
|
||||||
# Bring render/3 and render_to_string/3 for testing custom views
|
# Bring render/3 and render_to_string/3 for testing custom views
|
||||||
import Phoenix.View
|
import Phoenix.View
|
||||||
|
|
||||||
test "renders 404.html" do
|
test "renders 404.html" do
|
||||||
assert render_to_string(CanneryWeb.ErrorView, "404.html", []) == "Not Found"
|
assert render_to_string(CanneryWeb.ErrorView, "404.html", []) ==
|
||||||
|
dgettext("errors", "Not Found")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders 500.html" do
|
test "renders 500.html" do
|
||||||
assert render_to_string(CanneryWeb.ErrorView, "500.html", []) == "Internal Server Error"
|
assert render_to_string(CanneryWeb.ErrorView, "500.html", []) ==
|
||||||
|
dgettext("errors", "Internal Server Error")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user