[icinga-checkins] icinga.org: icingaweb2/feature/translation-catalog-object-13012: CatalogHeader: Add copyrightInformation

git at icinga.org git at icinga.org
Wed Nov 23 12:23:44 CET 2016


Module: icingaweb2
Branch: feature/translation-catalog-object-13012
Commit: 578def55d9d0602159d38ad57b941195f7bdad93
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=578def55d9d0602159d38ad57b941195f7bdad93

Author: Jennifer Mourek <jennifer.mourek at netways.de>
Date:   Wed Nov 23 12:21:58 2016 +0100

CatalogHeader: Add copyrightInformation

refs #13012

---

 .../library/Translation/Catalog/CatalogHeader.php  |   45 ++++++++++++++++++--
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/modules/translation/library/Translation/Catalog/CatalogHeader.php b/modules/translation/library/Translation/Catalog/CatalogHeader.php
index 0cb3a91..0aeeed8 100644
--- a/modules/translation/library/Translation/Catalog/CatalogHeader.php
+++ b/modules/translation/library/Translation/Catalog/CatalogHeader.php
@@ -32,6 +32,13 @@ class CatalogHeader implements ArrayAccess
     protected $headers;
 
     /**
+     * The copyright information for this CatalogHeader
+     *
+     * @var array
+     */
+    protected $copyrightInformation;
+
+    /**
      * Create a new CatalogHeader
      *
      * @param   array   $headers
@@ -51,7 +58,7 @@ class CatalogHeader implements ArrayAccess
     public static function fromString($header)
     {
         $lines = preg_split(
-            '/\n(?=.+: )/',
+            '/\n(?=\S+: )/',
             substr($header, -1) === "\n"
                 ? substr($header, 0, -1)
                 : $header
@@ -73,6 +80,29 @@ class CatalogHeader implements ArrayAccess
     }
 
     /**
+     * Set copyright information for this CatalogHeader
+     *
+     * @param   array   $copyrightInformation
+     *
+     * @return  $this
+     */
+    public function setCopyrightInformation($copyrightInformation)
+    {
+        $this->copyrightInformation = $copyrightInformation;
+        return $this;
+    }
+
+    /**
+     * Return copyright information for this CatalogHeader
+     *
+     * @return array
+     */
+    public function getCopyrightInformation()
+    {
+        return $this->copyrightInformation;
+    }
+
+    /**
      * Return whether the given header exists
      *
      * @param   string  $name   The name of the header
@@ -130,13 +160,22 @@ class CatalogHeader implements ArrayAccess
             throw new IcingaException('No headers to render');
         }
 
+
         $entries = array();
+
+        if (! empty($this->copyrightInformation)) {
+            foreach ($this->copyrightInformation as $value) {
+                $entries[] = '# ' . $value;
+            }
+        }
+
+        $entries[] = "msgid \"\"\nmsgstr \"\"";
         foreach ($this->headers as $key => $value)
         {
             $entries[] = '"' . $this->escapeCharacters(sprintf('%s: %s', $key, $value)) . '\n"';
         }
 
-        return "msgid \"\"\nmsgstr \"\"\n" . implode("\n", $entries);
+        return implode("\n", $entries);
     }
 
     /**
@@ -146,7 +185,7 @@ class CatalogHeader implements ArrayAccess
      *
      * @return  string
      */
-    public function escapeCharacters($string)
+    protected function escapeCharacters($string)
     {
         $escapedChars = array(
             "\n" => '\\n',



More information about the icinga-checkins mailing list