Clean up records of strings coming from JavaScript sources

Created on 11 July 2025, about 1 month ago

Motivation

The motivation of this ticket is to delete those locales_source records which belong to a removed Javascript location.

In locales_source, we have only one record for a specific string and context, but locales_location seems to record all occurrences of the same string - context pair.

Of course, in context of locale (interface) translations, items are recorded at the time when they are piped through a t (or formatPlural) function.
So, it can happen that we remove a string and a translation which was only used by a JS (which was removed), but later on a user visits a page which backend also need that string. My proposal is to delete only those sources which have no translation in one language at least.

In Babel's JavaScript alter hook, we are trying to remove unused JS records but we still not have the right functionality.

Proposed resolution

The initial idea:

  1. Move (or keep) Babel's JS alter hook just before Locale module's implementation
  2. Create a snapshot about the records before locale_js_alter (or LocaleHooks::jsAlter) is invoked
  3. After the JS altering is done (both module and theme alters), delete the unnecessary records.

Testing idea: after a short search I found out that e.g, the "Close" string is translated quite widely on Drupal UI, and it is also translated by JS of the Contextual module. So to testing out the functionality, maybe we can benefit from this situation:

  • First case: visit a UI where "Close" is translated in PHP (code or template), translate or don't translate the string, enable Contextual and visit a page where its JS is loaded, then uninstall Contextual
  • Second case: enable Contextual and visit a page where its JS is loaded, then go to a page where "Close" is translated in PHP, then uninstall Contextual
  • Etc.

Remaining tasks

User interface changes

Nothing.

API changes

Nothing.

Data model changes

Nothing.

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024