Problem/Motivation
When re-adding a language, zero translations are imported for that language even if imports are enabled.
Steps to reproduce
- Enable a new language.
- Delete the language
- Enable the same language again.
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | locale-no-imports-after-language-add-2994951-28-with-update.patch | 1.78 KB | neograph734 |
| #28 | locale-no-imports-after-language-add-2994951-28.patch | 1.27 KB | neograph734 |
Comments
Comment #2
lpeabody commentedComment #3
lpeabody commentedThis 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.
Comment #4
lpeabody commentedComment #5
gábor hojtsyHm, 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.
Comment #6
gábor hojtsyComment #7
lpeabody commentedWorking on an update to this.
Comment #8
lpeabody commentedUpdated patch. Removed clear on add and moved to on language delete. Added update hook to remove uninstalled languages from locale translation cache.
Comment #9
gábor hojtsyGetting 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 :)
Comment #16
neograph734There is already a lot of cleanups happening in
locale_configurable_language_delete(). So it could be as simple as this right?Comment #17
neograph734Comment #18
neograph734I was so convinced I had configured git for windows right... :s
Comment #19
smustgrave commentedCan the IS be updated to match the new solution?
Also ran the test locally without the fix and got
Which is good!
Comment #20
neograph734@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.
Comment #21
smustgrave commentedThanks! Think this is ready for committer review.
Comment #23
neograph734Random fail
Comment #24
quietone commentedI'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
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!
Comment #25
neograph734@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.
Comment #26
neograph734Made the requested changed from #24.
Tagging 'needs review' to validate the claim from #25 and determine if the DB update is needed or not.
Comment #27
needs-review-queue-bot commentedThe 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.
Comment #28
neograph734Comment #30
neograph734That one was supposed to fail. Setting to NR to validate the claim from #25 and determine if the DB update is needed or not.
Comment #31
smustgrave commentedBelieve 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.
Comment #32
neograph734Can't that be fixed on commit?