twigphp / Twig-extensions

Twig extensions
https://twig.symfony.com/
MIT License
1.45k stars 272 forks source link

I18n: Option to specify alternatives for gettext / ngettext (extension config?) #152

Closed Langmans closed 8 years ago

Langmans commented 9 years ago

As explained by me on https://github.com/oscarotero/Gettext/issues/82#issuecomment-144802849:

I don't want to rely on the php gettext extension. [...] However the problem is that Twig_Extensions_Extension_I18n compiles twig nodes (trans, plural, notes) to use internal php gettext functions(gettext and ngettext), making Gettext\Translator unusable because Gettext\Translator::dpgettext is never being called inside Twig templates.

See I18n.php and Trans.php

FYI, Gettext/Gettext functions are located here:

https://github.com/oscarotero/Gettext/blob/master/src/translator_functions.php

hmpf commented 8 years ago

I want to use Twig_Extensions_Extension_I18n with oscarotero/Gettext as well. With pull-request #166 I can easily switch between using gettext and oscarotero/Gettext depending on whether the first exists and works, without forking Twig_Extensions_Extension_I18n. Only Twig_TokenParser_Trans and and Twig_Node_Trans need to be changed for our needs though.

jaimeperez commented 8 years ago

This needs to be fixed. Being restricted to PHP's gettext extension is a show-stopper for anyone taking translations seriously, not only because the gettext extension is not thread-safe, but also because it requires you to install all the locales you may need on the server, and that's a huge issue when you don't even have access to the server.

So basically there should be a way to specify which functions you want to use for translations, provided they have the same signature as the original gettext() and ngettext() functions.

Since this repository looks a bit unmaintained, I've just created an extension on top of this that solves the problem for the current version and hopefully also for future updates, if any. Using it is extremely simple, it does not require modifications to the templates, and just a minimal modification to the script loading and displaying them.

Langmans commented 8 years ago

[offtopic, alternative] If you use symfony or Silex, it is also possible to use symfony/framework-bundle(for extracting), symfony/twig-bundle and symfony/translation.

fabpot commented 8 years ago

see #193