8000 Revert "Fixed translations file dumper behavior" · symfony/symfony@56e79fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 56e79fe

Browse files
committed
Revert "Fixed translations file dumper behavior"
1 parent be84687 commit 56e79fe

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

src/Symfony/Component/Translation/Dumper/FileDumper.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,37 +67,36 @@ public function dump(MessageCatalogue $messages, $options = [])
6767
throw new InvalidArgumentException('The file dumper needs a path option.');
6868
}
6969

70-
$hasMessageFormatter = class_exists(\MessageFormatter::class);
71-
7270
// save a file for each domain
7371
foreach ($messages->getDomains() as $domain) {
74-
if ($hasMessageFormatter) {
75-
$defaultDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
76-
$altDomain = $domain;
77-
} else {
78-
$defaultDomain = $domain;
79-
$altDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
80-
}
81-
$defaultPath = $options['path'].'/'.$this->getRelativePath($defaultDomain, $messages->getLocale());
82-
$altPath = $options['path'].'/'.$this->getRelativePath($altDomain, $messages->getLocale());
83-
84-
if (!file_exists($defaultPath) && file_exists($altPath)) {
85-
[$defaultPath, $altPath] = [$altPath, $defaultPath];
86-
}
87-
88-
if (!file_exists($defaultPath)) {
89-
$directory = \dirname($defaultPath);
72+
$fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale());
73+
if (!file_exists($fullpath)) {
74+
$directory = \dirname($fullpath);
9075
if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
9176
throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
9277
}
9378
}
9479

95-
if (file_exists($altPath)) {
96-
// clear alternative translation file
97-
file_put_contents($altPath, $this->formatCatalogue(new MessageCatalogue($messages->getLocale()), $altDomain, $options));
80+
$intlDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
81+
$intlMessages = $messages->all($intlDomain);
82+
83+
if ($intlMessages) {
84+
$intlPath = $options['path'].'/'.$this->getRelativePath($intlDomain, $messages->getLocale());
85+
file_put_contents($intlPath, $this->formatCatalogue($messages, $intlDomain, $options));
86+
87+
$messages->replace([], $intlDomain);
88+
89+
try {
90+
if ($messages->all($domain)) {
91+
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
92+
}
93+
continue;
94+
} finally {
95+
$messages->replace($intlMessages, $intlDomain);
96+
}
9897
}
9998

100-
file_put_contents($defaultPath, $this->formatCatalogue($messages, $domain, $options));
99+
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
101100
}
102101
}
103102

src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ public function testDump()
2727
$dumper = new ConcreteFileDumper();
2828
$dumper->dump($catalogue, ['path' => $tempDir]);
2929

30-
$suffix = class_exists(\MessageFormatter::class) ? '+intl-icu' : '';
31-
$this->assertFileExists($tempDir."/messages$suffix.en.concrete");
30+
$this->assertFileExists($tempDir.'/messages.en.concrete');
3231

33-
@unlink($tempDir."/messages$suffix.en.concrete");
32+
@unlink($tempDir.'/messages.en.concrete');
3433
}
3534

36-
/**
37-
* @requires extension intl
38-
*/
3935
public function testDumpIntl()
4036
{
4137
$tempDir = sys_get_temp_dir();
@@ -46,11 +42,13 @@ public function testDumpIntl()
4642
$catalogue->add(['bar' => 'foo'], 'd2+intl-icu');
4743

4844
$dumper = new ConcreteFileDumper();
45+
@unlink($tempDir.'/d2.en.concrete');
4946
$dumper->dump($catalogue, ['path' => $tempDir]);
5047

51-
$this->assertFileNotExists($tempDir.'/d1.en.concrete');
48+
$this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar');
49+
@unlink($tempDir.'/d1.en.concrete');
5250

53-
$this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo&foo=bar');
51+
$this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo');
5452
@unlink($tempDir.'/d1+intl-icu.en.concrete');
5553

5654
$this->assertFileNotExists($tempDir.'/d2.en.concrete');
@@ -62,8 +60,7 @@ public function testDumpCreatesNestedDirectoriesAndFile()
6260
{
6361
$tempDir = sys_get_temp_dir();
6462
$translationsDir = $tempDir.'/test/translations';
65-
$suffix = class_exists(\MessageFormatter::class) ? '+intl-icu' : '';
66-
$file = $translationsDir."/messages$suffix.en.concrete";
63+
$file = $translationsDir.'/messages.en.concrete';
6764

6865
$catalogue = new MessageCatalogue('en');
6966
$catalogue->add(['foo' => 'bar']);

0 commit comments

Comments
 (0)
0