-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
{% for source,target in translations[locale][domain] %} | ||
<tr> | ||
<td class="trans-source">{{ source }}</td> | ||
<td class="trans-target">{{ translator.wrap(source, domain, locale) }}</td> | ||
{% set trans = translator.trans(source, {}, domain, locale) %} | ||
<td class="trans-target">{{ translatorHelper.wrap(source, trans, domain, locale) }}</td> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
docteurklein
Author
Owner
|
||
</tr> | ||
|
||
{% endfor %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\TranslatorBundle\Templating\Helper; | ||
|
||
use Symfony\Component\Templating\Helper\Helper; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper as BaseTranslatorHelper; | ||
|
||
/** | ||
* TranslatorHelper. | ||
* | ||
* @author Florian Klein <florian.klein@free.fr> | ||
*/ | ||
class TranslatorHelper extends BaseTranslatorHelper | ||
{ | ||
/** | ||
* @see TranslatorInterface::trans() | ||
*/ | ||
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null) | ||
{ | ||
if (!isset($locale)) { | ||
$locale = $this->translator->getLocale(); | ||
} | ||
|
||
$trans = parent::trans($id, $parameters, $domain, $locale); | ||
|
||
return $this->wrap($id, $trans, $domain, $locale); | ||
This comment has been minimized.
Sorry, something went wrong.
stof
|
||
} | ||
|
||
/** | ||
* @see TranslatorInterface::transChoice() | ||
*/ | ||
public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null) | ||
{ | ||
if (!isset($locale)) { | ||
$locale = $this->translator->getLocale(); | ||
} | ||
|
||
$trans = parent::transChoice($id, $number, $parameters, $domain, $locale); | ||
|
||
return $this->wrap($id, $trans, $domain, $locale); | ||
} | ||
|
||
/** | ||
* Wraps a translated value with [T id="%s" domain="%s" locale="%s"]%s[/T] | ||
* Used to detect in-line edition of translations | ||
* | ||
* @return string | ||
*/ | ||
public function wrap($id, $trans, $domain = 'messages', $locale = null) | ||
{ | ||
$startTag = sprintf('[T id="%s" domain="%s" locale="%s"]', $id, $domain, $locale); | ||
|
||
return sprintf('%s%s%s', $startTag, $trans, '[/T]'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\TranslatorBundle\Templating\Twig; | ||
|
||
use Symfony\Bridge\Twig\Extension\TranslationExtension as BaseTranslationExtension; | ||
use Knp\Bundle\TranslatorBundle\Templating\Helper\TranslatorHelper; | ||
|
||
/** | ||
* Provides integration of the Translation component with Twig. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class TranslationExtension extends BaseTranslationExtension | ||
{ | ||
private $translatorHelper; | ||
|
||
public function __construct(TranslatorHelper $translatorHelper) | ||
{ | ||
$this->translatorHelper = $translatorHelper; | ||
} | ||
|
||
public function trans($message, array $arguments = array(), $domain = "messages") | ||
{ | ||
return $this->translatorHelper->trans($message, $arguments, $domain); | ||
} | ||
|
||
public function transchoice($message, $count, array $arguments = array(), $domain = "messages") | ||
{ | ||
return $this->translatorHelper->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain); | ||
} | ||
} |
Why not using a Twig filter for this ? it would be cleaner