Skip to content

Commit 08c42eb

Browse files
author
Oscar Otero
committed
Fix multiline strings in PO #244
1 parent 1dab649 commit 08c42eb

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
Previous releases are documented in [github releases](https://github.com/oscarotero/Gettext/releases)
99

10+
## [5.2.1] - 2019-12-08
11+
### Fixed
12+
- Multiline string in PoGenerator [#244]
13+
1014
## [5.2.0] - 2019-11-25
1115
### Added
1216
- New function `CodeScanner::extractCommentsStartingWith()` to extract comments from the code.
@@ -41,5 +45,8 @@ Previous releases are documented in [github releases](https://github.com/oscarot
4145
- The library is easier to extend
4246
- Translation id can be independent of the context + original values, in order to be more compatible with Xliff format.
4347

44-
[5.2.0]: https://github.com/php-gettext/Gettext/compare/v5.1.0...HEAD
48+
[#244]: https://github.com/php-gettext/Gettext/issues/244
49+
50+
[5.2.1]: https://github.com/php-gettext/Gettext/compare/v5.2.0...v5.2.1
51+
[5.2.0]: https://github.com/php-gettext/Gettext/compare/v5.1.0...v5.2.0
4552
[5.1.0]: https://github.com/php-gettext/Gettext/compare/v5.0.0...v5.1.0

src/Generator/PoGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ private static function appendLines(array &$lines, string $prefix, string $name,
8787

8888
$lines[] = sprintf('%s%s ""', $prefix, $name);
8989

90+
$last = $total - 1;
9091
foreach ($newLines as $k => $line) {
91-
if ($k === $total - 1) {
92+
if ($k < $last) {
9293
$line .= "\n";
9394
}
9495

tests/PoGeneratorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function testPoLoader()
3737
$translation->getComments()->add('This is a disabled comment');
3838
$translations->add($translation);
3939

40+
// https://github.com/php-gettext/Gettext/issues/244
41+
$translation = Translation::create(null, "foo\nbar");
42+
$translation->translate("bar\nbaz");
43+
$translations->add($translation);
44+
4045
$result = $generator->generateString($translations);
4146

4247
$expected = <<<'EOT'
@@ -64,6 +69,13 @@ public function testPoLoader()
6469
#~ msgid "Disabled comment"
6570
#~ msgstr "Comentario deshabilitado"
6671
72+
msgid ""
73+
"foo\n"
74+
"bar"
75+
msgstr ""
76+
"bar\n"
77+
"baz"
78+
6779
EOT;
6880

6981
$this->assertSame($expected, $result);

0 commit comments

Comments
 (0)