Skip to content

Instantly share code, notes, and snippets.

@nfreear
Created February 7, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfreear/cee98d29dfa2f317296afafcd512a586 to your computer and use it in GitHub Desktop.
Save nfreear/cee98d29dfa2f317296afafcd512a586 to your computer and use it in GitHub Desktop.
<?php
/**
* Twig-translate-function.php
*
* @link https://twig.symfony.com/doc/1.x/advanced.html#filters
*/
$twig = new Twig_Environment($loader);
$twig->addFunction(new \Twig_SimpleFunction('translate', function ($str) {
return gettext( $str );
}));
?>
#
#: example.twig
#
{# <?php fake php #}
{# Trans: Was: 'Assignments' #}
<p>{{ translate('My assignments') }}</p>
#
#: bash
#
xgettext --default-domain=messages -p ./lang -L PHP --keyword=translate -cTrans: --force-po templates/*/*.twig
# End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment