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

Appearance settings

Commit 039feed

Browse filesBrowse files
bug #35351 Revert #34797 "Fixed translations file dumper behavior" and fix #34713 (yceruto)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Revert #34797 "Fixed translations file dumper behavior" and fix #34713 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35264 | License | MIT | Doc PR | - Revert #34797 See also #35328 It's very likely that the new way will be completely different from this one that is being reverted. That's why I'm reverting rather than fixing it. Commits ------- 9ca8720 Fixed #34713 Move new messages to intl domain when possible 56e79fe Revert "Fixed translations file dumper behavior"
2 parents 947947e + 9ca8720 commit 039feed
Copy full SHA for 039feed

File tree

3 files changed

+47
-32
lines changed
Filter options

3 files changed

+47
-32
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Translation\Catalogue\TargetOperation;
2424
use Symfony\Component\Translation\Extractor\ExtractorInterface;
2525
use Symfony\Component\Translation\MessageCatalogue;
26+
use Symfony\Component\Translation\MessageCatalogueInterface;
2627
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
2728
use Symfony\Component\Translation\Writer\TranslationWriterInterface;
2829

@@ -254,6 +255,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
254255

255256
$resultMessage = 'Translation files were successfully updated';
256257

258+
// move new messages to intl domain when possible
259+
if (class_exists(\MessageFormatter::class)) {
260+
foreach ($operation->getDomains() as $domain) {
261+
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
262+
$newMessages = $operation->getNewMessages($domain);
263+
264+
if ([] === $newMessages || ([] === $currentCatalogue->all($intlDomain) && [] !== $currentCatalogue->all($domain))) {
265+
continue;
266+
}
267+
268+
$result = $operation->getResult();
269+
$allIntlMessages = $result->all($intlDomain);
270+
$currentMessages = array_diff_key($newMessages, $result->all($domain));
271+
$result->replace($currentMessages, $domain);
272+
$result->replace($allIntlMessages + $newMessages, $intlDomain);
273+
}
274+
}
275+
257276
// show compiled list of messages
258277
if (true === $input->getOption('dump-messages')) {
259278
$extractedMessagesCount = 0;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Dumper/FileDumper.php
+21-22Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php
+7-10Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.