]> git.openstreetmap.org Git - rails.git/commitdiff
Converted invalid_chars validator to use locale
authorJ Guthrie <jamie.guthrie@gmail.com>
Mon, 5 Nov 2018 01:55:25 +0000 (01:55 +0000)
committerJ Guthrie <jamie.guthrie@gmail.com>
Mon, 5 Nov 2018 14:27:07 +0000 (14:27 +0000)
app/validators/invalid_chars_validator.rb
app/validators/invalid_url_chars_validator.rb
app/validators/leading_whitespace_validator.rb
app/validators/trailing_whitespace_validator.rb
config/locales/en.yml

index 3860c95a3661192daadda41339f3306e48fc7709..f21f5a7cdb539aea4d432cd352f80cddfc8d54f5 100644 (file)
@@ -2,6 +2,6 @@ class InvalidCharsValidator < ActiveModel::EachValidator
   INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
 
   def validate_each(record, attribute, value)
   INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
 
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || "contains invalid chars") if value =~ /[#{INVALID_CHARS}]/
+    record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_chars")) if value =~ /[#{INVALID_CHARS}]/
   end
 end
   end
 end
index 38c4006b72701b25be12a64371f79cff3d818836..a93f6c6d9817aec8deb0dd5d980f6169601bf57e 100644 (file)
@@ -2,6 +2,6 @@ class InvalidUrlCharsValidator < ActiveModel::EachValidator
   INVALID_URL_CHARS = "/;.,?%#".freeze
 
   def validate_each(record, attribute, value)
   INVALID_URL_CHARS = "/;.,?%#".freeze
 
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.invalid chars", :invalid_chars => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
+    record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_url_chars", :invalid_url_chars => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
   end
 end
   end
 end
index e33d3c01b1624ba1cef6be2c7cf613ceae7e565e..90e7d9c95bf9f0854c25f02e6c30df2e59e1a7db 100644 (file)
@@ -1,5 +1,5 @@
 class LeadingWhitespaceValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
 class LeadingWhitespaceValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.leading whitespace")) if value =~ /\A\s/
+    record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if value =~ /\A\s/
   end
 end
   end
 end
index 03d6ef4db3bc88924ab370548d30faab2d97e650..aacc6dd043f2c503dfc32200ad4072fdb9fb4dd9 100644 (file)
@@ -1,5 +1,5 @@
 class TrailingWhitespaceValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
 class TrailingWhitespaceValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.trailing whitespace")) if value =~ /\s\z/
+    record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if value =~ /\s\z/
   end
 end
   end
 end
index c53ae19c8e014530174b64266fa239a328f14f71..112f3a207a56e3496a4d91418b24a5abe4a326a9 100644 (file)
@@ -2563,6 +2563,7 @@ en:
       flash: "Redaction destroyed."
       error: "There was an error destroying this redaction."
   validations:
       flash: "Redaction destroyed."
       error: "There was an error destroying this redaction."
   validations:
-    leading whitespace: "has leading whitespace"
-    trailing whitespace: "has trailing whitespace"
-    invalid chars: "must not contain an invalid char: %{invalid_chars}"
+    leading_whitespace: "has leading whitespace"
+    trailing_whitespace: "has trailing whitespace"
+    invalid_chars: "contains invalid chars"
+    invalid_url_chars: "must not contain an invalid char: %{invalid_url_chars}"