Von der sourcecode: Beginnen wir mit der Trans-Funktion, die Sie aufrufen.
/**
* Get the translation for a given key.
*/
public function trans($id, array $parameters = [], $domain = 'messages', $locale = null)
{
return $this->get($id, $parameters, $locale);
}
Die von $ this- genannt get-Funktion> get()
/**
* Get the translation for the given key.
*/
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
list($namespace, $group, $item) = $this->parseKey($key);
// Here we will get the locale that should be used for the language line. If one
// was not passed, we will use the default locales which was given to us when
// the translator was instantiated. Then, we can load the lines and return.
$locales = $fallback ? $this->parseLocale($locale) : [$locale ?: $this->locale];
foreach ($locales as $locale) {
$this->load($namespace, $group, $locale);
$line = $this->getLine(
$namespace, $group, $locale, $item, $replace
);
if (! is_null($line)) {
break;
}
}
// If the line doesn't exist, we will return back the key which was requested as
// that will be quick to spot in the UI if language keys are wrong or missing
// from the application's language files. Otherwise we can return the line.
if (! isset($line)) {
return $key;
}
return $line;
}
Wie Sie hier sehen können:
// If the line doesn't exist, we will return back the key which was requested as
// that will be quick to spot in the UI if language keys are wrong or missing
// from the application's language files. Otherwise we can return the line.
if (! isset($line)) {
return $key;
}
Der Wert keinen gültigen Wert hat, so isset nicht ist übergeben, daher gibt es den $ Schlüsselwert zurück, den Sie angefordert haben.
Um noch weiter zu gehen, können wir uns die folgende Funktion ansehen, die in der get-Funktion aufgerufen wurde.
/**
* Retrieve a language line out the loaded array.
*/
protected function getLine($namespace, $group, $locale, $item, array $replace)
{
$line = Arr::get($this->loaded[$namespace][$group][$locale], $item);
if (is_string($line)) {
return $this->makeReplacements($line, $replace);
} elseif (is_array($line) && count($line) > 0) {
return $line;
}
}
Hier se wir folgendes:
if (is_string($line)) {
Hier werden die Rahmen actualy überprüft, ob der Wert eine Zeichenfolge ist.