Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

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

Closed
Langmans opened this issue Oct 1, 2015 · 4 comments

Comments

@Langmans
Copy link

Langmans commented Oct 1, 2015

As explained by me on php-gettext/Gettext#82 (comment):

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
Copy link

hmpf commented Mar 4, 2016

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.

hmpf added a commit to simplesamlphp/simplesamlphp that referenced this issue Mar 7, 2016
@jaimeperez
Copy link

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
Copy link
Author

[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
Copy link
Contributor

fabpot commented Sep 30, 2016

see #193

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
4 participants