Project

General

Profile

Actions

Defect #2626

closed

Error during translation of the "is too short" and "is too long" messages

Added by Andrew R Jackson almost 16 years ago. Updated almost 16 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Translations
Target version:
Start date:
2009-01-30
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

PROBLEM:
This class of message is causing ActionView::TemplateError translation value error ("too few arguments") and a resulting 500 HTTP error in 0.8.0.

REASON:
The cause is in the error_message_for() method of app/helpers/application_helper.rb--prior to the call to l() to obtain a localized msg, the msg Array is forcibly transformed into msg.first which is the String to display to the user.

This breaks the call to GLoc's l() method when the String has dynamically filled fields which used to follow the String in msg, but were stripped off. The actual error occurs in GLoc's internal _l() method.

GLoc is present at vendor/plugins/gloc-1.1.0/

MY FIX:
Repair application_helper.rb to not do that transformation. In fact, fix it so that if msg is just String, it is turned into an Array with just the String (opposite of what is there) and call l(*msg) instead of l(msg).

PATCH (changes 2 lines):

--- broken/app/helpers/application_helper.rb   2009-01-26 09:49:24.000000000 -0600
+++ app/helpers/application_helper.rb   2009-01-30 10:17:35.000000000 -0600
@@ -524,11 +525,12 @@
       full_messages = []
       object.errors.each do |attr, msg|
         next if msg.nil?
-        msg = msg.first if msg.is_a? Array
+        msg = [msg] if(msg.is_a?(String))
         if attr == "base" 
           full_messages << l(msg)
         else
-          full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values" 
+          full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(*msg) unless attr == "custom_values" 
         end
       end
       # retrieve custom values error messages

My env:

  mysql-5.0.67
  rails (2.1.2)
  ruby 1.8.7 (2008-08-08 patchlevel 71) [x86_64-linux]
  redmine 0.8.0


Files

too_short_error.png (3.1 KB) too_short_error.png Jean-Philippe Lang, 2009-02-02 19:04

Related issues

Has duplicate Redmine - Defect #2787: validation fails when project name exceeds 30 characters on createClosed2009-02-20

Actions
Actions

Also available in: Atom PDF