gettext User

This commit is contained in:
shibao 2022-02-08 22:13:01 -05:00
parent 20f49a9a9a
commit 455fe354c1
2 changed files with 27 additions and 4 deletions

View File

@ -5,6 +5,7 @@ defmodule Cannery.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
import CanneryWeb.Gettext
alias Ecto.{Changeset, UUID}
alias Cannery.{Accounts.User, Invites.Invite}
@ -77,7 +78,9 @@ defmodule Cannery.Accounts.User do
defp validate_email(changeset) do
changeset
|> validate_required([:email])
|> validate_format(:email, ~r/^[^\s]+@[^\s]+$/, message: "must have the @ sign and no spaces")
|> validate_format(:email, ~r/^[^\s]+@[^\s]+$/,
message: dgettext("errors", "must have the @ sign and no spaces")
)
|> validate_length(:email, max: 160)
|> unsafe_validate_unique(:email, Cannery.Repo)
|> unique_constraint(:email)
@ -122,7 +125,7 @@ defmodule Cannery.Accounts.User do
|> validate_email()
|> case do
%{changes: %{email: _}} = changeset -> changeset
%{} = changeset -> add_error(changeset, :email, "did not change")
%{} = changeset -> add_error(changeset, :email, dgettext("errors", "did not change"))
end
end
@ -143,7 +146,7 @@ defmodule Cannery.Accounts.User do
def password_changeset(user, attrs, opts \\ []) do
user
|> cast(attrs, [:password])
|> validate_confirmation(:password, message: "does not match password")
|> validate_confirmation(:password, message: dgettext("errors", "does not match password"))
|> validate_password(opts)
end
@ -180,6 +183,6 @@ defmodule Cannery.Accounts.User do
def validate_current_password(changeset, password) do
if valid_password?(changeset.data, password),
do: changeset,
else: changeset |> add_error(:current_password, "is not valid")
else: changeset |> add_error(:current_password, dgettext("errors", "is not valid"))
end
end

View File

@ -99,3 +99,23 @@ msgid "There is still %{amount} ammo group in this container!"
msgid_plural "There are still %{amount} ammo groups in this container!"
msgstr[0] ""
msgstr[1] ""
#, elixir-format, ex-autogen
#: lib/cannery/accounts/user.ex:128
msgid "did not change"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery/accounts/user.ex:149
msgid "does not match password"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery/accounts/user.ex:186
msgid "is not valid"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery/accounts/user.ex:82
msgid "must have the @ sign and no spaces"
msgstr ""