Small refactoring of translate method.

This commit is contained in:
Carlos Antonio da Silva 2009-12-08 17:08:36 -02:00
parent 4a54e4ecd6
commit 73898c05e2
3 changed files with 12 additions and 7 deletions

View File

@ -45,5 +45,15 @@ module SimpleForm
else input_type
end
end
def translate_form(scope, default='')
lookups = [:"#{@object_name}.#{@attribute}", :"#{@attribute}", default]
translate(lookups.shift, :scope => :"simple_form.#{scope}", :default => lookups)
end
def translate(key, params={})
I18n.t(key, {:scope => :simple_form}.merge!(params))
end
end
end

View File

@ -13,8 +13,7 @@ module SimpleForm
end
def translate_hint
lookups = [:"#{@object_name}.#{@attribute}", :"#{@attribute}", '']
I18n.t(lookups.shift, :scope => :"simple_form.hints", :default => lookups)
translate_form(:hints)
end
end
end

View File

@ -20,8 +20,7 @@ module SimpleForm
def translate_label
default = @object.try(:human_attribute_name, @attribute.to_s) || @attribute.to_s.humanize
lookups = [:"#{@object_name}.#{@attribute}", :"#{@attribute}", default]
I18n.t(lookups.shift, :scope => :"simple_form.labels", :default => lookups)
translate_form(:labels, default)
end
def translate_required_string
@ -38,8 +37,5 @@ module SimpleForm
translate(:required_mark, :default => '*')
end
def translate(key, params={})
I18n.t(key, {:scope => :simple_form}.merge!(params))
end
end
end