Skip to content
Permalink
Browse files

Throw exception indicating translator cache must be cleared

Fix #10115
  • Loading branch information...
JoepRoebroek committed Jan 31, 2017
1 parent f11fe6a commit 049c54e7872e144b62ad5e26c95e31fb47028753
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/I18n/TranslatorFactory.php
@@ -17,6 +17,7 @@
use Aura\Intl\FormatterInterface;
use Aura\Intl\TranslatorFactory as BaseTranslatorFactory;
use Aura\Intl\TranslatorInterface;
use Cake\Core\Exception\Exception;
/**
* Factory to create translators
@@ -31,4 +32,31 @@ class TranslatorFactory extends BaseTranslatorFactory
* @var string
*/
protected $class = 'Cake\I18n\Translator';
/**
* Returns a new Translator.
* @param string $locale The locale code for the translator.
* @param array $messages The localized messages for the translator.
* @param FormatterInterface $formatter The formatter to use for
* interpolating token values.
* @param TranslatorInterface $fallback A fallback translator to use, if
* any.
* @throws \Cake\Core\Exception\Exception If fallback class does not match Cake\I18n\Translator
* @return Translator
*/
public function newInstance(
$locale,
array $messages,
FormatterInterface $formatter,
TranslatorInterface $fallback = null
) {
$class = $this->class;
if ($fallback !== null && get_class($fallback) !== $class) {
throw new Exception(sprintf(
'Translator fallback class %s does not match Cake\I18n\Translator, try clearing your _cake_core_ cache.',
get_class($fallback)
));
}
return new $class($locale, $messages, $formatter, $fallback);
}
}

0 comments on commit 049c54e

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