Problem/Motivation

Uninstalling a module removes its translation project data through locale_system_remove().
This deletes the locale_file history and the locale.project record.

If another module is installed later in the same request, the data comes back. Updates that run in one updb do exactly this. The project list is rebuilt from caches that still contain the uninstalled module:

  • locale_translation_project_list() keeps its result in drupal_static().
  • locale_translation_build_projects() writes a locale.project record for every project in that list.

With a translatable language, /admin/reports/translations then lists a project that is not installed. TranslationStatusForm::prepareUpdateData() also logs three PHP warnings (see #3270052):

Warning: Undefined array key "lockr" in ...TranslationStatusForm->prepareUpdateData()
Warning: Attempt to read property "info" on null ...
Warning: Trying to access array offset on null ...

Steps to reproduce

  1. Install locale with a second language (e.g. es) and enable translation import (translation.import_enabled).
  2. Install a module that has its own translation project, such as a contrib module with a project: key in its .info.yml.
  3. In one request, for example an update hook or a script, uninstall that module and then install any other module
  4. Look at the locale.project key/value collection and at locale_file. The uninstalled project is back.
  5. Open /admin/reports/translations. It lists the removed project, and the warnings above appear

Proposed resolution

Reset the stale caches when modules are uninstalled. Both of these would help:

  • Reset drupal_static('locale_translation_project_list') and clear update_project_projects, for example in a locale implementation of hook_modules_uninstalled().
  • Have locale_translation_project_list() reset the module extension list like it already does for themes (->reset() on line 105).

Also consider making locale_translation_build_projects() ignore projects with no installed extension.

Remaining tasks

  • Add a kernel test: install a module with a translation project, uninstall it, install another module in the same request, and assert locale.project and locale_file don't list the removed project.
  • Review the approach for cache invalidation.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

nitesh624 created an issue.