Skip to content

Commit 28e1054

Browse files
Merge branch '4.4' into 5.0
* 4.4: [DI] Fix EnvVar not loaded when Loader requires an env var Fixed #34713 Move new messages to intl domain when possible [FrameworkBundle] Fix small typo in output comment chown and chgrp should also accept int as owner and group Revert "Fixed translations file dumper behavior" Fix RememberMe with null password [Validator] Fix plurals for sr_Latn (Serbian language written in latin script) validation messages Set booted flag to false when test kernel is unset [FrameworkBundle] remove messenger cache if not enabled [PhpUnitBridge][SymfonyTestsListenerTrait] Remove some unneeded code [HttpClient] Fix strict parsing of response status codes fix PHP const mapping keys using the inline notation [SecurityBundle] Drop duplicated code [FrameworkBundle] Make sure one can use fragments.hinclude_default_template Fix that no-cache requires positive validation with the origin, even for fresh responses Improve upgrading instructions for deprecated router options [DI] Suggest typed argument when binding fails with untyped argument
2 parents a75b1dd + f5d2ac4 commit 28e1054

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

Dumper/FileDumper.php

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

54-
$hasMessageFormatter = class_exists(\MessageFormatter::class);
55-
5654
// save a file for each domain
5755
foreach ($messages->getDomains() as $domain) {
58-
if ($hasMessageFormatter) {
59-
$defaultDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
60-
$altDomain = $domain;
61-
} else {
62-
$defaultDomain = $domain;
63-
$altDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
64-
}
65-
$defaultPath = $options['path'].'/'.$this->getRelativePath($defaultDomain, $messages->getLocale());
66-
$altPath = $options['path'].'/'.$this->getRelativePath($altDomain, $messages->getLocale());
67-
68-
if (!file_exists($defaultPath) && file_exists($altPath)) {
69-
[$defaultPath, $altPath] = [$altPath, $defaultPath];
70-
}
71-
72-
if (!file_exists($defaultPath)) {
73-
$directory = \dirname($defaultPath);
56+
$fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale());
57+
if (!file_exists($fullpath)) {
58+
$directory = \dirname($fullpath);
7459
if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
7560
throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
7661
}
7762
}
7863

79-
if (file_exists($altPath)) {
80-
// clear alternative translation file
81-
file_put_contents($altPath, $this->formatCatalogue(new MessageCatalogue($messages->getLocale()), $altDomain, $options));
64+
$intlDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
65+
$intlMessages = $messages->all($intlDomain);
66+
67+
if ($intlMessages) {
68+
$intlPath = $options['path'].'/'.$this->getRelativePath($intlDomain, $messages->getLocale());
69+
file_put_contents($intlPath, $this->formatCatalogue($messages, $intlDomain, $options));
70+
71+
$messages->replace([], $intlDomain);
72+
73+
try {
74+
if ($messages->all($domain)) {
75+
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
76+
}
77+
continue;
78+
} finally {
79+
$messages->replace($intlMessages, $intlDomain);
80+
}
8281
}
8382

84-
file_put_contents($defaultPath, $this->formatCatalogue($messages, $domain, $options));
83+
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
8584
}
8685
}
8786

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)