Problem/Motivation
Steps to reproduce:
1. Call LocaleConfigManager::getStringTranslation with new source string.
2. A new translation object for that source is returned.
3. Save the translation for this.
4. Call it again with the same new source string.
5. Again a new translation object for that source is returned with the same ID.
6. When trying to save this, you get a duplicate key exception.
For example, that happens when translating a view that has the same source string multiple times.
Proposed resolution
Update the static cache with the new object. Then you get the existing, no longer new translation object.
Remaining tasks
Writing tests.
There is also a bigger problem. It is not possible to save multiple translations of the same source string in locale. For those views, the last identical source string will win and only that translation is stored.
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#19 | multiple_calls_to-2460259-19.patch | 2.3 KB | sasanikolic |
#15 | multiple_calls_to-2460259-12.patch | 2.51 KB | sasanikolic |
#15 | multiple_calls_to-2460259-11-test-only.patch | 1.66 KB | sasanikolic |
#12 | multiple_calls_to-2460259-12.patch | 2.51 KB | sasanikolic |
#11 | multiple_calls_to-2460259-11.patch | 1.66 KB | sasanikolic |
Comments
Comment #1
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedComment #2
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedComment #3
Gábor HojtsyThe fix totally makes sense to me. That would let our changes from the returned object keep being in the cache. Needs tests indeed.
Comment #4
ameenkhan07 CreditAttribution: ameenkhan07 commentedI have begun on testing, i'm a novice at testing so need wee bit time to get a hold of reins :)
Comment #5
ameenkhan07 CreditAttribution: ameenkhan07 commentedsasanikolic: Could you perhaps elaborate on this more?
"There is also a bigger problem. It is not possible to save multiple translations of the same source string in locale. For those views, the last identical source string will win and only that translation is stored."
Comment #6
Gábor Hojtsy@ameenkhan07: that should not be resolved here. @Berdir asked me to open an issue to document it. See #2460823: Document that locale + config translation integration treats string uniqueness the same way as locale itself to discuss.
Comment #7
Gábor HojtsyComment #8
ameenkhan07 CreditAttribution: ameenkhan07 commentedNeed feedback as well
Comment #9
Gábor HojtsyThanks for working on this.
Several lines have whitespace issues. (Not just these).
Look at the no_translation file, it has "Test" as the only string. It does not have a source string "test string". You should use the correct source string.
Also the string does not have a context, you should not pass a context, that will not work either.
Would save() do something useful without setting a translation? In LocaleConfigManager::saveCustomizedTranslation() we set a string and then save. That would be better.
What is being tested here? If the above should not throw an exception that is already tested implicitly. The test would fail in case of an exception.
Comment #11
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedHere is the test, based on the steps written in the issue description.
Comment #12
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedAnd a patch with the fix and the test.
Comment #15
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedRe-upload...
Comment #18
Gábor HojtsyThanks! Patch looks good minus a few small details:
Missing docblock on test method.
Missing space after ()
The test is already complete without these lines, no? If you are to do this, let's at least set yet another different value.
Comment #19
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedComment #20
Gábor HojtsyLooks good, thanks.
Comment #21
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 5ff53d7 and pushed to 8.0.x. Thanks!
Comment #23
Gábor HojtsyYay, thanks!