Module: ActionController::Resources

Defined in:
lib/i18n_routing_rails2.rb

Defined Under Namespace

Classes: Resource

Instance Method Summary collapse

Instance Method Details

#create_globalized_resources(type, namespace, *entities, &block) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/i18n_routing_rails2.rb', line 156

def create_globalized_resources(type, namespace, *entities, &block)

  Thread.current[:i18n_nested_deep] ||= 0
  Thread.current[:i18n_nested_deep] += 1

  if @set.locales
    name = entities.dup.shift.to_s

    options = entities.extract_options!
    opts = options.dup

    locales = @set.locales
    localized(nil) do
      locales.each do |l|
        I18n.locale = l
        nt = "#{l}_#{name}"
        if nt != name and (t = I18nRouting.translation_for(name, namespace))
          nt = "#{l}_#{name}"
          opts[:as] = t
          opts[:glang] = l
          opts[:controller] ||= name.to_s.pluralize
          opts[:real_path] = opts[:singular] || name
          opts[:path_names] = I18nRouting.path_names(name, options)
          path_prefix_t = I18n.t(:path_prefix, :scope => :"routes.#{name}", :default => "NoPathPrefixTranslation")
          opts[:path_prefix] = path_prefix_t unless path_prefix_t == "NoPathPrefixTranslation"

          localized([l]) do
            switch_no_named_localization(true) do
              send(type, nt.to_sym, opts, &block)
            end
          end
          puts("[I18n] > localize %-10s: %40s (%s) => %s" % [namespace, nt, l, t]) if @set.i18n_verbose
        end
      end

      if Thread.current[:i18n_nested_deep] < 2
        switch_no_named_localization(nil) do
          switch_globalized_state(true) do
            send(type, *(entities << options), &block)
          end
        end
      end
    end

  else
    send(type, *entities, &block)
  end

  Thread.current[:i18n_nested_deep] -= 1
end

#gl_resourceObject



212
# File 'lib/i18n_routing_rails2.rb', line 212

alias_method :gl_resource, :resource

#gl_resourcesObject



207
# File 'lib/i18n_routing_rails2.rb', line 207

alias_method :gl_resources, :resources

#resource(*entities, &block) ⇒ Object



213
214
215
# File 'lib/i18n_routing_rails2.rb', line 213

def resource(*entities, &block)
  create_globalized_resources(:gl_resource, :resource, *entities, &block)
end

#resources(*entities, &block) ⇒ Object



208
209
210
# File 'lib/i18n_routing_rails2.rb', line 208

def resources(*entities, &block)
  create_globalized_resources(:gl_resources, :resources, *entities, &block)
end

#switch_globalized_state(state) ⇒ Object



142
143
144
145
146
147
# File 'lib/i18n_routing_rails2.rb', line 142

def switch_globalized_state(state)
  old_g = Thread.current[:globalized]
  Thread.current[:globalized] = state
  yield
  Thread.current[:globalized] = old_g
end

#switch_no_named_localization(state) ⇒ Object



149
150
151
152
153
154
# File 'lib/i18n_routing_rails2.rb', line 149

def switch_no_named_localization(state)
  old_g = Thread.current[:i18n_no_named_localization]
  Thread.current[:i18n_no_named_localization] = state
  yield
  Thread.current[:i18n_no_named_localization] = old_g
end