-
Notifications
You must be signed in to change notification settings - Fork 1
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
trans filter definition #8
Comments
With that code you no longer use this library, but gettext directly. @vukbgit Can you provide a short example? In the example code and the template it works |
ok, here is a test:
I tried various combinations for the trans filter definition options (is_safe, is_safe_callback, pre_escape, preserves_safety) with no luck, the only working solution I found is to bypass twig-trans library:
FILES: I had to add the .txt extension to be able to upload them |
msgid "my string with tag"
msgstr "" Your msgstr is empty, but it needs to be filled and compiled to mo file. Is that a copy and paste mistake? I wonder why you chose the code from the extract.php file instead of the example.php file? |
hello:
I don't know, maybe I'm missing something about twig-trans and/or gettext logic... |
Did you run a program to fill in the po file? In my setup, we use a translation api to fill in the po files. |
I'm not sure to understand the question, if you mean how I add translations for the source text
I do not have until now set up a web interface to fill in the po files because I had the naive illusion that gettext could be somehow a standard for translators too but so far I have been disappointed, I only managed to make some of my customers install poedit and return po/mo files to me. If you instead are wondering how po files are generated into my application these are the steps:
It worked like a charm in the past but with this last environment (see above) I have problems to make the trans filter work. I suspect some change in Twig (maybe into Twig\Extension\EscaperExtension.php twig_escape_filter function?) but I was not able to find an explanation |
oh sorry was misundesrtanding that there were 2 msgstr's you were expecting to see. |
Something else... are you always using the filter like:
Does it make a difference if you do something like:
Just curious, cause in my app we only ever use the filter in a manner like that, rather than as part of an output string, since with the directly output string |
Only other thing I can think of is something about php8.2. Haven't updated to that yet (though I actually need to start doing that next week, so we'll see I guess). |
nope! Part of my translations are actually stored into a twig variable this way:
But just to meticulous I made a test with the pages I'm working on, reverting the trans filter definition to the one written in the docs:
new text by tag appears into po file, another text by filter does not (and both are correctly displayed into page) |
I added the last example to https://github.com/JBlond/twig-trans/tree/twig-trans-8 Also note: You have to restart the web server or fpm process in order to load changes in the mo files. PHP gettext is aggressively caching the content. |
which version of PHP with?
Yes, I experienced this in the past and in fact I was - pleasantly - surprised when in the current environment (after uploading the po/mo files with the translated text) I had no need to restart the PHP FPM process to see the new transltion be used into the pages. |
The PHP version is 8.2.0 tested on Windows. On Debian, it is PHP 8.2.4 I use msgfmt msgfmt Web_Content.po -o Web_Content.mo |
@vukbgit If you use https://github.com/JBlond/twig-trans/tree/twig-trans-8 does the example work on your setup? |
Hey JBlond, sorry I couldn't find the time to test the above version yet, but I stumbled over issue #4 and I think it applies to my situation too: generating twig templates cache and translations inserted by filter not showing up into po file. Am I wrong? |
Hello, I have this environment: PHP 8.2, Twig 3.5.1, jblond/twig-trans 1.1.0
Filter was defined as shown into README:
Templates were generated into cache (by a script that once worked without problems) but:
echo gettext("text-to-be-translated");
)$this->env->getFilter('trans')->getCallable()("text-to-be-translated");
Consequently .po files generated by xgettext did not show text to be translated with the trans filter
After digging into Twig code I came up wit the following solution:
Maybe this helps someone else stuck in the same situation
Cheers!
The text was updated successfully, but these errors were encountered: