Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Translation] Revert inlining fallback catalogues as it might cause inconsistent results when a cache is used#14315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aitboudad merged 1 commit intosymfony:2.7fromwebfactory:translator-get-catalogue-inconsistent
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,6 +196,45 @@ public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales(
$this->assertEquals('bar', $translator->trans('bar'));
}

public function testGetCatalogueBehavesConsistently()
{
/*
* Create a translator that loads two catalogues for two different locales.
* The catalogues contain distinct sets of messages.
*/
$translator = new Translator('a', null, $this->tmpDir);
$translator->setFallbackLocales(array('b'));

$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');

$catalogue = $translator->getCatalogue('a');
$this->assertFalse($catalogue->defines('bar')); // Sure, the "a" catalogue does not contain that message.

$fallback = $catalogue->getFallbackCatalogue();
$this->assertTrue($fallback->defines('foo')); // "foo" is present in "a" and "b"

/*
* Now, repeat the same test.
* Behind the scenes, the cache is used. But that should not matter, right?
*/
$translator = new Translator('a', null, $this->tmpDir);
$translator->setFallbackLocales(array('b'));

$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');

$catalogue = $translator->getCatalogue('a');
$this->assertFalse($catalogue->defines('bar'));

$fallback = $catalogue->getFallbackCatalogue();
$this->assertTrue($fallback->defines('foo'));
}

protected function getCatalogue($locale, $messages)
{
$catalogue = new MessageCatalogue($locale);
Expand Down
15 changes: 0 additions & 15 deletionssrc/Symfony/Component/Translation/Translator.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -420,21 +420,6 @@ public function dumpCatalogue($locale, ConfigCacheInterface $cache)

private function getFallbackContent(MessageCatalogue $catalogue)
{
if (!$this->debug) {
// merge all fallback catalogues messages into $catalogue
$fallbackCatalogue = $catalogue->getFallbackCatalogue();
$messages = $catalogue->all();
while ($fallbackCatalogue) {
$messages = array_replace_recursive($fallbackCatalogue->all(), $messages);
$fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
}
foreach ($messages as $domain => $domainMessages) {
$catalogue->add($domainMessages, $domain);
}

return '';
}

$fallbackContent = '';
$current = '';
$replacementPattern = '/[^a-z0-9_]/i';
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp