Skip to content

Commit 7d98aba

Browse files
authored
Merge pull request #296 from swissspidy/fix/empty-comment-lines
4.x: Fix parsing of PO files without empty lines
2 parents b632aaf + 4a4181c commit 7d98aba

File tree

14 files changed

+68
-4
lines changed

14 files changed

+68
-4
lines changed

src/Extractors/Po.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static function fromString($string, Translations $translations, array $op
2929
$line = trim($lines[$i]);
3030
$line = static::fixMultiLines($line, $lines, $i);
3131

32+
if ($line === "#") {
33+
$line = "";
34+
}
35+
3236
if ($line === '') {
3337
if ($translation->is('', '')) {
3438
static::extractHeaders($translation->getTranslation(), $translations);

tests/AssetsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public function testPo2()
8989
public function testPo3()
9090
{
9191
$translations = static::get('po3/input', 'Po');
92-
$countTranslations = 8;
93-
$countTranslated = 8;
92+
$countTranslations = 10;
93+
$countTranslated = 10;
9494
$countHeaders = 8;
9595

9696
$this->assertCount($countTranslations, $translations);
9797
$this->assertCount($countHeaders, $translations->getHeaders());
98-
$this->assertEquals(8, $translations->countTranslated());
98+
$this->assertEquals(10, $translations->countTranslated());
9999

100100
$this->assertContent($translations, 'po3/Po');
101101
$this->assertContent($translations, 'po3/Mo');

tests/assets/po3/Csv.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ Report-Msgid-Bugs-To:
1515
,"1 child","1 fillo"
1616
,"1 comment","1 comentario"
1717
,"1 star","1 estrela"
18+
,"1 world","1 Welt"
19+
,"1 sun","1 Sonne"

tests/assets/po3/CsvDictionary.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ Kunststoffboden,"synthetic floor"
66
"1 child","1 fillo"
77
"1 comment","1 comentario"
88
"1 star","1 estrela"
9+
"1 world","1 Welt"
10+
"1 sun","1 Sonne"

tests/assets/po3/Jed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
],
2929
"1 star": [
3030
"1 estrela"
31+
],
32+
"1 world": [
33+
"1 Welt"
34+
],
35+
"1 sun": [
36+
"1 Sonne"
3137
]
3238
}
3339
}

tests/assets/po3/Json.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
],
3030
"1 star": [
3131
"1 estrela"
32+
],
33+
"1 world": [
34+
"1 Welt"
35+
],
36+
"1 sun": [
37+
"1 Sonne"
3238
]
3339
}
3440
}

tests/assets/po3/JsonDictionary.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"Kunststoffboden": "synthetic floor",
77
"1 child": "1 fillo",
88
"1 comment": "1 comentario",
9-
"1 star": "1 estrela"
9+
"1 star": "1 estrela",
10+
"1 world": "1 Welt",
11+
"1 sun": "1 Sonne"
1012
}

tests/assets/po3/Mo.mo

61 Bytes
Binary file not shown.

tests/assets/po3/PhpArray.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
array (
5050
0 => '1 estrela',
5151
),
52+
'1 world' =>
53+
array (
54+
0 => '1 Welt',
55+
),
56+
'1 sun' =>
57+
array (
58+
0 => '1 Sonne',
59+
),
5260
),
5361
),
5462
);

tests/assets/po3/Po.po

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ msgid "1 star"
3939
msgid_plural "%s stars"
4040
msgstr[0] "1 estrela"
4141
msgstr[1] ""
42+
43+
msgid "1 world"
44+
msgstr "1 Welt"
45+
46+
msgid "1 sun"
47+
msgstr "1 Sonne"

0 commit comments

Comments
 (0)