merged branch cedric-g/patch_translator (PR #8310)
This PR was submitted for the 2.3 branch but it was merged into the 2.2 branch instead (closes #8310). Discussion ---------- [FrameworkBundle] Fixed variable name used in translation cache This simply fixes the `$catalogueXXX` variable name used in the translation cache files in case the user use locales such as `en-US`, the generated variable's name was `$catalogueEn-Us`, with this fix it will be `$catalogueEnUs`. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7824 | License | MIT | Doc PR | - Commits ------- e50399c [FrameworkBundle] Fixed variable name used in translation cache
This commit is contained in:
commit
1a0b38a48a
@ -45,13 +45,15 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$translator = $this->getTranslator($this->getLoader());
|
$translator = $this->getTranslator($this->getLoader());
|
||||||
$translator->setLocale('fr');
|
$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('foo (FR)', $translator->trans('foo'));
|
||||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
$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()
|
public function testTransWithCaching()
|
||||||
@ -59,25 +61,29 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
// prime the cache
|
// prime the cache
|
||||||
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir));
|
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir));
|
||||||
$translator->setLocale('fr');
|
$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('foo (FR)', $translator->trans('foo'));
|
||||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
$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
|
// do it another time as the cache is primed now
|
||||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
||||||
$translator->setLocale('fr');
|
$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('foo (FR)', $translator->trans('foo'));
|
||||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
$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()
|
public function testGetLocale()
|
||||||
@ -155,6 +161,20 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'foobar' => 'foobar (ES)',
|
'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;
|
return $loader;
|
||||||
}
|
}
|
||||||
@ -183,6 +203,8 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$translator->addResource('loader', 'foo', 'fr');
|
$translator->addResource('loader', 'foo', 'fr');
|
||||||
$translator->addResource('loader', 'foo', 'en');
|
$translator->addResource('loader', 'foo', 'en');
|
||||||
$translator->addResource('loader', 'foo', 'es');
|
$translator->addResource('loader', 'foo', 'es');
|
||||||
|
$translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese
|
||||||
|
$translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese
|
||||||
|
|
||||||
return $translator;
|
return $translator;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,8 @@ class Translator extends BaseTranslator
|
|||||||
$fallbackContent = '';
|
$fallbackContent = '';
|
||||||
$current = '';
|
$current = '';
|
||||||
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
||||||
|
$fallbackSuffix = ucfirst(str_replace('-', '_', $fallback));
|
||||||
|
|
||||||
$fallbackContent .= sprintf(<<<EOF
|
$fallbackContent .= sprintf(<<<EOF
|
||||||
\$catalogue%s = new MessageCatalogue('%s', %s);
|
\$catalogue%s = new MessageCatalogue('%s', %s);
|
||||||
\$catalogue%s->addFallbackCatalogue(\$catalogue%s);
|
\$catalogue%s->addFallbackCatalogue(\$catalogue%s);
|
||||||
@ -105,11 +107,11 @@ class Translator extends BaseTranslator
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
,
|
,
|
||||||
ucfirst($fallback),
|
$fallbackSuffix,
|
||||||
$fallback,
|
$fallback,
|
||||||
var_export($this->catalogues[$fallback]->all(), true),
|
var_export($this->catalogues[$fallback]->all(), true),
|
||||||
ucfirst($current),
|
ucfirst(str_replace('-', '_', $current)),
|
||||||
ucfirst($fallback)
|
$fallbackSuffix
|
||||||
);
|
);
|
||||||
$current = $fallback;
|
$current = $fallback;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user