make sure i18n_routing doesn't override I18n.locale #21

Merged
merged 2 commits into from Sep 14, 2011
Jump to file or symbol
Failed to load files and symbols.
+9 −0
Split
@@ -91,6 +91,7 @@ def add_named_route(name, path, options = {}) #:nodoc:
# Here, try to translate standard named routes
name = name.to_s
+ stored_locale = I18n.locale
@locales.each do |l|
I18n.locale = l
nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
@@ -100,6 +101,7 @@ def add_named_route(name, path, options = {}) #:nodoc:
puts("[I18n] > localize %-10s: %40s (%s) => %s" % ['route', name, l, t]) if @i18n_verbose
end
end
+ I18n.locale = stored_locale
old_v = Thread.current[:globalized]
Thread.current[:globalized] = true
@@ -160,6 +162,7 @@ def create_globalized_resources(type, namespace, *entities, &block)
locales = @set.locales
localized(nil) do
+ stored_locale = I18n.locale
locales.each do |l|
I18n.locale = l
nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
@@ -180,6 +183,8 @@ def create_globalized_resources(type, namespace, *entities, &block)
puts("[I18n] > localize %-10s: %40s (%s) => %s" % [namespace, nt, l, t]) if @set.i18n_verbose
end
end
+ I18n.locale = stored_locale
+
if Thread.current[:i18n_nested_deep] < 2
switch_no_named_localization(nil) do
@@ -31,6 +31,7 @@ def localized_resources(type = :resources, *resources, &block)
resource = resource_from_params(type, r, options.dup)
# Check for translated resource
+ stored_locale = I18n.locale
@locales.each do |locale|
I18n.locale = locale
localized_path = I18nRouting.translation_for(resource.name, type)
@@ -82,6 +83,7 @@ def localized_resources(type = :resources, *resources, &block)
localizable_route = resource
end
end
+ I18n.locale = stored_locale
end
return localizable_route
end
@@ -286,6 +288,7 @@ class LocalizedMapping < ActionDispatch::Routing::Mapper::Mapping
def initialize(locale, set, scope, path, options)
super(set, scope, path.clone, options ? options.clone : nil)
+ stored_locale = I18n.locale
# try to get translated path :
I18n.locale = locale
@@ -312,6 +315,7 @@ def initialize(locale, set, scope, path, options)
else
@localized_path = nil
end
+ I18n.locale = stored_locale
end
# Return true if this route is localizable