Hi again

As I'm really busy currently and as I'm not really familiar with open
source and git hub, I don't really know what the right thing to do,
but I'm ok to integrate properly the plugin in gloablize2 when i find
the time if someone can take a little bit of his time to explain me
the right way to do that.

But if you are in a hurry, here follow my source code (It's working
fine on Rails2.1 and Globalize1), You just have to change the way I
iterate the supported languages (MkdGlobalize::Langs.each_key). Just
include the file and add :globalized => true option to your resource
and named_route, then run "rake routes" and watch the magic.


module ActionController
  module Routing
    class RouteSet #:nodoc:
      class NamedRouteCollection #:nodoc:

        alias_method :mkd_define_url_helper, :define_url_helper
        def define_url_helper(route, name, kind, options)

          mkd_define_url_helper(route, name, kind, options)

          # globalization surcouche
          if options[:globalized] or options[:globalized_p] or
options[:globalized_s]
            selector = url_helper_name(name, kind)

            # surcharge de l'helper
            @module.module_eval <<-end_eval # We use module_eval to
avoid leaks
              alias_method :gl#{selector}, :#{selector}

              def #{selector}(*args)
                selector_g = "\#{lang}_
\#{'#{selector}'.gsub('_#{kind}', '')}_#{kind}"

                if respond_to? selector_g.to_sym and
selector_g.to_sym != :#{selector}
                  send(selector_g.to_sym, *args)
                else
                  gl#{selector}(*args)
                end
              end
              protected :gl#{selector}
            end_eval

          end
        end
      end

      alias_method :gl_add_named_route, :add_named_route
      def add_named_route(name, path, options = {}) #:nodoc:
        gl_add_named_route(name, path, options)
        return if !options[:globalized]

        options.delete(:globalized)
        name = name.to_s
        MkdGlobalize::Langs.each_key do |l|
          Globalize::Locale.set(l.to_s)
          nt = "#{l}_#{name}"
          if nt != name
            gl_add_named_route(nt, path.to_s.t(nil, nil,
'named_routes_path'), options)
          end
        end
      end

    end
  end
end

module ActionController
  module Resources
    alias_method :gl_resources, :resources
    def resources(*entities, &block)
      opts = entities.dup.extract_options!
      gl_resources(*entities, &block)
      return if !opts[:globalized]
      name = entities.shift.to_s

      opts[:controller] = name if !opts[:controller]

      opts.delete(:globalized)
      MkdGlobalize::Langs.each_key do |l|
        Globalize::Locale.set(l.to_s)
        nt = "#{l}_#{name}"#name.t(nil, nil, 'resources')
        if nt != name
          opts[:as] = name.t(nil, nil, 'resources')
          gl_resources(nt.to_sym, opts, &block)
        end
      end
    end

    alias_method :gl_resource, :resource
    def resource(*entities, &block)
      opts = entities.dup.extract_options!
      gl_resource(*entities, &block)
      return if !opts[:globalized]
      name = entities.shift.to_s

      opts[:controller] = name if !opts[:controller]

      opts.delete(:globalized)
      MkdGlobalize::Langs.each_key do |l|
        Globalize::Locale.set(l.to_s)
        nt = "#{l}_#{name}"#name.t(nil, nil, 'resource')
        if nt != name
          opts[:as] = name.t(nil, nil, 'resource')
          gl_resource(nt.to_sym, opts, &block)
        end
      end
    end

    private
      def action_options_for(action, resource, method = nil)
        default_options = { :action => action.to_s }
        if resource.options[:globalized]
          default_options[:globalized_p] = resource.plural
          if resource.uncountable?
            default_options[:globalized_p] = resource.plural.to_s +
'_index'
          end
          default_options[:globalized_s] = resource.singular
        end
        require_id = !resource.kind_of?(SingletonResource)
        case default_options[:action]
          when "index", "new";
default_options.merge(add_conditions_for(resource.conditions, method
|| :get)).merge(resource.requirements)
          when "create";
default_options.merge(add_conditions_for(resource.conditions, method
|| :post)).merge(resource.requirements)
          when "show", "edit";
default_options.merge(add_conditions_for(resource.conditions, method
|| :get)).merge(resource.requirements(require_id))
          when "update";
default_options.merge(add_conditions_for(resource.conditions, method
|| :put)).merge(resource.requirements(require_id))
          when "destroy";
default_options.merge(add_conditions_for(resource.conditions, method
|| :delete)).merge(resource.requirements(require_id))
          else
default_options.merge(add_conditions_for(resource.conditions,
method)).merge(resource.requirements)
        end
      end
  end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"rails-i18n" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rails-i18n?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to