Permalink
Browse files

i18n specs on radio input are passing, but I've noticed heaps of othe…

…r inputs are now broken
  • Loading branch information...
1 parent aee41a9 commit 4a2cc5905bfd84e9166f4541a38b1554903270b8 @justinfrench committed Mar 17, 2011
@@ -5,7 +5,7 @@ module Html
def to_html
input_wrapping do
- builder.label(method, label_html_options) <<
+ builder.label(input_name, label_text, label_html_options) <<
builder.text_field(method, input_html_options)
end
end
@@ -18,6 +18,14 @@ def sanitized_method_name
def attributized_method_name
method.to_s.gsub(/_id$/, '').to_sym
end
+
+ def humanized_method_name
+ if object && object.class.respond_to?(:human_attribute_name)
+ object.class.human_attribute_name(method.to_s)
+ else
+ method.to_s.send(builder.label_str_method)
+ end
+ end
end
end
@@ -111,6 +111,7 @@ module Inputs
class RadioInput
include NewBase
include NewBase::Collections
+ include Formtastic::LocalizedString
def to_html
input_wrapping do
@@ -160,15 +161,27 @@ def label_html_options
super.merge(:for => nil)
end
- # TODO move to NewBase
- # TODO i18n
- # abbr tag from config
+ # TODO move labeling to NewBase
def label_text
- text = method.to_s.humanize
- text << template.content_tag(:abbr, "*")
- text.html_safe
+ ((localized_label || humanized_method_name) << required_or_optional_string).html_safe
end
-
+
+ def required_or_optional_string
+ case required?
+ when true then builder.required_string.call
+ when false then builder.optional_string.call
+ else options[:required] # TODO why?
+ end
+ end
+
+ def label_from_options
+ options[:label]
+ end
+
+ def localized_label
+ localized_string(method, label_from_options, :label)
+ end
+
end
end
end
@@ -80,5 +80,24 @@ def normalize_model_name(name)
end
end
+ # TODO: Temporarily make this work when included inside an Input instead of FormBuilder
+ def escape_html_entities(string) #:nodoc:
+ if builder
+ if builder.escape_html_entities_in_hints_and_labels
+ # Acceppt html_safe flag as indicator to skip escaping
+ string = template.escape_once(string) unless string.respond_to?(:html_safe?) && string.html_safe? == true
+ end
+ string
+ else
+ super
+ end
+ end
+
+ # TODO: Temporarily make this work when included inside an Input instead of FormBuilder
+ def i18n_lookups_by_default
+ respond_to?(:builder) ? builder.i18n_lookups_by_default : super
+ end
+
+
end
end

0 comments on commit 4a2cc59

Please sign in to comment.