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

Includes:
GetText
Defined in:
lib/gettext_rails/action_view/active_record_helper.rb

Overview

:nodoc: all

Constant Summary collapse

@@error_message_headers =
{
  :header => Nn_("%{num} error prohibited this %{record} from being saved", 
                 "%{num} errors prohibited this %{record} from being saved"),
  :body => Nn_("There was a problem with the following field:", 
             "There were problems with the following fields:")
}

Class Method Summary collapse

Methods included from GetText

#create_mofiles, #create_mofiles_org

Class Method Details

.error_message(key, model, count) ⇒ Object

:nodoc:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gettext_rails/action_view/active_record_helper.rb', line 63

def error_message(key, model, count) #:nodoc:
  return nil if key.nil?
   
  if key.kind_of? Symbol
    msgids = @@error_message_headers[key]
  else
    key << key[0] if (key.is_a?(Array) && key.length==1) 
    key = [key, key] if key.is_a? String

    msgids = key
  end

  model = _(model)
  if msgids
    ngettext(msgids, count) % {:num => count, :count => count, 
      :record => model, :model => model} # :num, :record are for backward compatibility.
  else
    nil
  end
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]



53
54
55
56
57
58
59
60
61
# File 'lib/gettext_rails/action_view/active_record_helper.rb', line 53

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_headers[:body] = [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]



37
38
39
40
41
42
43
44
45
# File 'lib/gettext_rails/action_view/active_record_helper.rb', line 37

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_headers[:header] = [single_msg, plural_msg]
end