module FormInput::Parameter::R18nMethods
R18n specific methods.
Constants
- UNLOCALIZED_OPTIONS
Parameter
options which are known to be not localized.
Public Instance Methods
Automatically attempt to translate available parameter options.
# File lib/form_input/r18n.rb, line 27 def []( name ) if form and r18n value = opts[ name ] if value.is_a?( String ) or ( value.nil? and not UNLOCALIZED_OPTIONS.include?( name ) ) text = pt( name ) return text.to_s if text.translated? end end super end
Localized version of error message formatting. See original implementation for details.
# File lib/form_input/r18n.rb, line 39 def format_error_message( msg, count = nil, singular = nil, *rest ) return super unless msg.is_a?( Symbol ) and r18n if limit = count and singular limit = t.form_input.units[ singular, count ].to_s end text = t.form_input.errors[ msg, *limit, self ].to_s super( text ) end
Like t helper, except that the translation is looked up in the forms.<form_name> scope. Supports both ft.name( args ) and ft( :name, args ) forms.
# File lib/form_input/r18n.rb, line 50 def ft( *args ) form.ft( *args ) end
Get the gender string used for inflecting the parameter messages.
# File lib/form_input/r18n.rb, line 77 def gender ( self[ :gender ] || ( t.form_input.default_gender | 'n' ) ).to_s end
Get the inflection string used for correctly inflecting the parameter messages. Note that it ignores the noun case as the parameter names are supposed to use the nominative case anyway.
# File lib/form_input/r18n.rb, line 63 def inflection ( self[ :inflect ] || "#{pluralize}#{gender}" ).to_s end
Get the string corresponding to the grammatical number of the parameter name used for inflecting the parameter messages.
# File lib/form_input/r18n.rb, line 68 def pluralize p = self[ :plural ] p = ! scalar? if p.nil? p = 's' if p == false p = 'p' if p == true p.to_s end
Like t helper, except that the translation is looked up in the forms.<form_name>.<param_name> scope. Supports both pt.name( args ) and pt( :name, args ) forms. The latter automatically adds self as last argument to support inflection.
# File lib/form_input/r18n.rb, line 56 def pt( *args ) translation = ft[ name ] args.empty? ? translation : translation[ *args, self ] end