Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twig i18n support #82

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

Twig i18n support #82

Langmans opened this issue Oct 1, 2015 · 4 comments

Comments

@Langmans
Copy link

Langmans commented Oct 1, 2015

Is it possible to use the twig i18n extension or has anyone managed to make a different extension that allows us to use gettext/gettext and have php arrays as translation?

{% trans %}
    Hey {{ name }}, I have one apple.
{% plural apple_count %}
    Hey {{ name }}, I have {{ count }} apples.
{% notes %}
    This is shown in the user menu. This string should be shorter than 30 chars
{% endtrans %}

If not, I will have to refactor my code a bit, but I especially liked using the twig variables inside the trans block (gets converted with strtr automatically).

@oscarotero
Copy link
Member

Hi. I'm not familiarized with twig so I don't understand exactly what you want. There's a Twig extractor created by @Exnor to capture the translations (see conversation: #71)

@Langmans
Copy link
Author

Langmans commented Oct 1, 2015

I don't want to rely on the php gettext extension.

I'm using that extractor to compile all the twig files and then capture the compiled php classes. Extracting from twig templates and appending to a Gettext\Translations objects is easy and works just fine.

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

I guess this is out of scope since it's really a twig question rather than a gettext question. @Exnor have you by any chance found a solution?

@MazeChaZer
Copy link

@rubenvincenten I submitted a pull request to fix this: twigphp/Twig-extensions#160

@elcreator
Copy link

https://github.com/elcreator/tempot can be used to extract without the need to compile twig to PHP (i.e. if you haven't proper PHP environment where you have the project files).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants