/** * @param string $key * @param mixed $default * * @return mixed */ protected function translate($key, $default = false) { $string = $this->translator->get($key); if ($default !== false) { if ($string == $key) { return $default; } } return $string; }
/** * Get the displayable name of the attribute. * * @param string $attribute * @return string */ protected function getAttribute($attribute) { $primaryAttribute = $this->getPrimaryAttribute($attribute); $expectedAttributes = $attribute != $primaryAttribute ? [$attribute, $primaryAttribute] : [$attribute]; foreach ($expectedAttributes as $expectedAttributeName) { // The developer may dynamically specify the array of custom attributes // on this Validator instance. If the attribute exists in this array // it takes precedence over all other ways we can pull attributes. if (isset($this->customAttributes[$expectedAttributeName])) { return $this->customAttributes[$expectedAttributeName]; } $line = Arr::get($this->translator->get('validation.attributes'), $expectedAttributeName); // We allow for the developer to specify language lines for each of the // attributes allowing for more displayable counterparts of each of // the attributes. This provides the ability for simple formats. if ($line) { return $line; } } // When no language line has been specified for the attribute and it is // also an implicit attribute we will display the raw attribute name // and not modify it with any replacements before we display this. if (isset($this->implicitAttributes[$primaryAttribute])) { return $attribute; } return str_replace('_', ' ', Str::snake($attribute)); }
/** * Return the value of input key in the set locale input file (without extension). * * @param string $fileName * @param string $key * @throws InvalidFileNameException * * @return string */ public function getLanguageFileKey($fileName, $key) { // Check the input file name if (!$this->checkFileName($fileName)) { throw new InvalidFileNameException("Input file name is not valid."); } return $this->translator->get("{$fileName}.{$key}"); }