, Rails. (, ).
, :
:
. , ( ) .
:
. ( ) ( ).
Globalize .
/:
, , Rails + Globalize, ... , .
I18n.locale . Globalize, Globalize.locale /.
I18n.locale, Globalize.locale . Thread, .
Globalize.locale I18n.locale I18n.locale. . ( , -, ).
Globalize.locale ( I18n.locale), .
Reset I18n.locale Globalize.locale . rspec
RSpec.configure do |config|
config.after(:each) do
I18n.locale = :en
Globalize.locale = :en
end
end
, URL-, .
, .
When you are working in your rails application, you are probably using default_url_optionsto use the I18n.localedefault locales for your route / path helpers as a parameter. However, this does not work in tests. I chose a solution from this github issue on rspec-rails.
Monkey patch I ActionDispatch::Routing::RouteSetlike this:
class ActionDispatch::Routing::RouteSet
def url_for_with_locale_fix(options={})
url_for_without_locale_fix(options.merge(:locale => I18n.locale))
end
alias_method_chain :url_for, :locale_fix
end
Set the translation helper tas a wrapper around the I18n.t method
module I18nHelper
def t string, options = {}
I18n.t string, options
end
end
RSpec.configure do |config|
config.include I18nHelper
end
source
share