Skip to content
Permalink
Browse files

make fallback loader just a special name loader

  • Loading branch information...
andrej-griniuk committed Aug 14, 2016
1 parent 3965f76 commit da47cd4c353dd65d6c80637218e773f78457618c
Showing with 7 additions and 30 deletions.
  1. +0 −12 src/I18n/I18n.php
  2. +6 −17 src/I18n/TranslatorRegistry.php
  3. +1 −1 tests/TestCase/I18n/I18nTest.php
@@ -200,18 +200,6 @@ public static function config($name, callable $loader)
static::translators()->registerLoader($name, $loader);
}
/**
* Registers a fallback translator loader
*
* @param callable $loader A callable object that should return a Package
* instance to be used for assembling a new translator.
* @return void
*/
public static function fallbackConfig(callable $loader)
{
static::translators()->setFallbackLoader($loader);
}
/**
* Sets the default locale to use for future translator instances.
* This also affects the `intl.default_locale` PHP setting.
@@ -36,14 +36,14 @@ class TranslatorRegistry extends TranslatorLocator
*
* @var array
*/
protected $_loaders;
public $_loaders;
/**
* Fallback loader
* Fallback loader name
*
* @var callable
* @var string
*/
protected $_fallbackLoader;
protected $_fallbackLoader = '_fallback';
/**
* The name of the default formatter to use for newly created
@@ -90,7 +90,7 @@ public function __construct(
) {
parent::__construct($packages, $formatters, $factory, $locale);
$this->setFallbackLoader(function ($name, $locale) {
$this->registerLoader($this->_fallbackLoader, function ($name, $locale) {
$chain = new ChainMessagesLoader([
new MessagesFileLoader($name, $locale, 'mo'),
new MessagesFileLoader($name, $locale, 'po')
@@ -198,17 +198,6 @@ public function registerLoader($name, callable $loader)
$this->_loaders[$name] = $loader;
}
/**
* Set fallback loader function
*
* @param callable $loader A callable object that should return a Package
* @return void
*/
public function setFallbackLoader(callable $loader)
{
$this->_fallbackLoader = $loader;
}
/**
* Sets the name of the default messages formatter to use for future
* translator instances.
@@ -248,7 +237,7 @@ public function useFallback($enable = true)
*/
protected function _fallbackLoader($name, $locale)
{
return call_user_func($this->_fallbackLoader, $name, $locale);
return $this->_loaders[$this->_fallbackLoader]($name, $locale);
}
/**
@@ -517,7 +517,7 @@ public function testLoaderFactory()
*/
public function testFallbackLoaderFactory()
{
I18n::fallbackConfig(function ($name) {
I18n::config('_fallback', function ($name) {
$package = new Package('default');
if ($name == 'custom') {

0 comments on commit da47cd4

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