diff --git a/src/Generators/Po.php b/src/Generators/Po.php index 136ea5c7..0fbe1c9c 100644 --- a/src/Generators/Po.php +++ b/src/Generators/Po.php @@ -2,12 +2,14 @@ namespace Gettext\Generators; +use Gettext\Translation; use Gettext\Translations; class Po extends Generator implements GeneratorInterface { public static $options = [ 'noLocation' => false, + 'sortOutput' => false, ]; /** @@ -27,6 +29,12 @@ public static function toString(Translations $translations, array $options = []) $lines[] = ''; + if ($options['sortOutput'] == true) { + $translations->uasort(function (Translation $translation1, Translation $translation2) { + return strcmp($translation1->getOriginal(), $translation2->getTranslation()); + }); + } + //Translations foreach ($translations as $translation) { if ($translation->hasComments()) { @@ -136,6 +144,7 @@ public static function convertString($value) "\x00" => '', '\\' => '\\\\', "\t" => '\t', + "\r" => '\r', "\n" => '\n', '"' => '\\"', ]