Skip to content

Commit

Permalink
Added description and flag to generated po files #253
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Mar 12, 2020
1 parent e908297 commit 432cf36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Generator/PoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ public function generateString(Translations $translations): string
{
$pluralForm = $translations->getHeaders()->getPluralForm();
$pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null;
$lines = [];

//Description and flags
if ($translations->getDescription()) {
$description = explode("\n", $translations->getDescription());

foreach ($description as $line) {
$lines[] = sprintf('# %s', $line);
}
}

if (count($translations->getFlags())) {
$lines[] = sprintf('#, %s', implode(',', $translations->getFlags()->toArray()));
}

//Headers
$lines = ['msgid ""', 'msgstr ""'];
$lines[] = 'msgid ""';
$lines[] = 'msgstr ""';

foreach ($translations->getHeaders() as $name => $value) {
$lines[] = sprintf('"%s: %s\\n"', $name, $value);
Expand Down
13 changes: 13 additions & 0 deletions tests/PoGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public function testPoLoader()
{
$generator = new PoGenerator();
$translations = Translations::create('my-domain');
$translations->getFlags()->add('fuzzy');
$translations->setDescription(<<<'EOT'
SOME DESCRIPTIVE TITLE
Copyright (C) YEAR Free Software Foundation, Inc.
This file is distributed under the same license as the PACKAGE package.
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
EOT
);
$translations->setLanguage('gl_ES');
$translations->getHeaders()
->set('Content-Type', 'text/plain; charset=UTF-8')
Expand Down Expand Up @@ -45,6 +53,11 @@ public function testPoLoader()
$result = $generator->generateString($translations);

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

0 comments on commit 432cf36

Please sign in to comment.