Skip to content

Commit 0153c17

Browse files
Merge branch '2.8' into 3.0
* 2.8: [Validator] Test DNS Url constraints using checkdnsrr() mock 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
2 parents f6565c4 + b369d06 commit 0153c17

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
@@ -71,14 +71,20 @@ protected function loadResource($resource)
7171

7272
$messages = array();
7373
$item = $defaults;
74+
$flags = array();
7475

7576
while ($line = fgets($stream)) {
7677
$line = trim($line);
7778

7879
if ($line === '') {
7980
// Whitespace indicated current item is done
80-
$this->addMessage($messages, $item);
81+
if (!in_array('fuzzy', $flags)) {
82+
$this->addMessage($messages, $item);
83+
}
8184
$item = $defaults;
85+
$flags = array();
86+
} elseif (substr($line, 0, 2) === '#,') {
87+
$flags = array_map('trim', explode(',', substr($line, 2)));
8288
} elseif (substr($line, 0, 7) === 'msgid "') {
8389
// We start a new msg so save previous
8490
// TODO: this fails when comments or contexts are added
@@ -104,7 +110,9 @@ protected function loadResource($resource)
104110
}
105111
}
106112
// save last item
107-
$this->addMessage($messages, $item);
113+
if (!in_array('fuzzy', $flags)) {
114+
$this->addMessage($messages, $item);
115+
}
108116
fclose($stream);
109117

110118
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)