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:

  1. 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.").

  2. null in place of the arguments, with options: Drupal.t('…', null, {context: '…'}). The expressions require an object before the options.
  3. 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:

  1. The expressions allow a comma after the string of Drupal.t() and the plural of Drupal.formatPlural().
  2. The expressions allow null in place of the arguments.
  3. 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

Command icon 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

gábor hojtsy created an issue. See original summary.

gábor hojtsy’s picture

Title: JavaScript strings potx does not find: trailing commas, null arguments, template literals, calls at the start of a file » JavaScript strings potx does not find: trailing commas, null arguments, template literals
Issue summary: View changes

Calls at start of file are highly theoretical, would not make much sense in Drupal as the output would not be used for anything.

  • gábor hojtsy committed e553a3bc on 3.x
    fix: #3630552 JavaScript strings potx does not find: trailing commas,...
gábor hojtsy’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.