Module: ActionView::Helpers::ActiveRecordHelper::L10n

Includes:
GetText
Defined in:
lib/gettext/rails.rb

Constant Summary

Constants included from GetText

GetText::VERSION

Class Method Summary collapse

Methods included from GetText

N_, #Nn_, _, #add_default_locale_path, bindtextdomain, #bindtextdomain_to, bound_target, bound_targets, cached=, cached?, cgi, cgi=, charset=, clear_cache, create_mofiles, current_textdomain_info, each_textdomain, gettext, included, locale, locale=, msgmerge, msgmerge_all, n_, ngettext, ns_, nsgettext, output_charset, output_charset=, rgettext, rmsgfmt, rmsgmerge, s_, set_cgi, set_charset, set_locale, set_locale_all, set_output_charset, setlocale, sgettext, textdomain, #textdomain_to, update_pofiles

Class Method Details

.error_messages_for(instance, objects, object_names, count, options) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/gettext/rails.rb', line 332

def error_messages_for(instance, objects, object_names, count, options)
         record = ActiveRecord::Base.human_attribute_table_name_for_error(options[:object_name] || object_names[0].to_s)

  message_title = instance.error_message_title(@error_message_title)
  message_explanation = instance.error_message_explanation(@error_message_explanation)

         html = {}
         [:id, :class].each do |key|
           if options.include?(key)
             value = options[key] 
             html[key] = value unless value.blank?
           else
             html[key] = 'errorExplanation'
           end
         end

         header_message = n_(message_title, count) % {:num => count, :record => record}
         error_messages = objects.map {|object| object.errors.full_messages.map {|msg| instance.(:li, msg) } }
           
         instance.(:div,
                           instance.(options[:header_tag] || :h2, header_message) <<
                           instance.(:p, n_(message_explanation, count) % {:num => count}) <<
                           instance.(:ul, error_messages),
                           html
                           )
end

.set_error_message_explanation(msg, plural_msg = nil) ⇒ Object

call-seq: set_error_message_explanation(msg)

Sets a your own explanation of the error message dialog.

  • msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().

  • Returns: [single_msg, plural_msg]



321
322
323
324
325
326
327
328
329
# File 'lib/gettext/rails.rb', line 321

def set_error_message_explanation(msg, plural_msg = nil)
  if msg.kind_of? Array
    single_msg = msg[0]
    plural_msg = msg[1]
  else
    single_msg = msg
  end
  @error_message_explanation = [single_msg, plural_msg]
end

.set_error_message_title(msg, plural_msg = nil) ⇒ Object

call-seq: set_error_message_title(msgs)

Sets a your own title of error message dialog.

  • msgs: [single_msg, plural_msg]. Usually you need to call this with Nn_().

  • Returns: [single_msg, plural_msg]



305
306
307
308
309
310
311
312
313
# File 'lib/gettext/rails.rb', line 305

def set_error_message_title(msg, plural_msg = nil)
  if msg.kind_of? Array
    single_msg = msg[0]
    plural_msg = msg[1]
  else
    single_msg = msg
  end
  @error_message_title = [single_msg, plural_msg]
end