/**
  * Returns the error messages. If no file is specified, the error message
  * will be the name of the rule that failed. When a file is specified, the
  * message will be loaded from "field/rule", or if no rule-specific message
  * exists, "field/default" will be used. If neither is set, the returned
  * message will be "file/field/rule".
  *
  * By default all messages are translated using the default language.
  * A string can be used as the second parameter to specified the language
  * that the message was written in.
  *
  *     // Get errors from messages/forms/login.php
  *     $errors = $Validation->errors('forms/login');
  *
  * @uses    JsonApiApplication::message
  * @param   string  $file       file to load error messages from
  * @param   mixed   $translate  translate the message
  * @return  array
  */
 public function errors($file = NULL, $translate = TRUE)
 {
     if ($file === NULL) {
         return $this->_errors;
     }
     $messages = array();
     foreach ($this->_errors as $field => $set) {
         list($error, $params) = $set;
         $label = $this->_labels[$field];
         if ($translate) {
             if (is_string($translate)) {
                 $label = __($label, NULL, $translate);
             } else {
                 $label = __($label);
             }
         }
         $values = array(':field' => $label, ':value' => Arr::get($this, $field));
         if (is_array($values[':value'])) {
             $values[':value'] = implode(', ', Arr::flatten($values[':value']));
         }
         if ($params) {
             foreach ($params as $key => $value) {
                 if (is_array($value)) {
                     $value = implode(', ', Arr::flatten($value));
                 } elseif (is_object($value)) {
                     continue;
                 }
                 if (isset($this->_labels[$value])) {
                     $value = $this->_labels[$value];
                     if ($translate) {
                         if (is_string($translate)) {
                             $value = __($value, NULL, $translate);
                         } else {
                             $value = __($value);
                         }
                     }
                 }
                 $values[':param' . ($key + 1)] = $value;
             }
         }
         if ($message = JsonApiApplication::message($file, "{$field}.{$error}") and is_string($message)) {
         } elseif ($message = JsonApiApplication::message($file, "{$field}.default") and is_string($message)) {
         } elseif ($message = JsonApiApplication::message($file, $error) and is_string($message)) {
             // Found a default message for this error
         } elseif ($message = JsonApiApplication::message('validation', $error) and is_string($message)) {
             // Found a default message for this error
         } else {
             // No message exists, display the path expected
             $message = "{$file}.{$field}.{$error}";
         }
         if ($translate) {
             if (is_string($translate)) {
                 $message = __($message, $values, $translate);
             } else {
                 $message = __($message, $values);
             }
         } else {
             $message = strtr($message, $values);
         }
         $messages[$field] = $message;
     }
     return $messages;
 }