mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 07:16:41 +00:00
fix i18n locale load order to allow customisation
fix interpolation values for i18n
This commit is contained in:
@@ -31,7 +31,7 @@ module ValidatesTimeliness
|
||||
|
||||
def load_error_messages
|
||||
if defined?(I18n)
|
||||
I18n.load_path += [ LOCALE_PATH ]
|
||||
I18n.load_path.unshift(LOCALE_PATH)
|
||||
I18n.reload!
|
||||
else
|
||||
defaults = YAML::load(IO.read(LOCALE_PATH))['en']
|
||||
|
||||
@@ -94,7 +94,7 @@ module ValidatesTimeliness
|
||||
restriction = [restriction] unless restriction.is_a?(Array)
|
||||
|
||||
if defined?(I18n)
|
||||
message = custom_error_messages[option] || I18n.t('activerecord.errors.messages')[option]
|
||||
message = I18n.t('activerecord.errors.messages')[option]
|
||||
subs = message.scan(/\{\{([^\}]*)\}\}/)
|
||||
interpolations = {}
|
||||
subs.each_with_index {|s, i| interpolations[s[0].to_sym] = restriction[i].strftime(format) }
|
||||
@@ -118,7 +118,7 @@ module ValidatesTimeliness
|
||||
def add_error(record, attr_name, message, interpolate=nil)
|
||||
if defined?(I18n)
|
||||
custom = custom_error_messages[message]
|
||||
record.errors.add(attr_name, custom || message, interpolate || {})
|
||||
record.errors.add(attr_name, message, { :default => custom }.merge(interpolate || {}))
|
||||
else
|
||||
message = error_messages[message] if message.is_a?(Symbol)
|
||||
message = message % interpolate
|
||||
|
||||
Reference in New Issue
Block a user