Problem/Motivation
potx extracts Drupal.t() and Drupal.formatPlural() calls of JavaScript with regular expressions. These forms of the calls are reported as faulty or not seen, and their strings are not in the templates:
-
A trailing comma after the last argument. Core's JavaScript is formatted with a trailing comma in multi-line calls:
Drupal.t( 'Changes made in this table will not be saved until the form is submitted.', );The expressions allow a comma after the options only. In a copy of the localize.drupal.org database (to February 2024), such strings of core have lines in every release up to 9.5.11 and 10.0.0-alpha7, and in none of the later Drupal 10 releases, to 10.2.3; the translations of these releases do not have them (checked: "An AJAX HTTP request terminated abnormally.", "Changes made in this table will not be saved until the form is submitted.", "Remove group", "This permission is inherited from the authenticated user role.").
nullin place of the arguments, with options:Drupal.t('…', null, {context: '…'}). The expressions require an object before the options.- Template literals without substitutions:
Drupal.t(`The following files could not be loaded: @dependencies`, {…}). The expressions know single and double quotes only. A template literal with${…}is not a literal string, and it is reported as before.
Strings of a corpus of 51 projects
Drupal 11.4.9 core with its recipes, 33 contrib projects of localize.drupal.org, Drupal 7 core and contrib, potx's own fixtures. Of the 48 faulty JavaScript calls reported for Drupal 11 core, 4 are left, all real: a call with variables in misc/drupal.js, two template literals with ${} in the CKEditor 5 media plugin (source and build), a call in a comment of misc/announce.js.
1. Trailing commas: 26 new source strings of Drupal 11 core, 4 strings in more files, 1 new source string of l10n_server.
| File | Strings |
|---|---|
misc/ajax.js |
An AJAX HTTP request terminated abnormally. Oops, something went wrong. Check your browser's developer console for more details. The response failed verification so will not be processed. Changed (also in more files) |
misc/tableresponsive.js |
Show table cells that were hidden to make the table fit within a small screen. |
misc/vertical-tabs.js |
(active tab) |
modules/block/js/block.admin.js |
1 block is available in the modified list. / @count blocks are available in the modified list. |
modules/ckeditor5/js/ckeditor5.admin.js |
Press the down arrow key to use this divider in the active button list Press the up arrow key to deactivate. Use the right and left arrow keys to move position Available buttons Button divider Active toolbar |
modules/ckeditor5/js/ckeditor5.style.admin.js |
One style configured / @count styles configured |
modules/contextual/js/contextual.toolbar.js |
Tabbing is no longer constrained by the Contextual module. Tabbing is constrained to a set of @contextualsCount and the edit mode toggle. |
modules/contextual/js/toolbar/contextualToolbarModelView.js |
@count contextual link / @count contextual links |
modules/history/js/node-new-comments-link.js |
1 new comment / @count new comments |
modules/locale/js/locale.admin.js |
Changes made in this table will not be saved until the form is submitted. |
modules/media_library/js/media_library.ui.js, themes/claro/js/tableselect.js, themes/default_admin/js/tableselect.js |
1 item selected / @count items selected |
modules/node/js/node.preview.js |
Leaving the preview will cause unsaved changes to be lost. Are you sure you want to leave the preview? CTRL+Left click will prevent this dialog from showing and proceed to the clicked link. |
modules/system/js/system.modules.js |
1 module is available in the modified list. / @count modules are available in the modified list. |
modules/toolbar/js/models/ToolbarModel.js |
The toolbar cannot be set to a horizontal orientation when it is locked. |
modules/user/js/user.permissions.js |
This permission is inherited from the authenticated user role. 1 permission is available in the modified list. / @count permissions are available in the modified list. |
modules/views_ui/js/views-admin.js |
Remove group Add (also in more files) |
themes/claro/js/tableselect.js, themes/default_admin/js/tableselect.js |
Bulk actions are now available. These actions will be applied to all selected items. This can be accessed via the "Skip to bulk actions" link that appears after every enabled checkbox. |
modules/ckeditor5/js/ckeditor5_plugins/drupalMedia/src/…, modules/media/js/media_embed_ckeditor.theme.js |
An error occurred while trying to preview the media. Save your work and reload this page. (also in more files) Not all functionality may be available because some information could not be retrieved. (also in more files) |
l10n_server l10n_community/js/editor.js |
1 pending change on this page / @count pending changes on this page |
2. null arguments: 2 new source strings of Drupal 11 core, modules/ckeditor5/js/ckeditor5.admin.js, with their contexts:
- "The toolbar buttons that don't fit the user's browser window width will be grouped in a dropdown. …" (context: CKEditor 5 toolbar help text, default, no explicit wrapping breakpoint)
- "You have configured a multi-row toolbar by using an explicit wrapping breakpoint. …" (context: CKEditor 5 toolbar help text, with explicit wrapping breakpoint)
3. Template literals: 2 new source strings of Drupal 11 core:
- "The following files could not be loaded: @dependencies" (
misc/ajax.js,misc/htmx/htmx-utils.js) - "@listType button @label" (
modules/ckeditor5/js/ckeditor5.admin.js)
Proposed resolution
One commit for each, with a test in JsExtractorTest:
- The expressions allow a comma after the string of
Drupal.t()and the plural ofDrupal.formatPlural(). - The expressions allow
nullin place of the arguments. - The strings of the expressions are also template literals without
${, with the escapes of a double-quoted string.
LLM disclosure
LLM was used to find, diagnose explain and fix this issue. With human review.
Issue fork potx-3630552
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
gábor hojtsyCalls at start of file are highly theoretical, would not make much sense in Drupal as the output would not be used for anything.
Comment #5
gábor hojtsy