mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of github.com:rails/rails
This commit is contained in:
commit
02319b7982
5 changed files with 58 additions and 7 deletions
4
actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb
vendored
Normal file
4
actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
Hello there,
|
||||
|
||||
Mr. <%= @recipient %>. Be greeted, new member!
|
||||
|
46
actionmailer/test/i18n_with_controller_test.rb
Normal file
46
actionmailer/test/i18n_with_controller_test.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'abstract_unit'
|
||||
require 'action_controller'
|
||||
|
||||
class I18nTestMailer < ActionMailer::Base
|
||||
configure do |c|
|
||||
c.assets_dir = ''
|
||||
end
|
||||
|
||||
def mail_with_i18n_subject(recipient)
|
||||
@recipient = recipient
|
||||
I18n.locale = :de
|
||||
mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}",
|
||||
:from => "system@loudthinking.com", :date => Time.local(2004, 12, 12))
|
||||
end
|
||||
end
|
||||
|
||||
class TestController < ActionController::Base
|
||||
def send_mail
|
||||
I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
|
||||
render :text => 'Mail sent'
|
||||
end
|
||||
end
|
||||
|
||||
class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
|
||||
Routes = ActionDispatch::Routing::RouteSet.new
|
||||
Routes.draw do
|
||||
match ':controller(/:action(/:id))'
|
||||
end
|
||||
|
||||
def app
|
||||
Routes
|
||||
end
|
||||
|
||||
def setup
|
||||
I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome')
|
||||
end
|
||||
|
||||
def teardown
|
||||
I18n.locale = :en
|
||||
end
|
||||
|
||||
def test_send_mail
|
||||
get '/test/send_mail'
|
||||
assert_equal "Mail sent", @response.body
|
||||
end
|
||||
end
|
|
@ -13,14 +13,15 @@ module AbstractController
|
|||
# This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
|
||||
# it will trigger the lookup_context and consequently expire the cache.
|
||||
class I18nProxy < ::I18n::Config #:nodoc:
|
||||
attr_reader :i18n_config, :lookup_context
|
||||
attr_reader :original_config, :lookup_context
|
||||
|
||||
def initialize(i18n_config, lookup_context)
|
||||
@i18n_config, @lookup_context = i18n_config, lookup_context
|
||||
def initialize(original_config, lookup_context)
|
||||
original_config = original_config.original_config if original_config.respond_to?(:original_config)
|
||||
@original_config, @lookup_context = original_config, lookup_context
|
||||
end
|
||||
|
||||
def locale
|
||||
@i18n_config.locale
|
||||
@original_config.locale
|
||||
end
|
||||
|
||||
def locale=(value)
|
||||
|
|
|
@ -186,11 +186,11 @@ module ActionView
|
|||
end
|
||||
|
||||
# Overload locale= to also set the I18n.locale. If the current I18n.config object responds
|
||||
# to i18n_config, it means that it's has a copy of the original I18n configuration and it's
|
||||
# to original_config, it means that it's has a copy of the original I18n configuration and it's
|
||||
# acting as proxy, which we need to skip.
|
||||
def locale=(value)
|
||||
if value
|
||||
config = I18n.config.respond_to?(:i18n_config) ? I18n.config.i18n_config : I18n.config
|
||||
config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
|
||||
config.locale = value
|
||||
end
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ class LookupContextTest < ActiveSupport::TestCase
|
|||
assert_equal :pt, I18n.locale
|
||||
assert_equal :pt, @lookup_context.locale
|
||||
ensure
|
||||
I18n.config = I18n.config.i18n_config
|
||||
I18n.config = I18n.config.original_config
|
||||
end
|
||||
|
||||
assert_equal :pt, I18n.locale
|
||||
|
|
Loading…
Reference in a new issue