Last active
August 29, 2015 14:14
-
-
Save ybart/dab3fef2a2cfd2144c5c to your computer and use it in GitHub Desktop.
Localizing ActionMailer::Preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application < Rails::Application | |
... | |
# The easiest way : update the default locale and restart | |
config.i18n.default_locale = :fr | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyMailerPreview < MailerPreview | |
def notify_error | |
MyMailer.notify_error(MyModel.last) | |
end | |
def notify_error_fr | |
I18n.with_locale(:fr) do | |
notify_error | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rails::MailersController < Rails::ApplicationController | |
prepend_view_path File.expand_path('../../../../lib/templates', __FILE__) | |
before_action :set_locale | |
def set_locale | |
I18n.locale = params['locale'] || I18n.default_locale | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% unless @email.attachments.nil? || @email.attachments.empty? %> | |
<dt>Attachments:</dt> | |
<dd> | |
<%= @email.attachments.map { |a| a.respond_to?(:original_filename) ? a.original_filename : a.filename }.inspect %> | |
</dd> | |
<% end %> | |
<% if @email.multipart? %> | |
<dd> | |
<select onchange="document.getElementsByName('messageBody')[0].src=this.options[this.selectedIndex].value;"> | |
<option <%= request.format == Mime::HTML ? 'selected' : '' %> value="?part=text%2Fhtml&locale=<%= I18n.locale %>">View as HTML email</option> | |
<option <%= request.format == Mime::TEXT ? 'selected' : '' %> value="?part=text%2Fplain&locale=<%= I18n.locale %>">View as plain-text email</option> | |
</select> | |
</dd> | |
<% end %> | |
</dl> | |
</header> | |
<iframe seamless name="messageBody" src="?part=<%= Rack::Utils.escape(@part.mime_type) %>&locale=<%= I18n.locale %>"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MailerPreview < ActionMailer::Preview | |
before_action :set_locale | |
def set_locale | |
I18n.locale = params['locale'] || I18n.default_locale | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment