summaryrefslogtreecommitdiffstats
path: root/system/libraries/Form_validation.php
diff options
context:
space:
mode:
authorRick Ellis <rick.ellis@ellislab.com>2008-09-20 05:42:20 +0200
committerRick Ellis <rick.ellis@ellislab.com>2008-09-20 05:42:20 +0200
commit277451a42c8fac9c4dfc8f4d4c54e0e7a19e0dc1 (patch)
treee9756955e86bda8d4e92892b917c6740d307daac /system/libraries/Form_validation.php
parent28c90a30caddf029aed48b30af097b7f26bb2b8d (diff)
Added the ability to set translatable field names
Diffstat (limited to 'system/libraries/Form_validation.php')
-rw-r--r--system/libraries/Form_validation.php34
1 files changed, 29 insertions, 5 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c2749a0cf..1ba98bef4 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -504,11 +504,11 @@ class CI_Form_validation {
}
else
{
- $line = $this->_error_messages['isset'];
+ $line = $this->_translate_fieldname('isset');
}
// Build the error message
- $message = sprintf($line, $row['label']);
+ $message = sprintf($line, $this->_translate_fieldname($row['label']));
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
@@ -646,11 +646,11 @@ class CI_Form_validation {
}
else
{
- $line = $this->_error_messages[$rule];
+ $line = $this->_translate_fieldname($rule);
}
// Build the error message
- $message = sprintf($line, $row['label'], $param);
+ $message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
@@ -663,7 +663,31 @@ class CI_Form_validation {
return;
}
}
- }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Translate a field name
+ *
+ * @access private
+ * @param string the field name
+ * @return string
+ */
+ function _translate_fieldname($fieldname)
+ {
+ // Do we need to translate the field name?
+ // We look for the prefix lang: to determine this
+ if (substr($fieldname, 0, 5) == 'lang:')
+ {
+ $label = $this->CI->lang->line(substr($fieldname, 5));
+
+ // Were we able to translate the field name?
+ $fieldname = ($label === FALSE) ? substr($fieldname, 5) : $label;
+ }
+
+ return $fieldname;
+ }
// --------------------------------------------------------------------