Problem/Motivation

When re-adding a language, zero translations are imported for that language even if imports are enabled.

Steps to reproduce

  1. Enable a new language.
  2. Delete the language
  3. Enable the same language again.
  4. Observe zero translations imported.

Cause of issue

After a language has been deleted, locale does not clear it's cache entry in it's locale.translation_status key_value collection. It seems that the presence of this cache entry lingering causes a future import during a language add operation to result in zero imports.

Proposed resolution

When deleting an installed language (configurable_language entity), clear the translation cache entry in the locale.translation_status key/value collection.

Remaining tasks

Consider restoring the update hook
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

Comments

lpeabody created an issue. See original summary.

lpeabody’s picture

Version: 8.5.x-dev » 8.6.x-dev
lpeabody’s picture

This fixes it for me. It ensures whenever you add a language, if it has a previous cache entry then it expires it before attempting an import.

lpeabody’s picture

Status: Active » Needs review
gábor hojtsy’s picture

Title: When adding a new language, locale imports zero translations even while imports are enabled » Interface translations not downloaded after re-adding previously removed language

Hm, we should be clearing that cache when *removing* the language, no? Otherwise we accept that incorrect data will be lingering in our cache. The reason for the bug sounds like that the cache was filled in with data that is not cleared when the language is removed.

Retitled to be more specific.

gábor hojtsy’s picture

Status: Needs review » Needs work
lpeabody’s picture

Assigned: Unassigned » lpeabody

Working on an update to this.

lpeabody’s picture

Assigned: lpeabody » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.42 KB

Updated patch. Removed clear on add and moved to on language delete. Added update hook to remove uninstalled languages from locale translation cache.

gábor hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Getting there :) Ideally locale_translation_clear_status() would be tied to the config delete, so it happens if a deployment removed a language, not only if the form removed it. (The form would remove the config, so it would have the same effect with the config based solution).

Then needs tests if at all possible and done :)

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

neograph734’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.52 KB

There is already a lot of cleanups happening in locale_configurable_language_delete(). So it could be as simple as this right?

neograph734’s picture

Issue tags: -Needs tests
StatusFileSize
new1.38 KB
neograph734’s picture

I was so convinced I had configured git for windows right... :s

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Can the IS be updated to match the new solution?

Also ran the test locally without the fix and got

Translation status cache emptied
Failed asserting that an array is empty.

Which is good!

neograph734’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

@smustgrave IS updated. The essence is more or less the same, but more focus on cleaning up during deletion (instead of fixing it when enabling) as suggested in #9.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thanks! Think this is ready for committer review.

Status: Reviewed & tested by the community » Needs work
neograph734’s picture

Status: Needs work » Reviewed & tested by the community

Random fail

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

I'm triaging RTBC issues.

Thanks for working on this 5 year old issue and providing a test!

I have read the Issue Summary, comments and the patch. The proposed resolution matches the fix, which is good for reviewers. What I don't see is a fail test but @smustgrave did that locally and reported the results.

I read the patch in #8, which includes an update hook which is no longer in the patch. I am not sure if that should be done here or in a follow up but it is a significant change. I have added discussing this to the remaining items.

https://www.drupal.org/project/drupal/issues/3089764

+++ b/core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
@@ -407,6 +407,10 @@ public function testEnableLanguage() {
+    $translation_status = \Drupal::keyValue('locale.translation_status')->getAll();
+    $this->assertEmpty($translation_status, 'Translation status cache emptied');

Assertions should only have messages if in situations such as a for loop so that the individual failure can be identified.
This can also be one line, and eliminate the variable, $translation_status

I updated the IS with the standard template. Just a bit more to do here!

neograph734’s picture

@quitone, Thanks for having a look. I've left out the update because the issue should theoretically be self-healing.

The locale.translation_status key value store has a timestamp and last_checked date. So, when enough time has elapsed the cache should eventually expire and new translations should be downloaded again. Right?
It might be a good idea to validate this though.

If somebody decides they still want an update hook, just calling locale_translation_clear_status() should be enough. Drupal core always clears all translation caches at once, so there is no need to select specific languages.

neograph734’s picture

Made the requested changed from #24.

Tagging 'needs review' to validate the claim from #25 and determine if the DB update is needed or not.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new122 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

neograph734’s picture

Status: Needs review » Needs work
neograph734’s picture

Status: Needs work » Needs review

That one was supposed to fail. Setting to NR to validate the claim from #25 and determine if the DB update is needed or not.

smustgrave’s picture

Status: Needs review » Needs work

Believe the update hook is incorrect.

11.x is the development branch that D10 releases will be cut from so if this were to land in 10.2 update hook could start there.

neograph734’s picture

Can't that be fixed on commit?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.