Commit 5643daa6 authored by Taylor Otwell's avatar Taylor Otwell

Refactor Lang class.

parent e2973e56
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment