Refactoring the lang class.

This commit is contained in:
Taylor Otwell 2011-08-08 09:11:52 -05:00
parent 2e482d31e4
commit a7116e71f6
1 changed files with 3 additions and 14 deletions

View File

@ -63,10 +63,7 @@ public static function line($key, $replacements = array())
*/ */
public function get($language = null, $default = null) public function get($language = null, $default = null)
{ {
if (is_null($language)) if (is_null($language)) $language = Config::get('application.language');
{
$language = Config::get('application.language');
}
list($module, $file, $line) = $this->parse($this->key, $language); list($module, $file, $line) = $this->parse($this->key, $language);
@ -99,21 +96,13 @@ public function get($language = null, $default = null)
*/ */
private function parse($key, $language) private function parse($key, $language)
{ {
// Check for a module qualifier. If a module name is present, we need to extract it from
// the language line, otherwise, we will use "application" as the module.
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application'; $module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application';
if ($module != 'application') if ($module != 'application') $key = substr($key, strpos($key, ':') + 2);
{
$key = substr($key, strpos($key, ':') + 2);
}
$segments = explode('.', $key); $segments = explode('.', $key);
if (count($segments) > 1) if (count($segments = explode('.', $key)) > 1) return array($module, $segments[0], $segments[1]);
{
return array($module, $segments[0], $segments[1]);
}
throw new \Exception("Invalid language line [$key]. A specific line must be specified."); throw new \Exception("Invalid language line [$key]. A specific line must be specified.");
} }