/**
  * Resolve an error message from the translator.
  *
  * @return string|null
  */
 protected function resolveMessage()
 {
     if (!$this->translator->has($code = "errors.{$this->errorCode}")) {
         return null;
     }
     return $this->translator->trans($code, $this->parameters);
 }
Esempio n. 2
0
 /**
  * @param \LaravelPlus\Extension\Repository\NamespacedRepository $specs
  * @param \Symfony\Component\Translation\TranslatorInterface $translator
  * @param string $path
  */
 public function __construct(NamespacedRepository $specs, TranslatorInterface $translator, $path)
 {
     $rules = $specs->get($path);
     if (is_null($rules)) {
         throw new InvalidArgumentException("spec '{$path}' is not found");
     }
     if (!is_array($rules)) {
         throw new InvalidArgumentException('$rules must array in path ' . $path);
     }
     if (!$translator->has($path)) {
         throw new InvalidArgumentException("translate '{$path}' is not found");
     }
     if (strpos($path, '::') !== false) {
         list($namespace, $path) = explode('::', $path, 2);
     } else {
         $namespace = '';
     }
     $this->path = $path;
     $this->namespace = $namespace;
     $this->rules = $rules;
     $this->translator = new Translator($translator, $namespace);
     $this->resolveSpecReferences();
 }
Esempio n. 3
0
 /**
  * Determine if a translation exists.
  *
  * @param string $key
  * @param string $locale
  * @return bool
  */
 public function has($key, $locale = null)
 {
     return $this->translator->has($this->fullkey($key));
 }