Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
basz committed Nov 12, 2013
1 parent 40fc469 commit 52be614
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/SlmLocale/View/Helper/LocaleMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public function __toString()
$labelLocale = $this->getLabelInCurrentLocale() ? $locale : $current;

$url = $this->getView()->localeUrl($locale);
$title = $this->callLocale($this->getTitleMethod(), $locale, $titleLocale);
$label = $this->callLocale($this->getLabelMethod(), $locale, $labelLocale);
$title = $this->getLocaleProperty($this->getTitleMethod(), $locale, $titleLocale);
$label = $this->getLocaleProperty($this->getLabelMethod(), $locale, $labelLocale);

$item = sprintf(
'<li><a href="%s" title="%s"%s>%s</a></li>' . "\n",
Expand Down Expand Up @@ -297,16 +297,24 @@ protected function checkLocaleMethod($method)
}
}

protected function callLocale($method, $locale, $in_locale = false)
/**
* Retrieves a value by property from Locale
*
* @param $property
* @param $locale
* @param bool $in_locale
* @return mixed
*/
protected function getLocaleProperty($property, $locale, $in_locale = false)
{
$function = sprintf('\Locale::get%s', ucfirst($method));
$callback = sprintf('\Locale::get%s', ucfirst($property));

$args = array($locale);

if ($in_locale && !in_array($method, array('primaryLanguage', 'region', 'script'))) {
if ($in_locale && !in_array($property, array('primaryLanguage', 'region', 'script'))) {
$args[] = $in_locale;
}

return call_user_func_array($function, $args);
return call_user_func_array($callback, $args);
}
}

0 comments on commit 52be614

Please sign in to comment.