From 97d7b7d16f9cc57e89ecdf2cd61dced0796197ca Mon Sep 17 00:00:00 2001 From: oscarotero Date: Thu, 27 Apr 2017 21:00:32 +0200 Subject: [PATCH] added 'noLocation' option to po generator --- src/Generators/Po.php | 8 +++++++- tests/TranslationTest.php | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Generators/Po.php b/src/Generators/Po.php index 52fb4003..c42c75df 100644 --- a/src/Generators/Po.php +++ b/src/Generators/Po.php @@ -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 ""']; @@ -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); } diff --git a/tests/TranslationTest.php b/tests/TranslationTest.php index 38dee622..63e84d46 100644 --- a/tests/TranslationTest.php +++ b/tests/TranslationTest.php @@ -3,6 +3,7 @@ namespace Gettext\Tests; use Gettext\Translation; +use Gettext\Translations; class TranslationTest extends AbstractTest { @@ -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');