Skip to content
Permalink
Browse files

rename methods and properties

  • Loading branch information...
andrej-griniuk committed Aug 14, 2016
1 parent de8a33c commit 6700abb1725f4f94fcda36c4a70084514679a2d2
Showing with 53 additions and 27 deletions.
  1. +2 −2 src/I18n/I18n.php
  2. +51 −25 src/I18n/TranslatorRegistry.php
@@ -201,15 +201,15 @@ public static function config($name, callable $loader)
}
/**
* Registers a custom fallback translator 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()->setCustomFallbackLoader($loader);
static::translators()->setFallbackLoader($loader);
}
/**
@@ -15,6 +15,9 @@
namespace Cake\I18n;
use Aura\Intl\Exception;
use Aura\Intl\FormatterLocator;
use Aura\Intl\PackageLocator;
use Aura\Intl\TranslatorFactory;
use Aura\Intl\TranslatorLocator;
use Cake\Cache\CacheEngine;
@@ -36,11 +39,11 @@ class TranslatorRegistry extends TranslatorLocator
protected $_loaders;
/**
* Custom fallback loader
* Fallback loader
*
* @var callable
*/
protected $_customFallbackLoader;
protected $_fallbackLoader;
/**
* The name of the default formatter to use for newly created
@@ -65,6 +68,48 @@ class TranslatorRegistry extends TranslatorLocator
*/
protected $_cacher;
/**
*
* Constructor.
*
* @param PackageLocator $packages The package locator.
*
* @param FormatterLocator $formatters The formatter locator.
*
* @param TranslatorFactory $factory A translator factory to
* create translator objects for the locale and package.
*
* @param string $locale The default locale code to use.
*
*/
public function __construct(
PackageLocator $packages,
FormatterLocator $formatters,
TranslatorFactory $factory,
$locale
) {
parent::__construct($packages, $formatters, $factory, $locale);
$this->setFallbackLoader(function($name, $locale) {
$chain = new ChainMessagesLoader([
new MessagesFileLoader($name, $locale, 'mo'),
new MessagesFileLoader($name, $locale, 'po')
]);
// \Aura\Intl\Package by default uses formatter configured with key "basic".
// and we want to make sure the cake domain always uses the default formatter
$formatter = $name === 'cake' ? 'default' : $this->_defaultFormatter;
$chain = function () use ($formatter, $chain) {
$package = $chain();
$package->setFormatter($formatter);
return $package;
};
return $chain;
});
}
/**
* Sets the CacheEngine instance used to remember translators across
* requests.
@@ -154,14 +199,14 @@ public function registerLoader($name, callable $loader)
}
/**
* Set a custom fallback loader function
* Set fallback loader function
*
* @param callable $loader A callable object that should return a Package
* @return void
*/
public function setCustomFallbackLoader(callable $loader)
public function setFallbackLoader(callable $loader)
{
$this->_customFallbackLoader = $loader;
$this->_fallbackLoader = $loader;
}
/**
@@ -203,26 +248,7 @@ public function useFallback($enable = true)
*/
protected function _fallbackLoader($name, $locale)
{
if ($loader = $this->_customFallbackLoader) {
return $loader($name, $locale);
}
$chain = new ChainMessagesLoader([
new MessagesFileLoader($name, $locale, 'mo'),
new MessagesFileLoader($name, $locale, 'po')
]);
// \Aura\Intl\Package by default uses formatter configured with key "basic".
// and we want to make sure the cake domain always uses the default formatter
$formatter = $name === 'cake' ? 'default' : $this->_defaultFormatter;
$chain = function () use ($formatter, $chain) {
$package = $chain();
$package->setFormatter($formatter);
return $package;
};
return $chain;
return call_user_func($this->_fallbackLoader, $name, $locale);
}
/**

0 comments on commit 6700abb

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