Skip to content

Commit

Permalink
Merge pull request #296 from swissspidy/fix/empty-comment-lines
Browse files Browse the repository at this point in the history
4.x: Fix parsing of PO files without empty lines
  • Loading branch information
oscarotero authored May 18, 2024
2 parents b632aaf + 4a4181c commit 7d98aba
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Extractors/Po.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static function fromString($string, Translations $translations, array $op
$line = trim($lines[$i]);
$line = static::fixMultiLines($line, $lines, $i);

if ($line === "#") {
$line = "";
}

if ($line === '') {
if ($translation->is('', '')) {
static::extractHeaders($translation->getTranslation(), $translations);
Expand Down
6 changes: 3 additions & 3 deletions tests/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public function testPo2()
public function testPo3()
{
$translations = static::get('po3/input', 'Po');
$countTranslations = 8;
$countTranslated = 8;
$countTranslations = 10;
$countTranslated = 10;
$countHeaders = 8;

$this->assertCount($countTranslations, $translations);
$this->assertCount($countHeaders, $translations->getHeaders());
$this->assertEquals(8, $translations->countTranslated());
$this->assertEquals(10, $translations->countTranslated());

$this->assertContent($translations, 'po3/Po');
$this->assertContent($translations, 'po3/Mo');
Expand Down
2 changes: 2 additions & 0 deletions tests/assets/po3/Csv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Report-Msgid-Bugs-To:
,"1 child","1 fillo"
,"1 comment","1 comentario"
,"1 star","1 estrela"
,"1 world","1 Welt"
,"1 sun","1 Sonne"
2 changes: 2 additions & 0 deletions tests/assets/po3/CsvDictionary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Kunststoffboden,"synthetic floor"
"1 child","1 fillo"
"1 comment","1 comentario"
"1 star","1 estrela"
"1 world","1 Welt"
"1 sun","1 Sonne"
6 changes: 6 additions & 0 deletions tests/assets/po3/Jed.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
],
"1 star": [
"1 estrela"
],
"1 world": [
"1 Welt"
],
"1 sun": [
"1 Sonne"
]
}
}
6 changes: 6 additions & 0 deletions tests/assets/po3/Json.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
],
"1 star": [
"1 estrela"
],
"1 world": [
"1 Welt"
],
"1 sun": [
"1 Sonne"
]
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/assets/po3/JsonDictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"Kunststoffboden": "synthetic floor",
"1 child": "1 fillo",
"1 comment": "1 comentario",
"1 star": "1 estrela"
"1 star": "1 estrela",
"1 world": "1 Welt",
"1 sun": "1 Sonne"
}
Binary file modified tests/assets/po3/Mo.mo
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/assets/po3/PhpArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
array (
0 => '1 estrela',
),
'1 world' =>
array (
0 => '1 Welt',
),
'1 sun' =>
array (
0 => '1 Sonne',
),
),
),
);
6 changes: 6 additions & 0 deletions tests/assets/po3/Po.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ msgid "1 star"
msgid_plural "%s stars"
msgstr[0] "1 estrela"
msgstr[1] ""

msgid "1 world"
msgstr "1 Welt"

msgid "1 sun"
msgstr "1 Sonne"
18 changes: 18 additions & 0 deletions tests/assets/po3/Xliff.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,23 @@
<target>1 estrela</target>
</segment>
</unit>
<unit id="053956a6b44b2ec54e17b7a1b425c43b">
<notes>
<note category="context"></note>
</notes>
<segment>
<source>1 world</source>
<target>1 Welt</target>
</segment>
</unit>
<unit id="25b9c05aeb9c27e35a3b73f6dd5f6f2a">
<notes>
<note category="context"></note>
</notes>
<segment>
<source>1 sun</source>
<target>1 Sonne</target>
</segment>
</unit>
</file>
</xliff>
2 changes: 2 additions & 0 deletions tests/assets/po3/Yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ messages:
'1 child': '1 fillo'
'1 comment': '1 comentario'
'1 star': '1 estrela'
'1 world': '1 Welt'
'1 sun': '1 Sonne'
2 changes: 2 additions & 0 deletions tests/assets/po3/YamlDictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Kunststoffboden: 'synthetic floor'
'1 child': '1 fillo'
'1 comment': '1 comentario'
'1 star': '1 estrela'
'1 world': '1 Welt'
'1 sun': '1 Sonne'
6 changes: 6 additions & 0 deletions tests/assets/po3/input.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ msgstr[1] ""

msgid "1 star"
msgstr "1 estrela"
#
msgid "1 world"
msgstr "1 Welt"
#
msgid "1 sun"
msgstr "1 Sonne"

0 comments on commit 7d98aba

Please sign in to comment.