[icinga-checkins] icinga.org: icingaweb2/feature/translation-catalog-statistics-object-13013 : CatalogEntry: Add regex to method isFaulty

git at icinga.org git at icinga.org
Wed Dec 14 09:57:49 CET 2016


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

Author: Jennifer Mourek <jennifer.mourek at netways.de>
Date:   Wed Dec 14 09:55:47 2016 +0100

CatalogEntry: Add regex to method isFaulty

refs #13013

---

 .../library/Translation/Catalog/CatalogEntry.php       |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/modules/translation/library/Translation/Catalog/CatalogEntry.php b/modules/translation/library/Translation/Catalog/CatalogEntry.php
index f011a44..4b001ed 100644
--- a/modules/translation/library/Translation/Catalog/CatalogEntry.php
+++ b/modules/translation/library/Translation/Catalog/CatalogEntry.php
@@ -518,15 +518,21 @@ class CatalogEntry
      */
     public function isFaulty()
     {
-        $numberOfPlaceHoldersInId = substr_count($this->messageId, '%s');
-        if (! empty($this->message) && substr_count($this->message, '%s') !== $numberOfPlaceHoldersInId) {
+        $regexToCountPlaceholders = '/(?<!%)%(?:\d+\$)?[+-]?(?:[ 0]|\'.)?-?\d*(?:\.\d+)?[bcdeEufFgGosxX]/';
+
+        $numberOfPlaceholdersInId = preg_match_all($regexToCountPlaceholders, $this->messageId, $_);
+        $numberOfPlaceholdersInMessage = preg_match_all($regexToCountPlaceholders, $this->message, $_);
+
+        if ($numberOfPlaceholdersInId !== $numberOfPlaceholdersInMessage) {
             return true;
         }
 
-        if (! empty($this->messageIdPlural)) {
-            $numberOfPlaceHoldersInPluralId = substr_count($this->messageIdPlural, '%s');
+        if ($this->getMessageIdPlural()) {
+            $numberOfPlaceholdersInIdPlural = preg_match_all($regexToCountPlaceholders, $this->messageIdPlural, $_);
+
             foreach ($this->messagePlurals as $value) {
-                if (substr_count($value, '%s') !== $numberOfPlaceHoldersInPluralId) {
+                $numberOfPlaceholdersInMessagePlural = preg_match_all($regexToCountPlaceholders, $value, $_);
+                if ($numberOfPlaceholdersInIdPlural !== $numberOfPlaceholdersInMessagePlural) {
                     return true;
                 }
             }



More information about the icinga-checkins mailing list