Skip to content


Subversion checkout URL

You can clone with
Download ZIP


internationalized body of mailers #1989

wants to merge 4 commits into from

5 participants


added translation capability to body of mails sent for the instructions.
(error messages are pretty much translated although html views (hn or buttons) and mails body have not yet)


Thank you so much for the pull request.

Yes this seems useful, but we think that this is an unnecessary complexity for those not using i18n.

See #1983 and #1642.


I actually guessed so, but did not notice, and just felt like "oh, some translations are missing".

How about adding more emphasized guidance from the master wiki toward the devise-i18n project?

For "those not using i18n", this part would be outside their head or interests, although for those using i18n, missing translations (OR missing "the existence of" translations) practically assigns them a lot of additional works.


Hi @orzccc

Thank you so much for your pull request. As we're receiving a lot of pull requests about it recently, I think it is time, as you suggested, to emphasize guidance on this matter.

As you may have noticed, Devise views are only a way to quickly have a working authentication system, and as they are almost always overwritten with a custom view, adding it will only increase complexity on an environment that (at least initially) should be simple.


@orzccc feel free to update the wiki pages to provide the guidance you feel that it is missing. they are public and everyone has access to edit them! tks!


I've searched in devise-i18n issues also, i've found an issue dated 3 months ago for a future release of a devise-i18n-views gem, but googling for that i've only found a dismissed project on Github.

Internationalizing that views/mailers does not requires a giant amount of work and thus there are couple of attempts spread all over forums and groups.

So can I suggest that we could create a new gem right now, call it something like 'devise-intenationalized-views' and merge I18n views with @orzccc mailers.

Then if @josevalim, @rodrigoflores ... agree we could create/use a wiki page to provide guidance on how to actual translate views.

What about that?


This sounds perfect. Having a solid devise-i18n-views that we can recommend to others would be great. We could even add links to the README. Let us know when you get it done with!


@mcasimir if you look at #1983 I proposed this approach here. That said I'm :+1: for this path.


Ok done:

gem "devise-i18n-views"

I've basically downloaded @orzccc version of mailers (with a fallback to English) and merged it with devise views translated in a crude way, such that the string "Sign In!" in file "views/devise/sessions/new.html.erb" is now <%= t("", :default => "Sign In!") %>

It can be done better but it is a good starting point.

Maybe someone can help me to test it and discuss a little convention for I18n keys before publicly add it to the wiki. I don't know if this is the right place to talk about it, perhaps it would be better to move somewhere else, am I right? but where then?


I don't mind with continuing the discussion here. I would suggest to use the view shortcut for the translations though:


It is how it is commonly used in Rails apps and it is shorter. The only difference is that the key will now be instead of so you need to adjust the yml file accordingly. The reason the mailer uses devise.mailer as key is exactly because the name of the class is devise.mailer. :)

By default, Rails and I18n loads all translations in the config/locales/*. This means that, if you put all translations inside the gem, in the future you may have 20+ different translations and they will all be loaded into your app. This could possibly take MBs of memory. So I would suggest to put all translations into a translations directory at root and tell people to manually copy it to their apps.

Since you are already adding the default to the views, you don't need to have anything in config/locales and it should work fine.

About testing, the best recommendation I can give is to grab latest Rails and run:

rails plugin new --full devise-i18n-views

It will generate a full application inside test. In this application, you should install Devise, as you would for any app, and then you can test it as you would in any app. Simple assertions on the contents should do the trick.


Thanks for your suggestions, there is always something new to learn! Based on what you told me i've changed it as follows:

  • now it uses view-shortcut for I18n keys across all the views
  • yml files are corrected according to shortcut syntax
  • locale files are moved from config/locales to locales
  • i provided a generator to install locales under config/locales: rails g devise_i18n_views:locale LOCALE generates config/locales/devise.views.LOCALE.yml

Nothing except basic translation is tested yet, tomorrow i could try to see what happens with the mailer but at this time i don't have so much time to write programmatic tests, i hope someone else could do that if it's necessary.

Also, i've never mantained a Gem before now, neither a small one, so i've no idea about how much time it takes, is it a busy task?


What about devise:views:locale LOCALE, could it be ok? I would prefer to mantain the generate something form, i found it easier to remember, but is not so important ;)


Ok renamed and tested the mailer also, now it seems ok to me.

@nyjt nyjt referenced this pull request from a commit in maximalink/devise-i18n-bootstrap
@mcasimir mcasimir updated mailer with plataformatec/devise#1989 (commits) ed893c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
7 app/views/devise/mailer/confirmation_instructions.html.erb
@@ -1,5 +1,6 @@
-<p>Welcome <%= %>!</p>
+<p><%= t('devise.mailer.confirmation_instructions.greeting', :recepient => %></p>
-<p>You can confirm your account email through the link below:</p>
+<p><%= t('devise.mailer.confirmation_instructions.instruction') %></p>
-<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
+<p><%= link_to t('devise.mailer.confirmation_instructions.action'),
+ confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
10 app/views/devise/mailer/reset_password_instructions.html.erb
@@ -1,8 +1,8 @@
-<p>Hello <%= %>!</p>
+<p><%= t('devise.mailer.reset_password_instructions.greeting', :recepient => %></p>
-<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
+<p><%= t('devise.mailer.reset_password_instructions.instruction') %></p>
-<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
+<p><%= link_to t('devise.mailer.reset_password_instructions.action'), edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
-<p>If you didn't request this, please ignore this email.</p>
-<p>Your password won't change until you access the link above and create a new one.</p>
+<p><%= t('devise.mailer.reset_password_instructions.instruction_2') %></p>
+<p><%= t('devise.mailer.reset_password_instructions.instruction_3') %></p>
8 app/views/devise/mailer/unlock_instructions.html.erb
@@ -1,7 +1,7 @@
-<p>Hello <%= %>!</p>
+<p><%= t('devise.mailer.unlock_instructions.greeting', :recepient => %></p>
-<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
+<p><%= t('devise.mailer.unlock_instructions.message') %></p>
-<p>Click the link below to unlock your account:</p>
+<p><%= t('devise.mailer.unlock_instructions.instruction') %></p>
-<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
+<p><%= link_to t('devise.mailer.unlock_instructions.action'), unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
11 config/locales/en.yml
@@ -53,7 +53,18 @@ en:
subject: 'Confirmation instructions'
+ greeting: 'Welcome %{recepient}!'
+ instruction: 'You can confirm your account email through the link below:'
+ action: 'Confirm my account'
subject: 'Reset password instructions'
+ greeting: 'Hello %{recepient}!'
+ instruction: 'Someone has requested a link to change your password, and you can do this through the link below.'
+ action: 'Change my password'
+ instruction_2: "If you didn't request this, please ignore this email."
+ instruction_3: "Your password won't change until you access the link above and create a new one."
subject: 'Unlock Instructions'
+ greeting: 'Hello %{recepient}!'
+ message: 'Your account has been locked due to an excessive amount of unsuccessful sign in attempts.'
+ instruction: 'Click the link below to unlock your account:'
Something went wrong with that request. Please try again.