[-] FO : #PSCFV-2151 : Translations of errors are connected width sprintf()

This commit is contained in:
lLefevre
2012-05-14 11:45:41 +00:00
parent 97a37ff566
commit 83703dc4ee
21 changed files with 830 additions and 761 deletions
+6 -5
View File
@@ -469,12 +469,13 @@ abstract class AdminTabCore
/* Checking for maximum fields sizes */
foreach ($rules['size'] as $field => $maxLength)
if (Tools::getValue($field) !== false && Tools::strlen(Tools::getValue($field)) > $maxLength)
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is too long').' ('.$maxLength.' '.$this->l('chars max').')';
$this->_errors[] = sprintf(Tools::displayError('field %1$s is too long. (%2$d chars max)'), call_user_func(array($className, 'displayFieldName'), $field, $className), $maxLength);
/* Checking for maximum multilingual fields size */
foreach ($rules['sizeLang'] as $fieldLang => $maxLength)
foreach ($languages as $language)
if (Tools::getValue($fieldLang.'_'.$language['id_lang']) !== false && Tools::strlen(Tools::getValue($fieldLang.'_'.$language['id_lang'])) > $maxLength)
$this->_errors[] = sprintf(Tools::displayError('field %1$s is too long. (%2$d chars max, html chars including)'), call_user_func(array($className, 'displayFieldName'), $fieldLang, $className), $maxLength);
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).' ('.$language['name'].')</b> '.$this->l('is too long').' ('.$maxLength.' '.$this->l('chars max, html chars including').')';
/* Overload this method for custom checking */
@@ -962,10 +963,10 @@ abstract class AdminTabCore
{
foreach ($languages as $language)
if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false && (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
$this->_errors[] = sprintf(Tools::displayError('field %s is required.'), $values['title']);
}
elseif (($value = Tools::getValue($field)) == false && (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
$this->_errors[] = sprintf(Tools::displayError('field %s is required.'), $values['title']);
/* Check fields validity */
foreach ($fields as $field => $values)
@@ -974,11 +975,11 @@ abstract class AdminTabCore
foreach ($languages as $language)
if (Tools::getValue($field.'_'.$language['id_lang']) && isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang'])))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
$this->_errors[] = sprintf(Tools::displayError('field %s is invalid.'), $values['title']);
}
elseif (Tools::getValue($field) && isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field)))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
$this->_errors[] = sprintf(Tools::displayError('field %s is invalid.'), $values['title']);
/* Default value if null */
foreach ($fields as $field => $values)
+11 -3
View File
@@ -216,11 +216,15 @@ class ImageManagerCore
public static function validateUpload($file, $max_file_size = 0)
{
if ((int)$max_file_size > 0 && $file['size'] > (int)$max_file_size)
return Tools::displayError('Image is too large').' ('.($file['size'] / 1000).Tools::displayError('kB').'). '.Tools::displayError('Maximum allowed:').' '.($max_file_size / 1000).Tools::displayError('kB');
return sprintf(
Tools::displayError('Image is too large (%1$d kB). Maximum allowed: %2$d kB'),
$file['size'] / 1000,
$max_file_size / 1000
);
if (!ImageManager::isRealImage($file['tmp_name'], $file['type']))
return Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png');
if ($file['error'])
return Tools::displayError('Error while uploading image; please change your server\'s settings.').'('.Tools::displayError('Error code:').$file['error'].')';
return sprintf(Tools::displayError('Error while uploading image; please change your server\'s settings. (Error code: %s)'), $file['error']);
return false;
}
@@ -234,7 +238,11 @@ class ImageManagerCore
public static function validateIconUpload($file, $max_file_size = 0)
{
if ((int)$max_file_size > 0 && $file['size'] > $max_file_size)
return Tools::displayError('Image is too large').' ('.($file['size'] / 1000).'ko). '.Tools::displayError('Maximum allowed:').' '.($max_file_size / 1000).'ko';
return sprintf(
Tools::displayError('Image is too large (%1$d kB). Maximum allowed: %2$d kB'),
$file['size'] / 1000,
$max_file_size / 1000
);
if (substr($file['name'], -4) != '.ico')
return Tools::displayError('Image format not recognized, allowed formats are: .ico');
if ($file['error'])
+5 -2
View File
@@ -867,8 +867,11 @@ abstract class ObjectModelCore
// Checking for maximum fields sizes
if (isset($data['size']) && ($value = Tools::getValue($field, $this->{$field})) && Tools::strlen($value) > $data['size'])
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is too long.')
.' ('.Tools::displayError('Maximum length:').' '.$data['size'].')';
$errors[] = sprintf(
Tools::displayError('%1$s is too long. Maximum length: %2$d'),
self::displayFieldName($field, get_class($this), $htmlentities),
$data['size']
);
// Checking for fields validity
// Hack for postcode required for country which does not have postcodes
+1 -1
View File
@@ -289,7 +289,7 @@ abstract class PaymentModuleCore extends Module
$customization_text .= $text['name'].': '.$text['value'].'<br />';
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
$customization_text .= count($customization['datas'][Product::CUSTOMIZE_FILE]).' '.Tools::displayError('image(s)').'<br />';
$customization_text .= sprintf(Tools::displayError('%d image(s)'), count($customization['datas'][Product::CUSTOMIZE_FILE])).'<br />';
$customization_text .= '---<br />';
}
+12 -12
View File
@@ -871,10 +871,10 @@ class AdminControllerCore extends Controller
{
foreach ($languages as $language)
if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false && (string)$value != '0')
$this->errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
$this->errors[] = sprintf(Tools::displayError('field %s is required.'), $values['title']);
}
elseif (($value = Tools::getValue($field)) == false && (string)$value != '0')
$this->errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
$this->errors[] = sprintf(Tools::displayError('field %s is required.'), $values['title']);
// Check field validator
if (isset($values['type']) && $values['type'] == 'textLang')
@@ -882,11 +882,11 @@ class AdminControllerCore extends Controller
foreach ($languages as $language)
if (Tools::getValue($field.'_'.$language['id_lang']) && isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang'])))
$this->errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
$this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $values['title']);
}
elseif (Tools::getValue($field) && isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field)))
$this->errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
$this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $values['title']);
// Set default value
if (Tools::getValue($field) === false && isset($values['default']))
@@ -2157,7 +2157,7 @@ class AdminControllerCore extends Controller
if (($value = Tools::getValue($field)) == false && (string)$value != '0')
if (!Tools::getValue($this->identifier) || ($field != 'passwd' && $field != 'no-picture'))
$this->errors[] = sprintf(
$this->l('The field %s is required.'),
Tools::displayError('The field %s is required.'),
call_user_func(array($class_name, 'displayFieldName'), $field, $class_name)
);
@@ -2165,7 +2165,7 @@ class AdminControllerCore extends Controller
foreach ($rules['requiredLang'] as $field_lang)
if (($empty = Tools::getValue($field_lang.'_'.$default_language->id)) === false || $empty !== '0' && empty($empty))
$this->errors[] = sprintf(
$this->l('The field %s is required at least in %s.'),
Tools::displayError('The field %1$s is required at least in %2$s.'),
call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name),
$default_language->name
);
@@ -2174,7 +2174,7 @@ class AdminControllerCore extends Controller
foreach ($rules['size'] as $field => $max_length)
if (Tools::getValue($field) !== false && Tools::strlen(Tools::getValue($field)) > $max_length)
$this->errors[] = sprintf(
$this->l('The field %s is too long (%d chars max).'),
Tools::displayError('The field %1$s is too long (%2$d chars max).'),
call_user_func(array($class_name, 'displayFieldName'), $field, $class_name),
$max_length
);
@@ -2186,7 +2186,7 @@ class AdminControllerCore extends Controller
$field_lang = Tools::getValue($field_lang.'_'.$language['id_lang']);
if ($field_lang !== false && Tools::strlen($field_lang) > $max_length)
$this->errors[] = sprintf(
$this->l('The field %s (%s) is too long (%d chars max, html chars including).'),
Tools::displayError('The field %1$s (%2$s) is too long (%3$d chars max, html chars including).'),
call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name),
$language['name'],
$max_length
@@ -2200,7 +2200,7 @@ class AdminControllerCore extends Controller
if (($value = Tools::getValue($field)) !== false && ($field != 'passwd'))
if (!Validate::$function($value) && !empty($value))
$this->errors[] = sprintf(
$this->l('The field %s is invalid.'),
Tools::displayError('The field %s is invalid.'),
call_user_func(array($class_name, 'displayFieldName'), $field, $class_name)
);
@@ -2209,12 +2209,12 @@ class AdminControllerCore extends Controller
{
if ($class_name == 'Employee' && !Validate::isPasswdAdmin($value))
$this->errors[] = sprintf(
$this->l('The field %s is invalid.'),
Tools::displayError('The field %s is invalid.'),
call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name)
);
elseif ($class_name == 'Customer' && !Validate::isPasswd($value))
$this->errors[] = sprintf(
$this->l('The field %s is invalid.'),
Tools::displayError('The field %s is invalid.'),
call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name)
);
}
@@ -2225,7 +2225,7 @@ class AdminControllerCore extends Controller
if (($value = Tools::getValue($field_lang.'_'.$language['id_lang'])) !== false && !empty($value))
if (!Validate::$function($value))
$this->errors[] = sprintf(
$this->l('The field %s (%s) is invalid.'),
Tools::displayError('The field %1$s (%2$s) is invalid.'),
call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name),
$language['name']
);
+5 -2
View File
@@ -287,8 +287,11 @@ class SupplyOrderDetailCore extends ObjectModel
/* Checks maximum fields sizes */
foreach ($this->fieldsSize as $field => $max_length)
if ($value = $this->{$field} && Tools::strlen($value) > $max_length)
$errors[] = '<b>'.SupplyOrderDetail::displayFieldName($field, get_class($this), $htmlentities)
.'</b> '.Tools::displayError('is too long.').' ('.Tools::displayError('Maximum length:').' '.$max_length.')';
$errors[] = sprintf(
Tools::displayError('%1$s is too long. Maximum length: %2$d'),
SupplyOrderDetail::displayFieldName($field, get_class($this), $htmlentities),
$max_length
);
/* Checks fields validity */
foreach ($this->fieldsValidate as $field => $function)