Skip to content

Commit 432cf36

Browse files
committed
Added description and flag to generated po files #253
1 parent e908297 commit 432cf36

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/Generator/PoGenerator.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,24 @@ public function generateString(Translations $translations): string
1111
{
1212
$pluralForm = $translations->getHeaders()->getPluralForm();
1313
$pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null;
14+
$lines = [];
15+
16+
//Description and flags
17+
if ($translations->getDescription()) {
18+
$description = explode("\n", $translations->getDescription());
19+
20+
foreach ($description as $line) {
21+
$lines[] = sprintf('# %s', $line);
22+
}
23+
}
24+
25+
if (count($translations->getFlags())) {
26+
$lines[] = sprintf('#, %s', implode(',', $translations->getFlags()->toArray()));
27+
}
1428

1529
//Headers
16-
$lines = ['msgid ""', 'msgstr ""'];
30+
$lines[] = 'msgid ""';
31+
$lines[] = 'msgstr ""';
1732

1833
foreach ($translations->getHeaders() as $name => $value) {
1934
$lines[] = sprintf('"%s: %s\\n"', $name, $value);

tests/PoGeneratorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public function testPoLoader()
1414
{
1515
$generator = new PoGenerator();
1616
$translations = Translations::create('my-domain');
17+
$translations->getFlags()->add('fuzzy');
18+
$translations->setDescription(<<<'EOT'
19+
SOME DESCRIPTIVE TITLE
20+
Copyright (C) YEAR Free Software Foundation, Inc.
21+
This file is distributed under the same license as the PACKAGE package.
22+
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
23+
EOT
24+
);
1725
$translations->setLanguage('gl_ES');
1826
$translations->getHeaders()
1927
->set('Content-Type', 'text/plain; charset=UTF-8')
@@ -45,6 +53,11 @@ public function testPoLoader()
4553
$result = $generator->generateString($translations);
4654

4755
$expected = <<<'EOT'
56+
# SOME DESCRIPTIVE TITLE
57+
# Copyright (C) YEAR Free Software Foundation, Inc.
58+
# This file is distributed under the same license as the PACKAGE package.
59+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
60+
#, fuzzy
4861
msgid ""
4962
msgstr ""
5063
"Content-Type: text/plain; charset=UTF-8\n"

0 commit comments

Comments
 (0)