mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
Refactor Lang class.
This commit is contained in:
parent
e2973e565d
commit
5643daa66c
@ -61,31 +61,16 @@ class Lang {
|
||||
|
||||
$this->load($file, $language);
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// If the language file did not exist, return the default value.
|
||||
// --------------------------------------------------------------
|
||||
if ( ! array_key_exists($language.$file, static::$lines))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Get the language line from the appropriate file array.
|
||||
// If the line doesn't exist, return the default value.
|
||||
// --------------------------------------------------------------
|
||||
if (array_key_exists($line, static::$lines[$language.$file]))
|
||||
{
|
||||
$line = static::$lines[$language.$file][$line];
|
||||
// The language file doesn't exist, return the default value.
|
||||
$line = is_callable($default) ? call_user_func($default) : $default;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $default;
|
||||
$line = Arr::get(static::$lines[$language.$file], $line, $default);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Make all place-holder replacements. Place-holders are prefixed
|
||||
// with a colon for convenient location.
|
||||
// --------------------------------------------------------------
|
||||
foreach ($this->replacements as $key => $value)
|
||||
{
|
||||
$line = str_replace(':'.$key, $value, $line);
|
||||
@ -102,10 +87,8 @@ class Lang {
|
||||
*/
|
||||
private function parse($key)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// The left side of the dot is the file name, while the right
|
||||
// side of the dot is the item within that file being requested.
|
||||
// --------------------------------------------------------------
|
||||
// The left side of the dot is the file name, while the right side of the dot
|
||||
// is the item within that file being requested.
|
||||
$segments = explode('.', $key);
|
||||
|
||||
if (count($segments) < 2)
|
||||
@ -125,10 +108,7 @@ class Lang {
|
||||
*/
|
||||
private function load($file, $language)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// If we have already loaded the language file or the file
|
||||
// doesn't exist, bail out.
|
||||
// --------------------------------------------------------------
|
||||
// If we have already loaded the language file or the file doesn't exist, bail out.
|
||||
if (array_key_exists($language.$file, static::$lines) or ! file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT))
|
||||
{
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user