Skip to content
Permalink
Browse files

consolidate duplicate code from I18n into TranslatorRegistry

  • Loading branch information...
Schlaefer committed Jun 15, 2015
1 parent 464dc9c commit 4a65d92fd2e18f9433a794abe414d0a8952340c3
Showing with 17 additions and 13 deletions.
  1. +2 −10 src/I18n/I18n.php
  2. +15 −3 src/I18n/TranslatorRegistry.php
@@ -118,19 +118,11 @@ public static function translators()
public static function translator($name = 'default', $locale = null, callable $loader = null)
{
if ($loader !== null) {
$packages = static::translators()->getPackages();
$locale = $locale ?: static::locale();
if ($name !== 'default') {
$loader = function () use ($loader) {
$package = $loader();
if (!$package->getFallback()) {
$package->setFallback('default');
}
return $package;
};
}
$loader = static::translators()->setLoaderFallback($name, $loader);
$packages = static::translators()->getPackages();
$packages->set($name, $locale, $loader);
return;
}
@@ -212,6 +212,20 @@ protected function _getFromLoader($name, $locale)
};
}
$loader = $this->setLoaderFallback($name, $loader);
$this->packages->set($name, $locale, $loader);
return parent::get($name, $locale);
}
/**
* set lookup fallback for loader
*
* @param string $name The name of the fallback domain
* @param callable $loader invokable loader
* @return callable loader
*/
public function setLoaderFallback($name, callable $loader) {
if ($name !== 'default') {
$loader = function () use ($loader) {
$package = $loader();
@@ -221,8 +235,6 @@ protected function _getFromLoader($name, $locale)
return $package;
};
}
$this->packages->set($name, $locale, $loader);
return parent::get($name, $locale);
return $loader;
}
}

0 comments on commit 4a65d92

Please sign in to comment.
You can’t perform that action at this time.