Skip to content

Commit ed51dc5

Browse files
Merge branch '2.3' into 2.7
* 2.3: Improved the PHPdoc of FileSystem::copy() [Validator] Test DNS Email constraints using checkdnsrr() mock [travis] Run real php subprocesses on hhvm for Process component tests bug #18161 [Translation] Add support for fuzzy tags in PoFileLoader [Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers [Form] Fix INT64 cast to float in IntegerType. [SecurityBundle][PHPDoc] Added method doumentation for SecurityFactoryInterface FrameworkBundle: Client: getContainer(): fixed phpdoc [Validator] Updating inaccurate docblock comment Conflicts: .travis.yml src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php
2 parents 2db15c3 + abc5d93 commit ed51dc5

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Loader/PoFileLoader.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,20 @@ private function parse($resource)
108108

109109
$messages = array();
110110
$item = $defaults;
111+
$flags = array();
111112

112113
while ($line = fgets($stream)) {
113114
$line = trim($line);
114115

115116
if ($line === '') {
116117
// Whitespace indicated current item is done
117-
$this->addMessage($messages, $item);
118+
if (!in_array('fuzzy', $flags)) {
119+
$this->addMessage($messages, $item);
120+
}
118121
$item = $defaults;
122+
$flags = array();
123+
} elseif (substr($line, 0, 2) === '#,') {
124+
$flags = array_map('trim', explode(',', substr($line, 2)));
119125
} elseif (substr($line, 0, 7) === 'msgid "') {
120126
// We start a new msg so save previous
121127
// TODO: this fails when comments or contexts are added
@@ -141,7 +147,9 @@ private function parse($resource)
141147
}
142148
}
143149
// save last item
144-
$this->addMessage($messages, $item);
150+
if (!in_array('fuzzy', $flags)) {
151+
$this->addMessage($messages, $item);
152+
}
145153
fclose($stream);
146154

147155
return $messages;

Tests/Loader/PoFileLoaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,16 @@ public function testEscapedIdPlurals()
9393
$this->assertEquals('escaped "bar"', $messages['escaped "foo"']);
9494
$this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']);
9595
}
96+
97+
public function testSkipFuzzyTranslations()
98+
{
99+
$loader = new PoFileLoader();
100+
$resource = __DIR__.'/../fixtures/fuzzy-translations.po';
101+
$catalogue = $loader->load($resource, 'en', 'domain1');
102+
103+
$messages = $catalogue->all('domain1');
104+
$this->assertArrayHasKey('foo1', $messages);
105+
$this->assertArrayNotHasKey('foo2', $messages);
106+
$this->assertArrayHasKey('foo3', $messages);
107+
}
96108
}

Tests/fixtures/fuzzy-translations.po

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#, php-format
2+
msgid "foo1"
3+
msgstr "bar1"
4+
5+
#, fuzzy, php-format
6+
msgid "foo2"
7+
msgstr "fuzzy bar2"
8+
9+
msgid "foo3"
10+
msgstr "bar3"

0 commit comments

Comments
 (0)