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



153
154
155
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
# File 'lib/i18n_routing_rails2.rb', line 153

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
      stored_locale = I18n.locale
      locales.each do |l|
        I18n.locale = l
        nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
        if nt != name and !(t = I18nRouting.translation_for(name, namespace)).blank?
          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
      I18n.locale = stored_locale


      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



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

alias_method :gl_resource, :resource

#gl_resourcesObject



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

alias_method :gl_resources, :resources

#resource(*entities, &block) ⇒ Object



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

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

#resources(*entities, &block) ⇒ Object



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

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

#switch_globalized_state(state) ⇒ Object



139
140
141
142
143
144
# File 'lib/i18n_routing_rails2.rb', line 139

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



146
147
148
149
150
151
# File 'lib/i18n_routing_rails2.rb', line 146

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