Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Introducing english exports via _features_export_language() was a big win.
Exports done via the UI seem not to use this (checked for views).
Comments
Comment #2
geek-merlinPatch flying in that should fix this.
(Not thoroughly tested yet.)
Comment #3
mpotter CreditAttribution: mpotter at Phase2 commentedYour patch includes a LICENSE file that should not be there.
Also, this needs further investigation. The _features_export_language() is only intended to be used internally when computing the component state. I don't think it was intended to force all exports to be in English. So this will require a lot more input from people in the multi-lingual community to comment and test on this before it gets committed. Given all the side effects of other recent changes for language I am leary about making these kinds of changes at this late stage of development. This change would completely change the current export of features and also likely cause a large number of overrides.
Comment #4
geek-merlinYes here is the correct patch.
Exporting any strings in a non-english language is a bug by itself (meaning the export is not well-defined but dependent on the languege of the logged in user that creates that export) and leads to many people using admin_language as a dirty and error-prone workaround to prevent that.
See how you changed it in drush to do it right:
(My patch just copied that verrry same code over)
Curently drush does it right and the UI does not. Let's fix that.
Comment #5
geek-merlinHere's a lighter version of that patch that only clears static cache of that language. I'm confident but not totally sure that's enough.
Comment #6
geek-merlinAlso changed drush to only reset static cache, not db cache.
Comment #7
jurgenhaasThe patch from #6 is working really nice, although I wasn't here because of a language issue. In fact I came here because the drupal_flush_all_caches comes with a massive performance hit when you do a drush feature-update-all on a larger site.
Thanks a lot @axel.rutz for this fix, it saves us tons of hours.
Comment #8
zterry95 CreditAttribution: zterry95 commented#6 patch works for me.
Comment #9
zterry95 CreditAttribution: zterry95 commentedComment #10
robertom CreditAttribution: robertom at bmeme commentedattached a rerolled patch
Comment #11
donquixote CreditAttribution: donquixote as a volunteer commentedSome observations. Not sure if they are blockers.
Nested inception
With this patch, we will have cases with multiple levels of "inception" with _features_export_language().
E.g.
- _drush_features_export() calls _features_export_language() to set the language to English temporarily.
- _drush_features_export() calls features_export_render()
- features_export_render() calls _features_export_language() to (again) set the language to English temporarily.
- features_export_render() calls _features_export_language() to "restore" the language back to English.
- _drush_features_export() calls _features_export_language() to "restore" the language back to what it was before.
I currently don't see a real problem with this, it is just a curious observation.
Static reset when restoring original language?
Currently (incl the patch) the functions that set a new language temporarily call drupal_static_reset() to avoid polluted data.
However, when restoring the original language, I don't see anything being reset. Shouldn't this be the case?
Furthermore, if we do this on every call to _features_export_language(), perhaps it should be part of that function?
try / catch / finally?
If there is an exception while the language is set to English, the restoration of the original language will never happen.
To do this, we would need try/catch/finally, possibly with a re-throw.
Restoring the original language would happen in the finally case.
No more flush caches in drush?
For drush, this patch replaces the drupal_flush_all_caches() with a static reset.
What is the implication of this?
Why did we originally clear all caches?
It is great if we don't need to do this anymore, but it would be good to get an idea as to why :)
Also, is this in scope of this issue or should this be a separate issue?
Issue summary
The issue summary is quite short, would be useful to add more info.
Re-roll?
There have been some doc and code style fixes lately, which means this patch no longer applies cleanly.
I suggest to wait at least for #3081268: Non-controversial whitespace code style fixes, before uploading a new patch.
I already tried this patch locally. It applies to an earlier version of 7.x-2.x, and from there I can rebase it cleanly to where I have the local changes. So all is still good.
Comment #12
donquixote CreditAttribution: donquixote as a volunteer commentedProgress / perspective:
As @mpotter mentioned, this change might be risky.
I want to at least test this myself, before I commit anything.
I am also thinking of perhaps doing this in 7.x-3.x, and/or we could make it opt-in somehow?
I will think about it :)
Overall I think the idea is good, and @axel.rutz is spot-on in #4.
I remember having this problem myself in the past, where I or a colleague would export a feature in the "wrong" language.
Comment #13
donquixote CreditAttribution: donquixote as a volunteer commentedSide effects?
There is a possibility that some teams got used to exporting their features in another language (e.g. French) always.
This is a recipe for disaster, but we should know by now that this does not stop people..
Of course a team which does this would have other problems already:
- They cannot use drush for the export, because drush switches to English always.
- They can't use some other operations which also switch to English always. (not sure which, to be checked).
- Likely problems with t() called with non-English strings.
Changing this behavior now would mean that all of a sudden these features would be exported in English instead.
Comment #14
donquixote CreditAttribution: donquixote as a volunteer commentedInconsistency in existing code
I think there are more places where _features_export_language() should be called, but it is not.
E.g. drush_features_diff() calls features_detect_overrides() which calls features_get_normal().
I don't see _features_export_language() being called anywhere in this chain.
Comment #15
donquixote CreditAttribution: donquixote as a volunteer commentedI am sorry, the solution proposed here does not restore consistency drush vs UI.
In drush, the language switch wraps two parts:
- _drush_features_generate_export(), which does all the hook_features_export() pipe stuff.
- features_export_render().
In the UI, with the patch #10, the language switch would only be inside features_export_render().
All the rest would still happen in the currently active language:
- _features_export_build()
- _features_export_generate().
I am not sure atm if this would make a difference.
But we should aim for consistency.
We should also check if other operations suffer from the same problem, e.g. features diff.
Ideally we should add tests..
Comment #16
anrikun CreditAttribution: anrikun commentedAffected by the same bug...