Skip to content

Commit e9b93f4

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Add missing use statements [Translation] Add missing use statement [Translation] Add missing use statement [Config][XmlReferenceDumper] Prevent potential \TypeError [Mailer] Fix broken mandrill http send for recipients with names [Translation] prefer intl domain when adding messages to catalogue Fix CS Fix CS Fail on empty password verification (without warning on any implementation) [Translation][Debug] Add installation and minimal example to README [Validator] try to call __get method if property is uninitialized Show both missing packages in the same error message Fix handling of empty_data's \Closure value in Date/Time form types
2 parents 28e1054 + 52a914a commit e9b93f4

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

Command/XliffLintCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Input\InputOption;
1919
use Symfony\Component\Console\Output\OutputInterface;
2020
use Symfony\Component\Console\Style\SymfonyStyle;
21+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
2122
use Symfony\Component\Translation\Util\XliffUtils;
2223

2324
/**

MessageCatalogue.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,17 @@ public function replace(array $messages, string $domain = 'messages')
154154
public function add(array $messages, string $domain = 'messages')
155155
{
156156
if (!isset($this->messages[$domain])) {
157-
$this->messages[$domain] = $messages;
158-
} else {
159-
foreach ($messages as $id => $message) {
157+
$this->messages[$domain] = [];
158+
}
159+
$intlDomain = $domain;
160+
$suffixLength = \strlen(self::INTL_DOMAIN_SUFFIX);
161+
if (\strlen($domain) > $suffixLength && false !== strpos($domain, self::INTL_DOMAIN_SUFFIX, -$suffixLength)) {
162+
$intlDomain .= self::INTL_DOMAIN_SUFFIX;
163+
}
164+
foreach ($messages as $id => $message) {
165+
if (isset($this->messages[$intlDomain]) && \array_key_exists($id, $this->messages[$intlDomain])) {
166+
$this->messages[$intlDomain][$id] = $message;
167+
} else {
160168
$this->messages[$domain][$id] = $message;
161169
}
162170
}

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,28 @@ Translation Component
33

44
The Translation component provides tools to internationalize your application.
55

6+
Getting Started
7+
---------------
8+
9+
```
10+
$ composer require symfony/translation
11+
```
12+
13+
```php
14+
use Symfony\Component\Translation\Translator;
15+
16+
$translator = new Translator('fr_FR');
17+
$translator->addResource('array', [
18+
'Hello World!' => 'Bonjour !',
19+
], 'fr_FR');
20+
21+
echo $translator->trans('Hello World!'); // outputs « Bonjour ! »
22+
```
23+
624
Resources
725
---------
826

9-
* [Documentation](https://symfony.com/doc/current/components/translation.html)
27+
* [Documentation](https://symfony.com/doc/current/translation.html)
1028
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
1129
* [Report issues](https://github.com/symfony/symfony/issues) and
1230
[send Pull Requests](https://github.com/symfony/symfony/pulls)

Tests/Catalogue/TargetOperationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ public function testGetResultFromIntlDomain()
6767
);
6868
}
6969

70+
public function testGetResultWithMixedDomains()
71+
{
72+
$this->assertEquals(
73+
new MessageCatalogue('en', [
74+
'messages+intl-icu' => ['a' => 'old_a'],
75+
]),
76+
$this->createOperation(
77+
new MessageCatalogue('en', ['messages' => ['a' => 'old_a']]),
78+
new MessageCatalogue('en', ['messages+intl-icu' => ['a' => 'new_a']])
79+
)->getResult()
80+
);
81+
}
82+
7083
public function testGetResultWithMetadata()
7184
{
7285
$leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]);

0 commit comments

Comments
 (0)