Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
reverted to use of I18n.locale
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Mar 5, 2010
1 parent b5ff194 commit 5eb94f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions lib/translate_routes.rb
Expand Up @@ -167,7 +167,7 @@ def self.add_untranslated_helpers_to_controllers_and_views(old_name)
new_helper_name = "#{old_name}_#{suffix}"
def_new_helper = <<-DEF_NEW_HELPER
def #{new_helper_name}(*args)
send("#{old_name}_\#{locale_suffix(I18n.default_locale)}_#{suffix}", *args)
send("#{old_name}_\#{locale_suffix(I18n.locale)}_#{suffix}", *args)
end
DEF_NEW_HELPER

Expand All @@ -187,16 +187,25 @@ def self.add_prefix?(lang)
def self.translate_segment_key(segment, locale)
if @using_i18n
# tmp = I18n.locale
# I18n.default_locale = locale
value = I18n.translate locale, segment, {:default => segment.dup, :scope => @@translation_scope}
# I18n.default_locale = tmp
# I18n.locale = tmp
else
value = @@dictionaries[locale][segment] || segment.dup
end
value
end

# in rails 3, static segments are just keys/strings!
# we should also handle optional segments: “/:controller(/:action(/:id))(.:format)”
# def segment_keys
# @segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym }
# end
# class NamedRouteCollection
# :routes
# def names
# routes.keys
# end

def self.locale_segments(orig, locale)
segments = []

Expand All @@ -211,7 +220,7 @@ def self.locale_segments(orig, locale)
segments << new_segment
end
# should segments be joined like this!? or with a / ?
segments.join(" ")
segments.join("/")
end

def self.locale_requirements(orig, locale)
Expand Down Expand Up @@ -259,8 +268,8 @@ def self.translate_route(route, route_name = nil)
private
# called by before_filter
def set_locale_from_url
# use ActionDispatch in Rails 3, I18n.locale now default_locale
I18n.default_locale = params[ActionDispatch::Routing::Translator.locale_param_key]
# use ActionDispatch in Rails 3
I18n.locale = params[ActionDispatch::Routing::Translator.locale_param_key]
default_url_options({ActionDispatch::Routing::Translator => I18n.locale })
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/translate_routes_test_helper.rb
Expand Up @@ -24,7 +24,7 @@ def process_with_default_language(action, parameters = nil, session = nil, flash
new_helper_name = "#{old_name}_#{suffix}"
def_new_helper = <<-DEF_NEW_HELPER
def #{new_helper_name}(*args)
send("#{old_name}_#{ActionDispatch::Routing::Translator.locale_suffix(I18n.default_locale)}_#{suffix}", *args)
send("#{old_name}_#{ActionDispatch::Routing::Translator.locale_suffix(I18n.locale)}_#{suffix}", *args)
end
DEF_NEW_HELPER
eval def_new_helper
Expand Down

0 comments on commit 5eb94f0

Please sign in to comment.