Skip to content

Commit

Permalink
Add translation domain to tracy panel
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag committed Feb 7, 2016
1 parent 3f54b00 commit a73866a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
26 changes: 17 additions & 9 deletions src/Kdyby/Translation/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct($rootDir)
public function getTab()
{
return '<span title="Translation"><img width="16px" height="16px" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90DExAuL9uIsPUAAAQ2SURBVFjD7Ze9bxxVFMV/583skjgOIXEaKCNFAgmQ+ExS8qEUCEHH30BBScG/QM1fEmgoAAkoAigSKKFASElHESEFbGcdez7uoXhvZteW7ewmQjRMsTs7s/Pufeece+4d+P/4jw8ddvHq1avv2b5mm02Lr9Y7/gpQBCFDD5YhgsAoRLhHMtHnRYNAAb3yt92//9y3v3x+MFY6LIGIuGYbKedngzAGsPK5Kb8BGRAu9xiuL+zQ6NphsQ5NYB7YhA1jQCObyOHG/3sMlpM0hmGNcmXh7w9PYL5wfsphbCMPaOR7BipEJahV0FHZvZ2D+1i2qY+gYERCZTGZzLdFkLNIht/v72AHGM5Pa85MqowUc4p81PaPo2CgIa9RxOZ8jowDZm0WXo2oBdttN8ihIABC5dPLI7BIQQA5prEGIeYdbnVtSSpD3WCaCCqpMB8jXSshEBFEROZ9TCTvepC/be63HWA2ppNRoJttP1flvkp5BArmNBQl5zSIMJtNRxJEwHqVOF1XGLHVdSQp+0CpAi1UytJVYHteBQ7cm7AgIKnAH7CWhBDrVRqfud91UERLFNPyihQMwaOUIAI5I9D0PU2Xz9frCjs4WVVUMhJstR2SwaUWgvx7VQqyG2b4IoIoO9xsWipllJ6sK1JB7Exd4whmbUcYlCVcRKrVq0DSqCIVRlPZ4SCqO7MHC0Ey1Epiu+k5XafMvbRaFXCgdBxBOIgw202/TyNBtmuHibJRYba6LjuAsgjjCA3UxwWPCEwanRCJ7bYd/eHspFootdwhdvqeJsyegyaCSVK271US2E9BNp8otbTd9STlB89NJvRFmJREJ4K7e0El2Op6NiY1x7GQlpoawihgq+lIZF2s1xWdu9GAcO6Yp6rcE4OcwGDGR7nhUglYRjL32pbOQdMH61VCzgiFc8eUs+2cTIkuoI2MmH20D9TLzEzuTafgwtp0dNXO5FlhsOvSh23zzBPTBfDm4ny0BBBWAInWpSmVmSDzqrEko0TpBwct9W+xGgKL41hWoMeJB/LQsa/JlOYkVDrmAHlpwnF0M6of2gdIC7vUvDUNk1HMbwVRbmo+jA3tOlaYByTYbRJdiG1E3UFFg2IvLxqm67qR1yg71kLflDXvwhHhsxtbSycw2xWffXiPP+/NmFTiGyX21t9m99RbWDCZ1Fy5dAlJeXyz6aOfz48Mzli6aPTp8rMXz/585UVeun7z4WW418Kll0/w9Pk1/t5JTHdh2otpElMl1PX8eP06fdus9ObhQ2g4VBrVxpvvdl/Ovmgacev2Dnf+2GXnxi6zGw/KMJrNJUXPS6fXmCaNw+d8GNV8KHXgp87xyg83tVQCALPvLlvCVUK/3tnh9t3mkw8+/u3Tx3kNu/H6C7z6063lnLBU4dd98NHzF9Z47eKpE4/7Hngw+LHHzveX3zmAyBv/xsvpP+li/lm3bxkuAAAAAElFTkSuQmCC" />'
. $this->translator->getLocale() . ($this->untranslated ? ' <b>(' . count(array_unique($this->untranslated)) . ' errors)</b>' : '')
. $this->translator->getLocale() . ($this->untranslated ? ' <b>(' . count(array_unique($this->untranslated, SORT_REGULAR)) . ' errors)</b>' : '')
. '</span>';
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public function getPanel()
}

return empty($panel) ? '' :
'<h1>Missing translations: ' . count(array_unique($this->untranslated)) .
'<h1>Missing translations: ' . count(array_unique($this->untranslated, SORT_REGULAR)) .
', Resources: ' . count(Nette\Utils\Arrays::flatten($this->resources)) . '</h1>' .
'<div class="nette-inner tracy-inner kdyby-TranslationPanel" style="min-width:500px">' . implode($panel) . '</div>' .
'<style>
Expand All @@ -172,7 +172,9 @@ private function renderUntranslated()
$s = '';
$h = 'htmlSpecialChars';

foreach ($unique = array_unique($this->untranslated) as $message) {
foreach ($unique = array_unique($this->untranslated, SORT_REGULAR) as $untranslated) {
$message = $untranslated['message'];

$s .= '<tr><td>';

if ($message instanceof \Exception) {
Expand All @@ -185,10 +187,10 @@ private function renderUntranslated()
$s .= $h($message);
}

$s .= '</td></tr>';
$s .= '</td><td>' . $h($untranslated['domain']) . '</td></tr>';
}

return '<table style="width:100%"><tr><th>Untranslated message</th></tr>' . $s . '</table>';
return '<table style="width:100%"><tr><th>Untranslated message</th><th>Translation domain</th></tr>' . $s . '</table>';
}


Expand Down Expand Up @@ -225,19 +227,25 @@ private function renderResources($resourcesMap)



public function markUntranslated($id)
public function markUntranslated($id, $domain)
{
$this->untranslated[] = $id;
$this->untranslated[] = array(
'message' => $id,
'domain' => $domain,
);
}



/**
* @param \Exception|\Throwable $e
*/
public function choiceError($e)
public function choiceError($e, $domain)
{
$this->untranslated[] = $e;
$this->untranslated[] = array(
'message' => $message,
'domain' => $domain,
);
}


Expand Down
8 changes: 4 additions & 4 deletions src/Kdyby/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function translate($message, $count = NULL, $parameters = array(), $domai

} elseif ($message instanceof Nette\Utils\Html) {
if ($this->panel) {
$this->panel->markUntranslated($message);
$this->panel->markUntranslated($message, $domain);
}
return $message; // todo: what now?
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function trans($message, array $parameters = array(), $domain = NULL, $lo
if ($result === "\x01") {
$this->logMissingTranslation($message, $domain, $locale);
if ($this->panel !== NULL) {
$this->panel->markUntranslated($message);
$this->panel->markUntranslated($message, $domain);
}
$result = strtr($message, $parameters);
}
Expand Down Expand Up @@ -219,14 +219,14 @@ public function transChoice($message, $number, array $parameters = array(), $dom
} catch (\Exception $e) {
$result = $id;
if ($this->panel !== NULL) {
$this->panel->choiceError($e);
$this->panel->choiceError($e, $domain);
}
}

if ($result === "\x01") {
$this->logMissingTranslation($message, $domain, $locale);
if ($this->panel !== NULL) {
$this->panel->markUntranslated($message);
$this->panel->markUntranslated($message, $domain);
}
$result = strtr($message, $parameters);
}
Expand Down

0 comments on commit a73866a

Please sign in to comment.