Last active
August 29, 2015 14:22
-
-
Save mauricius/057d82da3b4122ee65a1 to your computer and use it in GitHub Desktop.
Extend Processwire TemplateEngineTwig.module with the function to enable i18n translations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function ___initTwig(Twig_Environment $twig) | |
{ | |
$function = new Twig_SimpleFunction("__", function ($text, $filename = '', $context = '') use ($twig) { | |
if (!empty($filename)) { | |
if ($twig->getLoader()->exists($filename . '.twig')) { | |
$textdomain = $twig->getLoader()->getCacheKey($filename . '.twig'); | |
$language = $this->user->language; | |
$out = htmlspecialchars($language->translator()->getTranslation($textdomain, $text, $context), ENT_QUOTES, 'UTF-8'); | |
} else { | |
$out = $text; | |
} | |
return $out; | |
} | |
}); | |
$twig->addFunction($function); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment