SVN commit 866459 by ternisien: Use new Pology XML syntax for error highlighting M +29 -12 pology-errors.php --- trunk/www/areas/l10n/teams/fr/pology-errors.php #866458:866459 @@ -210,18 +210,28 @@ return NULL; } - function highlightRulesError($message, $start, $end) { + function highlightRulesError($message, $highlights) { define(LEFT_MARKER, "#{"); define(RIGHT_MARKER, "}#"); - $left = mb_substr($message, 0, $start, 'UTF-8'); - //echo "Left=$start : [" . $left . "] " . mb_strlen($left). " \n"; - - $middle = mb_substr($message, $start, $end - $start, 'UTF-8'); - //echo "Middle : [" . $middle . "]\n"; - - $right = mb_substr($message, $end, mb_strlen($message, 'UTF-8'), 'UTF-8'); - //echo "End=$end : [" . $right . "]\n"; + // Important : The reading must be from last to begin, because adding marker will modify error indexes. + // So each error has to be added from the last error to the first, to NEVER modify indexes. + // Another problem is that crossing errors could not work with this system. + for ($i = count($highlights) - 1 ; $i>=0 ; $i--) { + $start = $highlights[$i][0]; + $end = $highlights[$i][1]; + + $left = mb_substr($message, 0, $start, 'UTF-8'); + //echo "Left=$start : [" . $left . "] " . mb_strlen($left). " \n"; + + $middle = mb_substr($message, $start, $end - $start, 'UTF-8'); + //echo "Middle : [" . $middle . "]\n"; + + $right = mb_substr($message, $end, mb_strlen($message, 'UTF-8'), 'UTF-8'); + //echo "End=$end : [" . $right . "]\n"; + + $message = $left.LEFT_MARKER.$middle.RIGHT_MARKER.$right; + } $result = prepareMessage($left.LEFT_MARKER.$middle.RIGHT_MARKER.$right); @@ -265,9 +275,16 @@ $msgstr = $error->msgstr; - if ($typeCheck == ERROR_TYPE_RULES) - $msgstr = highlightRulesError($msgstr, $error->start, $error->end); - else if ($typeCheck == ERROR_TYPE_SPELL) + if ($typeCheck == ERROR_TYPE_RULES) { + $highlights = array(); + + foreach ($error->highlight as $highlight) { + $highlights[] = array( $highlight["begin"], $highlight["end"] ); + } + + $msgstr = highlightRulesError($msgstr, $highlights); + + } else if ($typeCheck == ERROR_TYPE_SPELL) $msgstr = highlightSpellError($msgstr, $error->faulty); echo "