Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 2 commits into from

2 participants

@fishman

No description provided.

@kwi
Owner

Hey, thanks for the pull request, what kinf of bug is this fixing exactly ?

Thanks!

@fishman

when you do anything in a rake task for example that needs locales. the way i18n_routing generates routes, it will parse through all locales and subsequently set I18n.locale to the last locale. in my case the last locale is not the default locale, therefore the default locale of rake tasks is not what it should be.

@kwi kwi merged commit fd6fb4b into from
@kwi
Owner

Thanks :) merged !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 26, 2011
  1. @fishman
  2. @fishman

    Merge branch 'rails3.0'

    fishman authored
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 0 deletions.
  1. +5 −0 lib/i18n_routing_rails2.rb
  2. +4 −0 lib/i18n_routing_rails3.rb
View
5 lib/i18n_routing_rails2.rb
@@ -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
View
4 lib/i18n_routing_rails3.rb
@@ -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
Something went wrong with that request. Please try again.