lib/traco/class_methods.rb in traco-1.2.4 vs lib/traco/class_methods.rb in traco-1.3.0

- old
+ new

@@ -1,9 +1,11 @@ module Traco module ClassMethods + LOCALE_RE = /[a-zA-Z]{2}(?:-[a-zA-Z]{2})?/ + def locales_for_attribute(attribute) - re = /\A#{attribute}_([a-z]{2})\z/ + re = /\A#{attribute}_(#{LOCALE_RE})\z/ column_names. grep(re) { $1.to_sym }. sort_by(&locale_sort_value) end @@ -16,10 +18,10 @@ } end def human_attribute_name(attribute, options = {}) default = super(attribute, options.merge(:default => "")) - if default.blank? && attribute.to_s.match(/\A(\w+)_([a-z]{2})\z/) + if default.blank? && attribute.to_s.match(/\A(\w+)_(#{LOCALE_RE})\z/) column, locale = $1, $2.to_sym if translates?(column) return "#{super(column, options)} (#{locale_name(locale)})" end end