Problem
On a regular page load in Drupal 8, the system currently never enters a new context. However, the config context system starts out with a blank slate and if locale module is enabled, it reacts to the Kernel request event and take the language negotiation results into the context. It does not clear the context's override cache, so any config loaded prior to that will not be override-able. Such as the site name for a very trivial example.
Reproduce manually
- Install http://drupal.org/project/config_translation
- Add at least one foreign language
- Translate your site name (Regional and language > Configuration translation > Site information > Translate) to the desired language
- Switch the page to said desired language
- Site name will not be translated
Propposed solution
1. Re-initialize the context when such a crucial thing changes about it as its language. The user context already re-initializes the context when an account is set on it.
2. Make re-initializing the context clear the existing overrides cache on the context.
Note that this also let us remove some duplicate code, since we can actually reuse the existing configContext() response logic, which re-initializing the context will fire.
Comment | File | Size | Author |
---|---|---|---|
#18 | 13-18-interdiff.txt | 633 bytes | alexpott |
#18 | 1934964.config-context-reinit.18.testonly.patch | 2.57 KB | alexpott |
#18 | 1934964.config-context-reinit.18.patch | 4.25 KB | alexpott |
#16 | 13-15-interdiff.txt | 1.67 KB | alexpott |
#16 | 1934964.config-context-reinit.15.patch | 4.25 KB | alexpott |
Comments
Comment #1
Gábor HojtsyNeeds tests. Settings needs review for bot.
Comment #2
Gábor HojtsyComment #3
vijaycs85Applied patch and checked the translation strings with config_translation module. Patch in #1 fixes the problem.
Comment #4
andymartha CreditAttribution: andymartha commentedI can confirm that after taking these steps on a Drupal 8.x-dev download from March 6, 2013:
- Install http://drupal.org/project/config_translation
- Add at least one foreign language
- Translate your site name (Regional and language > Configuration translation > Site information > Translate) to the desired language
- Switch the page to said desired language
- Site name will not be translated
and after applying the patch from #1 the problem was fixed and the site was translated.
See attached screenshots.
Comment #5
Gábor HojtsyThanks for cross-testing manually. I think it would be very valuable to have automated tests for this. I tried to whip together something but it does not fail! I cannot really figure out why. Anybody have insights? Based on what we do manually to reproduce the issue, the test should fail, right? No?
Comment #6
Gábor HojtsyBTW the reason we did not have tests for this is that all the config override tests (including locale) are unit test based, so they are not meant / targeted to test the full cycle of an override getting into the output of the webpage. That is why I needed to open a totally new webtestbase based test.
Comment #7
alexpottYep #1934712: Merge system.timezone config object into system.date proves we have the issue... once system.timezone is merged into system.date we can no longer localise date and times :(
Comment #8
nevergone CreditAttribution: nevergone commented#0 patch re-rerolled.
Comment #9
Gábor HojtsyI've seen @nevergone reproduce the bug and express his joy seeing it fixed with the patch BTW :) That does not save us from needing to produce a failing test :) Also adding #SprintWeekend tag for sprint weekend.
Comment #10
alexpottHere is a failing test and patch with the fix and test... only system.performance, system.file and system.timezone are read before language negotiation... that's why the system.site test does not work.
Comment #11
alexpottFixing tags :)
Comment #12
Gábor HojtsyThe name of the method is not good anymore :)
There is no explanation why you do this?!
This is pretty odd. If the admin page shows the localised version of the setting, that would be a problem. The regular admin pages should not show localised settings at any time. (Date formats have some custom implementation for this for some reason, but the rest of the forms should use the override free context).
So testing for this actually exposes the bug that overrides are actually used on this form. The prior test I did did not use the admin forms, but instead see the effect on frontend output.
Is there another setting we can test with that has an easily testable frontend effect? I've seen people reproduce the site name issue and I reproduced and debugged it myself. So it is strange it would not be useful in the test...
Comment #13
alexpottHmmm... okay managed to get a failing test by adding
to the test.
This should resolve @Gaborhojtsy's objections form #12 as it's now using his system.site override test.
Comment #14
alexpottOkay... found the first use of system.site... it's PathProcessorFront::processInbound() and this is called before language is negotiated. Will update code comment.
Comment #15
Gábor HojtsyMake sense :) Thanks for keeping it to the site name override, which is the most natural example to work with :) Only found two issues.
Too much // :D
Also core/modules/config/tests/config_test/config/locale.config.fr.system.site.yml missing from both test only and the other patch.
Comment #16
alexpottUpdated comment to reflect discoveries...
Comment #17
Gábor Hojtsy#15 problems still stand.
Comment #18
alexpottAnd finally (hopefully) a correct working and failing patch...
Comment #19
Gábor HojtsyLooks great to me now :) The fix wil also make #1934712: Merge system.timezone config object into system.date work where another failing test reproduces the issue, so that should be two great reasons to commit :)
Comment #20
Gábor Hojtsy#18: 1934964.config-context-reinit.18.patch queued for re-testing.
Comment #21
Gábor Hojtsy#18: 1934964.config-context-reinit.18.testonly.patch queued for re-testing.
Comment #22
Gábor HojtsyUpping to major since even though you can save translations for your site name and other basic things, they will never be used on display until this is fixed.
Comment #23
webchickWell that definitely seems sub-optimal.
Committed and pushed to 8.x. Thanks!
Comment #24
Gábor HojtsyThanks!