From b0bba8ccb53a01346dca824f5be953bdebf8e7b9 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 1 Oct 2019 13:08:09 +0200 Subject: [PATCH] Save user locale and use it to translate things Signed-off-by: Thomas Citharel --- lib/mobilizon/users/user.ex | 5 +++- lib/mobilizon/users/users.ex | 2 +- lib/mobilizon_web/email/admin.ex | 2 +- lib/mobilizon_web/email/event.ex | 2 +- lib/mobilizon_web/email/participation.ex | 4 ++-- lib/mobilizon_web/email/user.ex | 4 ++-- lib/mobilizon_web/gettext.ex | 23 +++++++++++++++++++ lib/mobilizon_web/resolvers/user.ex | 16 +++++++------ lib/mobilizon_web/schema/user.ex | 7 ++++-- .../templates/email/event_updated.html.eex | 4 ++-- .../templates/email/event_updated.text.eex | 4 ++-- .../templates/email/password_reset.html.eex | 2 +- .../templates/email/password_reset.text.eex | 2 +- lib/mobilizon_web/views/email_view.ex | 2 ++ lib/service/events/tools.ex | 4 ++-- priv/gettext/cs/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/de/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/default.pot | 16 +++++-------- priv/gettext/en/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/es/LC_MESSAGES/default.po | 16 +++++-------- .../{fr_FR => fr}/LC_MESSAGES/default.po | 18 ++++++--------- .../{fr_FR => fr}/LC_MESSAGES/errors.po | 0 priv/gettext/it/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/ja/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/nl/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/oc/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/pl/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/pt/LC_MESSAGES/default.po | 16 +++++-------- priv/gettext/ru/LC_MESSAGES/default.po | 16 +++++-------- .../20191001074442_add_locale_to_users.exs | 9 ++++++++ .../resolvers/user_resolver_test.exs | 10 +++++++- 31 files changed, 155 insertions(+), 157 deletions(-) rename priv/gettext/{fr_FR => fr}/LC_MESSAGES/default.po (97%) rename priv/gettext/{fr_FR => fr}/LC_MESSAGES/errors.po (100%) create mode 100644 priv/repo/migrations/20191001074442_add_locale_to_users.exs diff --git a/lib/mobilizon/users/user.ex b/lib/mobilizon/users/user.ex index 08bd65dc3..be77498ab 100644 --- a/lib/mobilizon/users/user.ex +++ b/lib/mobilizon/users/user.ex @@ -23,6 +23,7 @@ defmodule Mobilizon.Users.User do confirmation_token: String.t(), reset_password_sent_at: DateTime.t(), reset_password_token: String.t(), + locale: String.t(), default_actor: Actor.t(), actors: [Actor.t()], feed_tokens: [FeedToken.t()] @@ -37,7 +38,8 @@ defmodule Mobilizon.Users.User do :confirmation_sent_at, :confirmation_token, :reset_password_sent_at, - :reset_password_token + :reset_password_token, + :locale ] @attrs @required_attrs ++ @optional_attrs @@ -59,6 +61,7 @@ defmodule Mobilizon.Users.User do field(:confirmation_token, :string) field(:reset_password_sent_at, :utc_datetime) field(:reset_password_token, :string) + field(:locale, :string, default: "en") belongs_to(:default_actor, Actor) has_many(:actors, Actor) diff --git a/lib/mobilizon/users/users.ex b/lib/mobilizon/users/users.ex index 2fe784980..802dc42b2 100644 --- a/lib/mobilizon/users/users.ex +++ b/lib/mobilizon/users/users.ex @@ -24,7 +24,7 @@ defmodule Mobilizon.Users do Registers an user. """ @spec register(map) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()} - def register(%{email: _email, password: _password} = args) do + def register(args) do with {:ok, %User{} = user} <- %User{} |> User.registration_changeset(args) diff --git a/lib/mobilizon_web/email/admin.ex b/lib/mobilizon_web/email/admin.ex index 603511307..0f78db66f 100644 --- a/lib/mobilizon_web/email/admin.ex +++ b/lib/mobilizon_web/email/admin.ex @@ -17,7 +17,7 @@ defmodule MobilizonWeb.Email.Admin do @spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t() def report(%User{email: email}, %Report{} = report, locale \\ "en") do - Gettext.put_locale(locale) + MobilizonWeb.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/email/event.ex b/lib/mobilizon_web/email/event.ex index c1e55077e..a568521a0 100644 --- a/lib/mobilizon_web/email/event.ex +++ b/lib/mobilizon_web/email/event.ex @@ -24,7 +24,7 @@ defmodule MobilizonWeb.Email.Event do changes, locale \\ "en" ) do - Gettext.put_locale(locale) + MobilizonWeb.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/email/participation.ex b/lib/mobilizon_web/email/participation.ex index 6029349fb..4bf40066f 100644 --- a/lib/mobilizon_web/email/participation.ex +++ b/lib/mobilizon_web/email/participation.ex @@ -46,7 +46,7 @@ defmodule MobilizonWeb.Email.Participation do %Participant{event: event, role: :rejected}, locale ) do - Gettext.put_locale(locale) + MobilizonWeb.Gettext.put_locale(locale) subject = gettext( @@ -67,7 +67,7 @@ defmodule MobilizonWeb.Email.Participation do %Participant{event: event, role: :participant}, locale ) do - Gettext.put_locale(locale) + MobilizonWeb.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/email/user.ex b/lib/mobilizon_web/email/user.ex index 6476e6989..b331e8951 100644 --- a/lib/mobilizon_web/email/user.ex +++ b/lib/mobilizon_web/email/user.ex @@ -19,7 +19,7 @@ defmodule MobilizonWeb.Email.User do %User{email: email, confirmation_token: confirmation_token}, locale \\ "en" ) do - Gettext.put_locale(locale) + MobilizonWeb.Gettext.put_locale(locale) subject = gettext( @@ -39,7 +39,7 @@ defmodule MobilizonWeb.Email.User do %User{email: email, reset_password_token: reset_password_token}, locale \\ "en" ) do - Gettext.put_locale(locale) + MobilizonWeb.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/gettext.ex b/lib/mobilizon_web/gettext.ex index 25a7544e4..e6880ae86 100644 --- a/lib/mobilizon_web/gettext.ex +++ b/lib/mobilizon_web/gettext.ex @@ -21,4 +21,27 @@ defmodule MobilizonWeb.Gettext do See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. """ use Gettext, otp_app: :mobilizon + + def put_locale(locale) do + locale = determine_best_locale(locale) + Gettext.put_locale(MobilizonWeb.Gettext, locale) + end + + @spec determine_best_locale(String.t()) :: String.t() + def determine_best_locale(locale) do + locale = String.trim(locale) + locales = Gettext.known_locales(MobilizonWeb.Gettext) + + cond do + # Either it matches directly, eg: "en" => "en", "fr" => "fr", "fr_FR" => "fr_FR" + locale in locales -> locale + # Either the first part matches, "fr_CA" => "fr" + split_locale(locale) in locales -> split_locale(locale) + # Otherwise default to english + true -> "en" + end + end + + # Keep only the first part of the locale + defp split_locale(locale), do: locale |> String.split("_", trim: true, parts: 2) |> hd end diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/mobilizon_web/resolvers/user.ex index 6d765e5e0..613b7dde2 100644 --- a/lib/mobilizon_web/resolvers/user.ex +++ b/lib/mobilizon_web/resolvers/user.ex @@ -116,7 +116,7 @@ defmodule MobilizonWeb.Resolvers.User do with {:registrations_open, true} <- {:registrations_open, Config.instance_registrations_open?()}, {:ok, %User{} = user} <- Users.register(args) do - Activation.send_confirmation_email(user) + Activation.send_confirmation_email(user, Map.get(args, :locale, "en")) {:ok, user} else {:registrations_open, false} -> @@ -154,10 +154,11 @@ defmodule MobilizonWeb.Resolvers.User do Send the confirmation email again. We only do this to accounts unconfirmed """ - def resend_confirmation_email(_parent, %{email: email, locale: locale}, _resolution) do - with {:ok, user} <- Users.get_user_by_email(email, false), + def resend_confirmation_email(_parent, args, _resolution) do + with {:ok, %User{locale: locale} = user} <- + Users.get_user_by_email(Map.get(args, :email), false), {:ok, email} <- - Activation.resend_confirmation_email(user, locale) do + Activation.resend_confirmation_email(user, Map.get(args, :locale, locale)) do {:ok, email} else {:error, :user_not_found} -> @@ -171,10 +172,11 @@ defmodule MobilizonWeb.Resolvers.User do @doc """ Send an email to reset the password from an user """ - def send_reset_password(_parent, %{email: email, locale: locale}, _resolution) do - with {:ok, user} <- Users.get_user_by_email(email, true), + def send_reset_password(_parent, args, _resolution) do + with email <- Map.get(args, :email), + {:ok, %User{locale: locale} = user} <- Users.get_user_by_email(email, true), {:ok, %Bamboo.Email{} = _email_html} <- - ResetPassword.send_password_reset_email(user, locale) do + ResetPassword.send_password_reset_email(user, Map.get(args, :locale, locale)) do {:ok, email} else {:error, :user_not_found} -> diff --git a/lib/mobilizon_web/schema/user.ex b/lib/mobilizon_web/schema/user.ex index d02aa6457..fc3021d3b 100644 --- a/lib/mobilizon_web/schema/user.ex +++ b/lib/mobilizon_web/schema/user.ex @@ -46,6 +46,8 @@ defmodule MobilizonWeb.Schema.UserType do field(:role, :user_role, description: "The role for the user") + field(:locale, :string, description: "The user's locale") + field(:participations, list_of(:participant), description: "The list of events this user goes to" ) do @@ -109,6 +111,7 @@ defmodule MobilizonWeb.Schema.UserType do field :create_user, type: :user do arg(:email, non_null(:string)) arg(:password, non_null(:string)) + arg(:locale, :string) resolve(handle_errors(&User.create_user/3)) end @@ -122,14 +125,14 @@ defmodule MobilizonWeb.Schema.UserType do @desc "Resend registration confirmation token" field :resend_confirmation_email, type: :string do arg(:email, non_null(:string)) - arg(:locale, :string, default_value: "en") + arg(:locale, :string) resolve(&User.resend_confirmation_email/3) end @desc "Send a link through email to reset user password" field :send_reset_password, type: :string do arg(:email, non_null(:string)) - arg(:locale, :string, default_value: "en") + arg(:locale, :string) resolve(&User.send_reset_password/3) end diff --git a/lib/mobilizon_web/templates/email/event_updated.html.eex b/lib/mobilizon_web/templates/email/event_updated.html.eex index 553dfe526..eb2ff8fd3 100644 --- a/lib/mobilizon_web/templates/email/event_updated.html.eex +++ b/lib/mobilizon_web/templates/email/event_updated.html.eex @@ -58,7 +58,7 @@ <%= gettext "Start of event" %> - <%= datetime_to_string(@event.begins_on) %> + <%= datetime_to_string(@event.begins_on, @locale) %> <% end %> @@ -68,7 +68,7 @@ <%= gettext "Ending of event" %> - <%= datetime_to_string(@event.ends_on) %> + <%= datetime_to_string(@event.ends_on, @locale) %> <% end %> diff --git a/lib/mobilizon_web/templates/email/event_updated.text.eex b/lib/mobilizon_web/templates/email/event_updated.text.eex index f7b393395..31a64c918 100644 --- a/lib/mobilizon_web/templates/email/event_updated.text.eex +++ b/lib/mobilizon_web/templates/email/event_updated.text.eex @@ -9,11 +9,11 @@ <% end %> <%= if MapSet.member?(@changes, :begins_on) do %> - <%= gettext "New date and time for start of event: %{begins_on}", begins_on: datetime_to_string(@event.begins_on) %> + <%= gettext "New date and time for start of event: %{begins_on}", begins_on: datetime_to_string(@event.begins_on, @locale) %> <% end %> <%= if MapSet.member?(@changes, :ends_on) do %> - <%= gettext "New date and time for ending of event: %{ends_on}", ends_on: datetime_to_string(@event.ends_on) %> + <%= gettext "New date and time for ending of event: %{ends_on}", ends_on: datetime_to_string(@event.ends_on, @locale) %> <% end %> <%= gettext "View the updated event on: %{link}", link: page_url(MobilizonWeb.Endpoint, :event, @event.id) %> diff --git a/lib/mobilizon_web/templates/email/password_reset.html.eex b/lib/mobilizon_web/templates/email/password_reset.html.eex index 6f3d000af..f66691484 100644 --- a/lib/mobilizon_web/templates/email/password_reset.html.eex +++ b/lib/mobilizon_web/templates/email/password_reset.html.eex @@ -35,7 +35,7 @@

- <%= gettext "You requested a new password for your account on %{server}.", server: @instance[:name] %> + <%= gettext "You requested a new password for your account on %{instance}.", instance: @instance[:name] %>

<%= gettext "Resetting your password is easy. Just press the button below and follow the instructions. We'll have you up and running in no time." %> diff --git a/lib/mobilizon_web/templates/email/password_reset.text.eex b/lib/mobilizon_web/templates/email/password_reset.text.eex index 51268a127..58a4aacd3 100644 --- a/lib/mobilizon_web/templates/email/password_reset.text.eex +++ b/lib/mobilizon_web/templates/email/password_reset.text.eex @@ -2,7 +2,7 @@ == -<%= gettext "You requested a new password for your account on %{host}.", host: @instance[:name] %> +<%= gettext "You requested a new password for your account on %{instance}.", instance: @instance[:name] %> <%= gettext "Resetting your password is easy. Just click the link below and follow the instructions. We'll have you up and running in no time." %> diff --git a/lib/mobilizon_web/views/email_view.ex b/lib/mobilizon_web/views/email_view.ex index 2c911cb45..a65d3ce5e 100644 --- a/lib/mobilizon_web/views/email_view.ex +++ b/lib/mobilizon_web/views/email_view.ex @@ -1,6 +1,8 @@ defmodule MobilizonWeb.EmailView do use MobilizonWeb, :view + import MobilizonWeb.Gettext + def datetime_to_string(%DateTime{} = datetime, locale \\ "en") do with {:ok, string} <- Cldr.DateTime.to_string(datetime, Mobilizon.Cldr, format: :medium, locale: locale) do diff --git a/lib/service/events/tools.ex b/lib/service/events/tools.ex index dc8efef8e..902e6ce54 100644 --- a/lib/service/events/tools.ex +++ b/lib/service/events/tools.ex @@ -38,13 +38,13 @@ defmodule Mobilizon.Service.Events.Tool do end defp send_notification_for_event_update_to_participant( - {%Actor{} = actor, %User{} = user}, + {%Actor{} = actor, %User{locale: locale} = user}, %Event{} = old_event, %Event{} = event, diff ) do user - |> Email.Event.event_updated(actor, old_event, event, diff) + |> Email.Event.event_updated(actor, old_event, event, diff, locale) |> Email.Mailer.deliver_later() end end diff --git a/priv/gettext/cs/LC_MESSAGES/default.po b/priv/gettext/cs/LC_MESSAGES/default.po index ad4115407..d8c6e77f2 100644 --- a/priv/gettext/cs/LC_MESSAGES/default.po +++ b/priv/gettext/cs/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index e0e7f0286..6a6081c27 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index f4b50c1eb..8b6c7d1ad 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -108,11 +108,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -203,11 +198,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -285,3 +275,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 506cdaaef..8de59e581 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -134,11 +134,6 @@ msgstr "" "You created an account on %{host} with this email address. You are one click " "away from activating it." -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "You requested a new password for your account on %{server}." - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -239,11 +234,6 @@ msgstr "" "You created an account on %{host} with this email address. You are one click " "away from activating it." -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "You requested a new password for your account on %{server}." - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -321,3 +311,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "Your participation to event %{title} has been rejected" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "You requested a new password for your account on %{instance}." diff --git a/priv/gettext/es/LC_MESSAGES/default.po b/priv/gettext/es/LC_MESSAGES/default.po index f42f9d3c3..a2be30f64 100644 --- a/priv/gettext/es/LC_MESSAGES/default.po +++ b/priv/gettext/es/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/fr_FR/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po similarity index 97% rename from priv/gettext/fr_FR/LC_MESSAGES/default.po rename to priv/gettext/fr/LC_MESSAGES/default.po index f927185cd..d1ad8a06e 100644 --- a/priv/gettext/fr_FR/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -13,7 +13,7 @@ msgstr "" "PO-Revision-Date: 2019-09-30 17:10+0000\n" "Last-Translator: Thomas Citharel \n" "Language-Team: French \n" -"Language: fr_FR\n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -130,11 +130,6 @@ msgstr "Voir le signalement" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "Vous avez créé un compte sur %{host} avec cette adresse email. Vous êtes à un clic de l'activer." -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "Vous avez demandé un nouveau mot de passe pour votre compte sur %{server}." - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -234,11 +229,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "Vous avez créé un compte sur %{host} avec cette adresse email. Vous êtes à un clic de l'activer." -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "Vous avez demandé un nouveau mot de passe pour votre compte sur %{server}." - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -316,3 +306,9 @@ msgstr "Titre" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "Voir l'événement mis à jour sur : %{link}" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "Vous avez demandé un nouveau mot de passe pour votre compte sur %{instance}." diff --git a/priv/gettext/fr_FR/LC_MESSAGES/errors.po b/priv/gettext/fr/LC_MESSAGES/errors.po similarity index 100% rename from priv/gettext/fr_FR/LC_MESSAGES/errors.po rename to priv/gettext/fr/LC_MESSAGES/errors.po diff --git a/priv/gettext/it/LC_MESSAGES/default.po b/priv/gettext/it/LC_MESSAGES/default.po index 5b5d3dd37..f6e1f838a 100644 --- a/priv/gettext/it/LC_MESSAGES/default.po +++ b/priv/gettext/it/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/ja/LC_MESSAGES/default.po b/priv/gettext/ja/LC_MESSAGES/default.po index 66424dbab..0727e1803 100644 --- a/priv/gettext/ja/LC_MESSAGES/default.po +++ b/priv/gettext/ja/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/nl/LC_MESSAGES/default.po b/priv/gettext/nl/LC_MESSAGES/default.po index 011be229e..2718f3c4e 100644 --- a/priv/gettext/nl/LC_MESSAGES/default.po +++ b/priv/gettext/nl/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/oc/LC_MESSAGES/default.po b/priv/gettext/oc/LC_MESSAGES/default.po index 6bf2192ae..239b8ffa3 100644 --- a/priv/gettext/oc/LC_MESSAGES/default.po +++ b/priv/gettext/oc/LC_MESSAGES/default.po @@ -132,11 +132,6 @@ msgstr "" "Avètz creat un compte sus %{host} amb aquesta adreça electronica. Sètz a un " "clic de l’activar." -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "Avètz demandat un nòu senhal per vòstre compte sus %{server}." - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -231,11 +226,6 @@ msgstr "" "Avètz creat un compte sus %{host} amb aquesta adreça electronica. Sètz a un " "clic de l’activar." -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "Avètz demandat un nòu senhal per vòstre compte sus %{server}." - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -313,3 +303,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "Avètz demandat un nòu senhal per vòstre compte sus %{instance}." diff --git a/priv/gettext/pl/LC_MESSAGES/default.po b/priv/gettext/pl/LC_MESSAGES/default.po index 31bd9c749..2b1267a0e 100644 --- a/priv/gettext/pl/LC_MESSAGES/default.po +++ b/priv/gettext/pl/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/pt/LC_MESSAGES/default.po b/priv/gettext/pt/LC_MESSAGES/default.po index e29555fe7..140b2cf02 100644 --- a/priv/gettext/pt/LC_MESSAGES/default.po +++ b/priv/gettext/pt/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/gettext/ru/LC_MESSAGES/default.po b/priv/gettext/ru/LC_MESSAGES/default.po index 2cc3a51e8..22bc3d09d 100644 --- a/priv/gettext/ru/LC_MESSAGES/default.po +++ b/priv/gettext/ru/LC_MESSAGES/default.po @@ -122,11 +122,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 -msgid "You requested a new password for your account on %{server}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/email/user.ex:25 msgid "Instructions to confirm your Mobilizon account on %{instance}" @@ -217,11 +212,6 @@ msgstr "" msgid "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email." msgstr "" -#, elixir-format -#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 -msgid "You requested a new password for your account on %{host}." -msgstr "" - #, elixir-format #: lib/mobilizon_web/templates/email/event_participation_approved.html.eex:38 msgid "You requested to participate in event %{title}" @@ -299,3 +289,9 @@ msgstr "" #: lib/mobilizon_web/templates/email/event_updated.text.eex:19 msgid "View the updated event on: %{link}" msgstr "" + +#, elixir-format, fuzzy +#: lib/mobilizon_web/templates/email/password_reset.html.eex:38 +#: lib/mobilizon_web/templates/email/password_reset.text.eex:5 +msgid "You requested a new password for your account on %{instance}." +msgstr "" diff --git a/priv/repo/migrations/20191001074442_add_locale_to_users.exs b/priv/repo/migrations/20191001074442_add_locale_to_users.exs new file mode 100644 index 000000000..da3ae8b26 --- /dev/null +++ b/priv/repo/migrations/20191001074442_add_locale_to_users.exs @@ -0,0 +1,9 @@ +defmodule Mobilizon.Storage.Repo.Migrations.AddLocaleToUsers do + use Ecto.Migration + + def change do + alter table(:users) do + add(:locale, :string, default: "en") + end + end +end diff --git a/test/mobilizon_web/resolvers/user_resolver_test.exs b/test/mobilizon_web/resolvers/user_resolver_test.exs index e6324d651..701cb44f8 100644 --- a/test/mobilizon_web/resolvers/user_resolver_test.exs +++ b/test/mobilizon_web/resolvers/user_resolver_test.exs @@ -220,6 +220,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do @user_creation %{ email: "test@demo.tld", password: "long password", + locale: "fr_FR", username: "toto", name: "Sir Toto", summary: "Sir Toto, prince of the functional tests" @@ -236,9 +237,11 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do createUser( email: "#{@user_creation.email}", password: "#{@user_creation.password}", + locale: "#{@user_creation.locale}" ) { id, - email + email, + locale } } """ @@ -248,6 +251,11 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) assert json_response(res, 200)["data"]["createUser"]["email"] == @user_creation.email + assert json_response(res, 200)["data"]["createUser"]["locale"] == @user_creation.locale + + {:ok, user} = Users.get_user_by_email(@user_creation.email) + + assert_delivered_email(Email.User.confirmation_email(user, @user_creation.locale)) mutation = """ mutation {