Change record status: 
Project: 
Introduced in branch: 
9.5.x
Introduced in version: 
9.5.8
Description: 

In order to fix the bug #2806009: Installing a module causes translations to be overwritten several additions are made to the API.

The locale batch to update configuration translations can now be instructed to update the langcodes in the configuration. This is only required during extension or site install. Unless you have written custom code to do this outside of the installer of ModuleInstaller it is highly unlikely that you will need to make any changes.

The API additions are:

  • New method LocaleConfigManager::updateDefaultConfigLangcodes()
  • New argument $update_default_config_langcodes to locale_config_batch_build() and locale_config_batch_update_components()
  • New batch callback locale_config_batch_set_config_langcodes()

How to fix an existing site

There is no automatic fix because the incorrect translations look exactly the same as a custom translation added via the UI.

The easiest way is to reinstall from configuration. However this might not possible if you have content.

An alternate approach to fix an existing site

1. Identify problematic rows in locales_target by running the following query:

select language, source, translation from locales_source ls, locales_target lt where ls.lid = lt.lid and source = translation and customized = 1;

... if they are look suspect then run the following query...

delete lt from locales_target lt JOIN locales_source ls ON lt.lid = ls.lid where source = translation and customized = 1;

if you need to exclude some translations the query will be more complex.

2. Use Drush to redo the translations.

Firstly use vendor/bin/drush php to run the following code:

    // Prep system to get update.
    \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
    locale_translation_clear_status();
    locale_translation_flush_projects();
    locale_translation_file_history_delete();

Secondly use drush to update the translations:

drush locale:check
drush locale:update
Impacts: 
Module developers
Site templates, recipes and distribution developers

Comments

kaszarobert’s picture

To show blob fields as text in phpMyAdmin, the first query will be this: select language, CONVERT(source USING utf8), CONVERT(translation USING utf8) from locales_source ls, locales_target lt where ls.lid = lt.lid and source = translation and customized = 1;