Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit772f429

Browse files
committed
bug#18161 [Translation] Add support for fuzzy tags in PoFileLoader
The traditional gettext tools usually try to find similar strings whenupdating translations. This results in some strings having a translationbut being marked as "fuzzy", even if the translation is not correct.The expected result when a string is marked as fuzzy is that it shouldnot be used by the translation system. Using symfony, though, thetranslations were used, which could result in "funny" messages beingdisplayed in the interface despite being often completely out ofcontext.This commit discards messages in .po files that have a '#, fuzzy' flag.| Q | A| ------------- | ---| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | 18161| License | MIT| Doc PR | -
1 parentb19ce5e commit772f429

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

‎src/Symfony/Component/Translation/Loader/PoFileLoader.php‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ 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);
8183
$item =$defaults;
84+
$flags =array();
85+
}elseif (substr($line,0,2) ==='#,') {
86+
$flags =array_map('trim',explode(',',substr($line,2)));
8287
}elseif (substr($line,0,7) ==='msgid "') {
8388
// We start a new msg so save previous
8489
// TODO: this fails when comments or contexts are added
@@ -104,7 +109,8 @@ protected function loadResource($resource)
104109
}
105110
}
106111
// save last item
107-
$this->addMessage($messages,$item);
112+
if (!in_array('fuzzy',$flags))
113+
$this->addMessage($messages,$item);
108114
fclose($stream);
109115

110116
return$messages;

‎src/Symfony/Component/Translation/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+
publicfunctiontestSkipFuzzyTranslations()
98+
{
99+
$loader =newPoFileLoader();
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
}
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)

[8]ページ先頭

©2009-2025 Movatter.jp