Fixed variable name used in translation cache
This commit is contained in:
parent
c875d0aae1
commit
b272419ab9
|
@ -45,13 +45,15 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$translator = $this->getTranslator($this->getLoader());
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocale(array('en', 'es'));
|
||||
$translator->setFallbackLocale(array('en', 'es', 'pt-PT', 'pt_BR'));
|
||||
|
||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||
}
|
||||
|
||||
public function testTransWithCaching()
|
||||
|
@ -59,25 +61,29 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||
// prime the cache
|
||||
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir));
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocale(array('en', 'es'));
|
||||
$translator->setFallbackLocale(array('en', 'es', 'pt-PT', 'pt_BR'));
|
||||
|
||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||
|
||||
// do it another time as the cache is primed now
|
||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocale(array('en', 'es'));
|
||||
$translator->setFallbackLocale(array('en', 'es', 'pt-PT', 'pt_BR'));
|
||||
|
||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||
}
|
||||
|
||||
public function testGetLocale()
|
||||
|
@ -155,6 +161,20 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||
'foobar' => 'foobar (ES)',
|
||||
))))
|
||||
;
|
||||
$loader
|
||||
->expects($this->at(3))
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('pt-PT', array(
|
||||
'foobarfoo' => 'foobarfoo (PT-PT)',
|
||||
))))
|
||||
;
|
||||
$loader
|
||||
->expects($this->at(4))
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('pt_BR', array(
|
||||
'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)',
|
||||
))))
|
||||
;
|
||||
|
||||
return $loader;
|
||||
}
|
||||
|
@ -183,6 +203,8 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||
$translator->addResource('loader', 'foo', 'fr');
|
||||
$translator->addResource('loader', 'foo', 'en');
|
||||
$translator->addResource('loader', 'foo', 'es');
|
||||
$translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese
|
||||
$translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese
|
||||
|
||||
return $translator;
|
||||
}
|
||||
|
|
|
@ -98,6 +98,8 @@ class Translator extends BaseTranslator
|
|||
$fallbackContent = '';
|
||||
$current = '';
|
||||
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
||||
$fallbackSuffix = ucfirst(str_replace('-', '_', $fallback));
|
||||
|
||||
$fallbackContent .= sprintf(<<<EOF
|
||||
\$catalogue%s = new MessageCatalogue('%s', %s);
|
||||
\$catalogue%s->addFallbackCatalogue(\$catalogue%s);
|
||||
|
@ -105,11 +107,11 @@ class Translator extends BaseTranslator
|
|||
|
||||
EOF
|
||||
,
|
||||
ucfirst($fallback),
|
||||
$fallbackSuffix,
|
||||
$fallback,
|
||||
var_export($this->catalogues[$fallback]->all(), true),
|
||||
ucfirst($current),
|
||||
ucfirst($fallback)
|
||||
ucfirst(str_replace('-', '_', $current)),
|
||||
$fallbackSuffix
|
||||
);
|
||||
$current = $fallback;
|
||||
}
|
||||
|
|
Reference in New Issue