Пример #1
0
 /**
  * Returns the models errors with proper messages.
  *
  * @return array
  */
 public function errorMessages()
 {
     $messages = array();
     // Loop over each field
     foreach ($this->errors as $field => $errors) {
         $messages[$field] = array();
         // Loop over the fields errors
         foreach ($errors as $validation => $error) {
             $vars = array_merge(array('field' => Language::translate($field)), $error);
             unset($vars['message']);
             $messages[$field][] = Language::translate($error['message'], $vars);
         }
     }
     return $messages;
 }
Пример #2
0
 /**
  * Translates the passed string.
  *
  * @param string $string       String to translate.
  * @param array  $replacements Replacements to be inserted into the string.
  */
 public function translate($string, array $replacements = [])
 {
     return Language::translate($string, $replacements);
 }
Пример #3
0
 /**
  * @param string $template
  * @param array  $locals
  *
  * @return string
  */
 public function render($template, array $locals = [])
 {
     $templatePath = $this->find($template);
     if (!$templatePath) {
         throw new Exception("Unable to find template [{$template}]");
     }
     // View variables
     $variables = $locals + $this->globals;
     foreach ($variables as $_name => $_value) {
         ${$_name} = $_value;
     }
     // Shortcut for escaping HTML
     $e = function ($string) {
         return htmlspecialchars($string);
     };
     // Shortcut for Language::translate()
     $t = function ($string, array $vars = array()) {
         return Language::translate($string, $vars);
     };
     // Shortcut for Language::date()
     $l = function ($format, $timestamp = null) {
         return Language::date($format, $timestamp);
     };
     ob_start();
     include $templatePath;
     return ob_get_clean();
 }