Problem/Motivation
#3274237: [META] Porting localization server module to Drupal 9, we are at a point, where we can import projects and releases and parse them.
When looking at the numbers, there are different string counts, compared to the counts on l.d.o.
l10n_server module on localize.drupal.org (D7)
Project Version Strings Lines Files Warnings
Drupal core 10.0.0-alpha4 10594 - 7650 174
Drupal core 9.4.0-alpha1 10848 - 7818 175
Drupal core 8.9.20 9994 - 7180 141
Drupal core 7.89 4696 - 475 76
See https://localize.drupal.org/translate/projects/drupal/releases
l10n_server module ported (D9), PHP 8.1.7
Project Version Strings Lines Files Warnings
Drupal core 10.0.0-alpha4 10244 15588 7650 174
Drupal core 9.4.0-alpha1 10493 15939 7818 175
Drupal core 8.9.20 9673 14769 7180 141
Drupal core 7.89 3747 5003 475 70
Drupal 7, drush, PHP 8.1.7
drush potx single --api=7 --folder=../projects/drupal/drupal-7.89
drush potx single --api=8 --folder=../projects/drupal/drupal-8.9.20
drush potx single --api=8 --folder=../projects/drupal/drupal-9.4.0-alpha1
drush potx single --api=8 --folder=../projects/drupal/drupal-10.0.0-alpha4
Project Version Strings Lines Files Warnings
Drupal core 10.0.0-alpha4 10512 - 7650 174
Drupal core 9.4.0-alpha1 10766 - 7818 175
Drupal core 8.9.20 9911 - 7180 141
Drupal core 7.89 4583 - 475 76
Drupal 9, drush, PHP 8.1.7
drush potx single --api=7 --folder=../projects/drupal/drupal-7.89
drush potx single --api=8 --folder=../projects/drupal/drupal-8.9.20
drush potx single --api=8 --folder=../projects/drupal/drupal-9.4.0-alpha1
drush potx single --api=8 --folder=../projects/drupal/drupal-10.0.0-alpha4
Project Version Strings Lines Files Warnings
Drupal core 10.0.0-alpha4 10549 - 7650 174
Drupal core 9.4.0-alpha1 10803 - 7818 175
Drupal core 8.9.20 9942 - 7180 141
Drupal core 7.89 4583 - 475 76
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
gábor hojtsyHm, so the files are exactly the same. You can export a .pot file from the localize.drupal.org UI I think and compare the list of strings there if you don't have a better way yet.
Comment #3
sanduhrsComment #4
sanduhrsComment #5
sanduhrsAttached are patches showing the differences parsing various Drupal releases with Potx D7 vs. Potx D9.
Comment #6
sanduhrsParsing just Views module things get a bit clearer, the following strings are missing from the D9 extraction:
Apparently ist mainly *.yml and some *.twig files.
Looking at the whole code base of a Drupal 9 setup two files do not deliver any results at all:
web/core/themes/claro/templates/node-add-list.html.twigweb/core/themes/olivero/templates/misc/feed-icon.html.twigComment #7
sanduhrsDowngrading in D9 tosymfony/yaml:2.1.0fixes the issues.The files are still different, though.
// edit: I don't get it :/
Comment #8
gábor hojtsyFYI opened #3298360: Strengthen test by adding string count checking to each generated .po file to further strengthen the existing very strong test coverage on potx.
Comment #9
gábor hojtsy@sandurhs: ah, ALL of those in the diff seem to be twig sourced strings where the space before the replacement pattern gets eatean up. It seems to me that is a combination of PHP version and twig version. I can reproduce the same problem locally even on the PHP 7 version of potx (which has a bundled hardcoded Twig vendor directory). Probably the twig included with the module on Drupal 7 has this bug.
Comment #10
sanduhrsAlso, any idea what this is?
Comment #11
sanduhrsAnd these are apparently only in some extractions:
Comment #12
gábor hojtsySo https://github.com/twigphp/Twig/issues/3248 is the reason for the diffs in https://www.drupal.org/files/issues/2022-07-10/Drupal-10.0.0-alpha6-Potx... I believe. We need to keep the vendor twig version compatible with PHP 5 in potx Drupal 7 due to allowed PHP versions there, so we have some upper bounds as to where we can update it I think.
The binary thing I have no idea why it would show up.
Comment #13
gábor hojtsyLooking at the views mini pager example, this is where that comes from:
Also the other two twig examples you cited are pipe-t examples. I wonder what would be special about them in Drupal 7 vs 9.
Comment #14
gábor hojtsyLooking at test coverage for the cases you mentioned in #6:
I think these in the tests should provide enough coverage, they cover similar cases where t is used as a filter in {%set%}:
The default method thing from #13 was not covered, adding coverge for that in #3298454: Add more test coverage for Twig default value case.
Comment #15
gábor hojtsyI committed #3298454: Add more test coverage for Twig default value case, but that did not uncover a bug on Drupal 7 or 8 they were the same.
That said, before that I committed #3298467: Update dependencies: twig to 1.42.5, yaml to 3.4.41, polyfill-ctype to 1.19 which significantly updates Twig to fix the whitespace differences you noticed in #7.
I think given the expanded test coverage and updated Twig in Drupal 7, it would be nice to run another comparison. I suspect now that any remaining difference would be down to which files actually get found while parsing. Or some segfaulting or running out of time of the process for Drupal core at least. It takes a lot of time.
Can you try again with the current dev versions on Drupal 7 and 8/9 of potx and see what's the difference now?
Comment #16
gábor hojtsyComment #17
gábor hojtsyI compared the strings of the current branches on 51 projects using an LLM: Drupal 11 core, 32 Drupal 11 contrib projects and the bluecheese theme, Drupal 7 core and 9 Drupal 7 contrib projects, and the test fixtures of potx for Drupal 5 to 8. The versions were 7.x-3.x at ddb3613 (with Twig 1.42.5 and symfony/yaml 3.4.41 from #3298467: Update dependencies: twig to 1.42.5, yaml to 3.4.41, polyfill-ctype to 1.19), 2.x at d22de3e, and 3.x at 66debe9. Each run was like
drush potx single --folder, with the file names relative to the project.All three versions scanned the same 11,197 files. 7.x-3.x and 3.x extracted the same strings, with the same contexts and plurals, in all projects but core and l10n_server: 3.x extracted 31 more JavaScript strings there, 30 in core and 1 in l10n_server. These are the calls fixed in 3.x by #3630552: JavaScript strings potx does not find: trailing commas, null arguments, template literals: a trailing comma right after the string,
nullin place of the arguments, and template literals. 7.x-3.x currently reports these calls as warnings, like "Drupal.t() calls should have a single literal string as their first parameter.", so it had 182 warnings for core, and 3.x 138.2.x extracted the same strings as 7.x-3.x, except for diff: 2.x currently crashes on the config schema of diff, so its template of diff had none of the 209 strings. 3.x fixed that in #3630545: Config and YAML strings potx misses: invalid schema elements, schema of config dependencies, patterns without keys.
Other differences of the output:
@Translationstring of devel with a raw newline, so their template of devel is not a valid .pot file. 3.x escapes the newline.So with the current branches, the strings of 7.x-3.x and 3.x are the same, except for the JavaScript fixes of 3.x which is good :)