Skip to content

Commit

Permalink
Adding getCurrentLocaleEntity + Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 19, 2015
1 parent a0523be commit aac20bc
Showing 1 changed file with 39 additions and 51 deletions.
90 changes: 39 additions & 51 deletions src/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,63 +163,77 @@ public function getSupportedLocalesKeys()
}

/**
* Returns current locale name.
* Returns current language.
*
* @return string
*/
public function getCurrentLocale()
{
if ( ! is_null($this->currentLocale)) {
return $this->currentLocale;
}

// Get application default language
if ( ! $this->useAcceptLanguageHeader()) {
return $this->config()->get('app.locale');
}

$negotiator = new Negotiator(
$this->defaultLocale,
$this->getSupportedLocales()
);

return $negotiator->negotiate($this->request());
}

/**
* Returns current language.
*
* @todo: Refactor to Locale Entity
* @return Entities\Locale
*/
public function getCurrentLocaleEntity()
{
return $this->supportedLocales->get($this->getCurrentLocale());
}

/**
* Returns current locale name.
*
* @return string
*/
public function getCurrentLocaleName()
{
/** @var Entities\Locale $locale */
$locale = $this->supportedLocales->get($this->getCurrentLocale());

return $locale->name();
return $this->getCurrentLocaleEntity()->name();
}

/**
* Returns current locale script.
*
* @todo: Refactor to Locale Entity
*
* @return string
*/
public function getCurrentLocaleScript()
{
/** @var Entities\Locale $locale */
$locale = $this->supportedLocales->get($this->getCurrentLocale());

return $locale->script();
return $this->getCurrentLocaleEntity()->script();
}

/**
* Returns current locale direction.
*
* @todo: Refactor to Locale Entity
*
* @return string
*/
public function getCurrentLocaleDirection()
{
/** @var Entities\Locale $locale */
$locale = $this->supportedLocales->get($this->getCurrentLocale());

return $locale->direction();
return $this->getCurrentLocaleEntity()->direction();
}

/**
* Returns current locale native name.
*
* @todo: Refactor to Locale Entity
*
* @return string
*/
public function getCurrentLocaleNative()
{
/** @var Entities\Locale $locale */
$locale = $this->supportedLocales->get($this->getCurrentLocale());

return $locale->native();
return $this->getCurrentLocaleEntity()->native();
}

/**
Expand Down Expand Up @@ -259,32 +273,6 @@ public function setLocale($locale = null)
return $locale;
}

/**
* Returns current language.
*
* @todo: Refactor to Locale entity
*
* @return string
*/
public function getCurrentLocale()
{
if ( ! is_null($this->currentLocale)) {
return $this->currentLocale;
}

// Get application default language
if ( ! $this->useAcceptLanguageHeader()) {
return $this->config()->get('app.locale');
}

$negotiator = new Negotiator(
$this->defaultLocale,
$this->getSupportedLocales()
);

return $negotiator->negotiate($this->request());
}

/**
* Sets the base url for the site.
*
Expand Down Expand Up @@ -534,7 +522,7 @@ public function getUrlFromRouteName($locale, $transKey, $attributes = [])
$route = '';

if (
! ($locale === $this->defaultLocale && $this->hideDefaultLocaleInURL())
! ($locale === $this->defaultLocale && $this->hideDefaultLocaleInURL())
) {
$route = '/' . $locale;
}
Expand Down

0 comments on commit aac20bc

Please sign in to comment.