merged branch umpirsky/fix-issue-5797 (PR #6331)
This PR was merged into the master branch. Commits -------2196810
Added QtTranslationsLoader tests.201818b
Fixed #5797. Discussion ---------- [Translation] Fixed #5797. This should fix issue #5797. What I did is prevented `Translator` to throw `NotFoundResourceException` if resource is not found and there are fallback locales to process. This happens for locales like `en_GB`, `fr_FR`... I also tested this fix against real application which uses Validation component without full stack framework and I was able to use `en_GB` locale without any errors only after this fix.
This commit is contained in:
commit
5a8534a5db
@ -67,6 +67,36 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foobar', $translator->trans('bar'));
|
$this->assertEquals('foobar', $translator->trans('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getTransFileTests
|
||||||
|
* @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
|
||||||
|
*/
|
||||||
|
public function testTransWithoutFallbackLocaleFile($format, $loader)
|
||||||
|
{
|
||||||
|
$loaderClass = 'Symfony\\Component\\Translation\\Loader\\'.$loader;
|
||||||
|
$translator = new Translator('en', new MessageSelector());
|
||||||
|
$translator->addLoader($format, new $loaderClass());
|
||||||
|
$translator->addResource($format, __DIR__.'/fixtures/non-existing', 'en');
|
||||||
|
$translator->addResource($format, __DIR__.'/fixtures/resources.'.$format, 'en');
|
||||||
|
|
||||||
|
// force catalogue loading
|
||||||
|
$translator->trans('foo');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getTransFileTests
|
||||||
|
*/
|
||||||
|
public function testTransWithFallbackLocaleFile($format, $loader)
|
||||||
|
{
|
||||||
|
$loaderClass = 'Symfony\\Component\\Translation\\Loader\\'.$loader;
|
||||||
|
$translator = new Translator('en_GB', new MessageSelector());
|
||||||
|
$translator->addLoader($format, new $loaderClass());
|
||||||
|
$translator->addResource($format, __DIR__.'/fixtures/non-existing', 'en_GB');
|
||||||
|
$translator->addResource($format, __DIR__.'/fixtures/resources.'.$format, 'en', 'resources');
|
||||||
|
|
||||||
|
$this->assertEquals('bar', $translator->trans('foo', array(), 'resources'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testTransWithFallbackLocaleBis()
|
public function testTransWithFallbackLocaleBis()
|
||||||
{
|
{
|
||||||
$translator = new Translator('en_US', new MessageSelector());
|
$translator = new Translator('en_US', new MessageSelector());
|
||||||
@ -144,6 +174,20 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected, $translator->transChoice($id, $number, $parameters, $domain, $locale));
|
$this->assertEquals($expected, $translator->transChoice($id, $number, $parameters, $domain, $locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTransFileTests()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('csv', 'CsvFileLoader'),
|
||||||
|
array('ini', 'IniFileLoader'),
|
||||||
|
array('mo', 'MoFileLoader'),
|
||||||
|
array('po', 'PoFileLoader'),
|
||||||
|
array('php', 'PhpFileLoader'),
|
||||||
|
array('ts', 'QtTranslationsLoader'),
|
||||||
|
array('xlf', 'XliffFileLoader'),
|
||||||
|
array('yml', 'YamlFileLoader'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function getTransTests()
|
public function getTransTests()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Translation;
|
namespace Symfony\Component\Translation;
|
||||||
|
|
||||||
use Symfony\Component\Translation\Loader\LoaderInterface;
|
use Symfony\Component\Translation\Loader\LoaderInterface;
|
||||||
|
use Symfony\Component\Translation\Exception\NotFoundResourceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translator.
|
* Translator.
|
||||||
@ -181,7 +182,13 @@ class Translator implements TranslatorInterface
|
|||||||
|
|
||||||
protected function loadCatalogue($locale)
|
protected function loadCatalogue($locale)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$this->doLoadCatalogue($locale);
|
$this->doLoadCatalogue($locale);
|
||||||
|
} catch (NotFoundResourceException $e) {
|
||||||
|
if (!$this->computeFallbackLocales($locale)) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->loadFallbackCatalogues($locale);
|
$this->loadFallbackCatalogues($locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user