Skip to content

Commit

Permalink
added 'noLocation' option to po generator
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Apr 27, 2017
1 parent 9f8b059 commit 97d7b7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Generators/Po.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

class Po extends Generator implements GeneratorInterface
{
public static $options = [
'noLocation' => false,
];

/**
* {@parentDoc}.
*/
public static function toString(Translations $translations, array $options = [])
{
$options += static::$options;

$pluralForm = $translations->getPluralForms();
$pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null;
$lines = ['msgid ""', 'msgstr ""'];
Expand All @@ -35,7 +41,7 @@ public static function toString(Translations $translations, array $options = [])
}
}

if ($translation->hasReferences()) {
if (!$options['noLocation'] && $translation->hasReferences()) {
foreach ($translation->getReferences() as $reference) {
$lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/TranslationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gettext\Tests;

use Gettext\Translation;
use Gettext\Translations;

class TranslationTest extends AbstractTest
{
Expand All @@ -24,6 +25,20 @@ public function testReferences()
$this->assertCount(0, $translation->getReferences());
}

public function testNoReferences()
{
$po = static::get('phpcode/input', 'PhpCode')->toPoString(['noLocation' => true]);
$translations = Translations::fromPoString($po);
$translation = $translations->find(null, 'text 10 with plural');

$this->assertInstanceOf('Gettext\\Translation', $translation);

$references = $translation->getReferences();

$this->assertCount(0, $references);
$this->assertFalse($translation->hasReferences());
}

public function testPlurals()
{
$translations = static::get('phpcode/input', 'PhpCode');
Expand Down

0 comments on commit 97d7b7d

Please sign in to comment.