Closed (fixed)
Project:
Translation template extractor
Version:
8.x-1.1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Jun 2025 at 15:19 UTC
Updated:
10 Nov 2025 at 15:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jvollebregt-swis commentedSorry about that, accidentally made the patch on the 7.x branch
Comment #3
casey commentedThe bug is introduced since twig 3.21.0:
Extract operators logic from ExpressionParser to their own classes
https://github.com/twigphp/Twig/commit/42c82e1e9b88af365b15ed35cb5488f16...
https://github.com/twigphp/Twig/blob/3.x/CHANGELOG:
Comment #4
volmanTwig 3.21.0 not only broke extracting from
|tfilter. Potx now incorrectly extracts variable names containing a dot ({{ node.type }}becomes@nodeinstead of@node.type).This patch expands on #2. It fixes both issues and should work with earlier twig versions as well.
Comment #5
gábor hojtsyCan you put this into an MR? That way tests would run on it too :)
Comment #7
jvollebregt-swis commentedI've put my original patch into an MR. @volman do you have push access to my branch? If not do you want me to add your patch to the branch?
Comment #8
johnatas commentedHello,
I confirm that @volman’s patch #4 works.
Tested on Drupal 11.2.2 and 11.2.3 with potx 1.1.0.
@volman, as mentioned in the previous comment, could you please push the patch to the branch?
Thank you.
Comment #9
volman#4 patch was pushed to MR !33 and the tests are passing.
Comment #10
johnatas commentedThanks @volman.
Everything looks fine to me.
@jvollebregt-swis, does it look good to you as well?
Comment #11
ricovandevin commentedWe can confirm the issue and that this issue is fixed when applying the provided patch.
Comment #12
johnatas commentedComment #13
watergate commentedAlthough already RTBC, I can also confirm the patch (i.e., MR) fixes the issue.
Comment #14
espurnesHello,
The patch solves the translation detection on twigs, but it seems it does not respect the context.
I've tried to export translations in twig files like this:
{{ 'my text'|t({}, {'context': 'my context' }}The translation is exported without context.
Before d11, I was using potx applying the following patch: https://www.drupal.org/project/potx/issues/2816601#comment-14971928
but it no longer applies because that patch modifies some of the lines modified here.
Anyone has faced the context translation issue?
Comment #17
alexpottThis looks good - it fixes the test and preserves compatibility with older versions of Twig. I've also backported the fix to the 7.x branch so that it is ready if we update twig there.
Comment #18
alexpottWe do have test coverage that is now failing on 8.x due to this - https://git.drupalcode.org/issue/potx-3553345/-/jobs/6961106.
7.x does not fail because we're using an older twig version there.
Comment #19
alexpott#14 is an existing bug - see #1299966-27: String context not taken into account when retrieving a translation - this issue does not fix it or break it. I've created #3553786: Extract context from t or trans filter in Twig template to track it and hopefully someone will fix it.
Comment #21
penyaskitoThanks!
Comment #25
ressaThanks for maintaining this great module!
To avoid accidentally making a patch for the wrong branch (which I have done myself countless times) is it possible to set the default GitLab branch to current Drupal (8.x), and not Drupal 7?
Comment #26
alexpott@ressa this one is a bit complex localize.drupal.org is still using the Drupal 7 module so it is vital that all work happens on that branch.
Comment #27
ressaThanks @alexpott, it did cross my mind that something like that might be a factor here ... so thanks for clarifying.