Skip to content
Permalink
Browse files

Remove i18n::defaultFallbackDomain(), rename i18n:: useTranslationFal…

…lback()

Refs: #6812
  • Loading branch information...
Schlaefer committed Jun 16, 2015
1 parent 99b5c7d commit 495a6fd06939986e46b101cbd790a901228396f6
Showing with 10 additions and 78 deletions.
  1. +3 −17 src/I18n/I18n.php
  2. +6 −30 src/I18n/TranslatorRegistry.php
  3. +1 −31 tests/TestCase/I18n/I18nTest.php
@@ -237,20 +237,6 @@ public static function defaultLocale()
return static::$_defaultLocale;
}
/**
* Set default fallback domain. If a domain can't provide a translation
* messages from the fallback domain are used.
*
* Get the currently set domain if argument is null.
*
* @param string|null $name name of the fallback-translator
* @return string
*/
public static function defaultFallbackDomain($name = null)
{
return static::translators()->defaultFallbackDomain($name);
}
/**
* Sets the name of the default messages formatter to use for future
* translator instances. By default the `default` and `sprintf` formatters
@@ -267,14 +253,14 @@ public static function defaultFormatter($name = null)
}
/**
* Set if the default domain fallback is used.
* Set if the domain fallback is used.
*
* @param bool $enable flag to enable or disable fallback
* @return void
*/
public static function useTranslationFallback($enable = true)
public static function useFallback($enable = true)
{
static::translators()->useTranslationFallback($enable);
static::translators()->useFallback($enable);
}
/**
@@ -42,13 +42,6 @@ class TranslatorRegistry extends TranslatorLocator
*/
protected $_defaultFormatter = 'default';
/**
* Domain used as fallback if translation isn't found in original domain
*
* @var string
*/
protected $_defaultFallbackDomain = 'default';
/**
* Enable translation fallback
*
@@ -168,31 +161,13 @@ public function defaultFormatter($name = null)
return $this->_defaultFormatter = $name;
}
/**
* Set fallback domain. Messages from the fallback domain are used if
* a domain can't provide a localization message.
*
* Get the currently set domain if argument is null.
*
* @param string|null $name fallback domain
* @return string
*/
public function defaultFallbackDomain($name = null)
{
if ($name === null) {
return $this->_defaultFallbackDomain;
}
return $this->_defaultFallbackDomain = $name;
}
/**
* Set if the default domain fallback is used.
*
* @param bool $enable flag to enable or disable fallback
* @return void
*/
public function useTranslationFallback($enable = true)
public function useFallback($enable = true)
{
$this->_fallback = $enable;
}
@@ -264,19 +239,20 @@ protected function _getFromLoader($name, $locale)
/**
* Set domain fallback for loader.
*
* @param string $name The name of the fallback domain
* @param string $name The name of the loader domain
* @param callable $loader invokable loader
* @return callable loader
*/
public function setLoaderFallback($name, callable $loader)
{
if (!$this->_fallback || $name === $this->_defaultFallbackDomain) {
$fallbackDomain = 'default';
if (!$this->_fallback || $name === $fallbackDomain) {
return $loader;
}
$loader = function () use ($loader) {
$loader = function () use ($loader, $fallbackDomain) {
$package = $loader();
if (!$package->getFallback()) {
$package->setFallback($this->_defaultFallbackDomain);
$package->setFallback($fallbackDomain);
}
return $package;
};
@@ -520,7 +520,7 @@ public function testFallbackTranslator()
*/
public function testFallbackTranslatorDisabled()
{
I18n::useTranslationFallback(false);
I18n::useFallback(false);
I18n::translator('default', 'fr_FR', function () {
$package = new Package('default');
@@ -539,36 +539,6 @@ public function testFallbackTranslatorDisabled()
$this->assertEquals('Dog', $translator->translate('Dog'));
}
/**
* Test that a different fallback domain can be set
*
* @return void
*/
public function testFallbackTranslatorSetFallbackDomain()
{
$this->assertEquals('default', I18n::defaultFallbackDomain());
$fallbackDomain = 'foo';
I18n::defaultFallbackDomain($fallbackDomain);
$this->assertEquals($fallbackDomain, I18n::defaultFallbackDomain());
I18n::translator($fallbackDomain, 'fr_FR', function () {
$package = new Package('default');
$package->setMessages(['Dog' => 'Le bark']);
return $package;
});
I18n::translator('custom', 'fr_FR', function () {
$package = new Package('default');
$package->setMessages(['Cow' => 'Le moo']);
return $package;
});
$translator = I18n::translator('custom', 'fr_FR');
$this->assertEquals('Le moo', $translator->translate('Cow'));
$this->assertEquals('Le bark', $translator->translate('Dog'));
}
/**
* Tests that it is possible to register a generic translators factory for a domain
* instead of having to create them manually

0 comments on commit 495a6fd

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