public function getTranslation(string $key, string $locale = null)
    {
        $this->throwExceptionIfAttributeIsNotTranslatable($key);

        $translations = $this->getTranslations($key);

        if (count($translations)) {
            $locale = $locale ?: config('app.locale');

            if (isset($translations[$locale])) {
                $translation = $translations[$locale];
            } else {
                $translation = $translations[$this->getDefaultLocale()] ?? head($translations);
            }

        } else {
            $translation = null;
        }

        if ($this->hasGetMutator($key)) {
            return $this->mutateAttribute($key, $translation);
        }

        return $translation;
    }
public function getTranslation(string $key, string $locale = null)
    {
        $this->throwExceptionIfAttributeIsNotTranslatable($key);

        $translations = $this->getTranslations($key);

        if (count($translations)) {
            $locale = $locale ?: config('app.locale');

            if (isset($translations[$locale])) {
                $translation = $translations[$locale];
            } else {
                $translation = $translations[$this->getDefaultLocale()] ?? head($translations);
            }

        } else {
            $translation = null;
        }

        if ($this->hasGetMutator($key)) {
            return $this->mutateAttribute($key, $translation);
        }

        return $translation;
    }
public function getTranslation ( string $ key , string $ locale = null ) { $ this -> throwExceptionIfAttributeIsNotTranslatable ( $ key ) ; $ translations = $ this -> getTranslations ( $ key ) ; if ( count ( $ translations ) ) { $ locale = $ locale ? : config ( 'app.locale' ) ; if ( isset ( $ translations [ $ locale ] ) ) { $ translation = $ translations [ $ locale ] ; } else { $ translation = $ translations [ $ this -> getDefaultLocale ( ) ] ?? head ( $ translations ) ; } } else { $ translation = null ; } if ( $ this -> hasGetMutator ( $ key ) ) { return $ this -> mutateAttribute ( $ key , $ translation ) ; } return $ translation ; }
Get attribute translation.

@param  string      $key
@param  string|null $locale
@return mixed
Get attribute translation .