Problem/Motivation
Local task labels are always displayed using the content language, ignoring that users can set their admin language preference (if the site has an admin language preference option set in negotiation). Local task label should honor this config and use the admin interface language. Even if they are in a non-admin pages, they are part of the admin interface.
This is very similar to what is being done in #2313309: Admin toolbar, Navigation and contextual links should always be rendered in the admin language (if set), but for local tasks. It's worth to note that in that issue current patches seems to translate Contextual Links as well (if not, probably a new issue should be created).
Proposed resolution
Render local task labels using the admin language config from language negotiation.
Steps to reproduce
1. Install Drupal with standard install profile
2. Enable following modules language, content_translation, locale
3. Visit /admin/config/regional/language/detection and enable "Account administration pages", submit the form.
4. Add new language at /admin/config/regional/language/add
5. Select just added language on "Administration pages language" dropdown at /user/1/edit
6. Visit /user/1 local tabs are still in English.
7. Apply the patch from MR and clear the caches.
8. Visit /user/1 again, and local tabs are now in translated language.
Remaining tasks
Implement it.
User interface changes
Local task labels will be in an admin-appropriate language. Optionally, a checkbox can be added to make this behavior optional.
API changes
Likely none.
Issue fork drupal-3054641
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tunicComment #3
lussolucaQuick attempt to implement this feature
Comment #5
lussolucaCS fixes
Comment #7
yogeshmpawarComment #8
yogeshmpawarMaybe this patch will pass the tests. Adding patch with an interdiff.
Comment #10
yogeshmpawarRemoving the patch.
Comment #11
dionsjSo far it looks like #5 fixes it on my local test sites (3 different installs with varying degree of customization).
Though it would probably be better to get the failing tests fixed since they seem directly related to the change made by the patch.
Comment #12
malcomio commentedWith the patch from #8 applied on 8.7.5, I get the following fatal error:
Error: Call to undefined method Drupal\Core\Language\Language::get() in Drupal\Core\Menu\LocalTaskManager->getTitle() (line 205 of core/lib/Drupal/Core/Menu/LocalTaskManager.php).The patch from #5 seems to work as expected from my (limited) testing so far.
Comment #14
aimevpI used the patch from #8 and got the same error as @malcomio. I took a look at the code and noticed there were 2 ->get() usages.
I created a new patch and a interdiff. The patch seems to be working now on my local install (D8.8.0).
Comment #16
tunicTests failed:
There were 2 errors:
I guess those tests need an update and add the "string_translation" and "language.default" services.
Comment #17
emek commentedLocal actions needs to be translated as well, I tested with the code that is added in the patch for this issue but for local actions and it seems to work well. Should we add it here or make an own issue for that change?
Comment #19
weseze commentedPatch in #14 breaks more then it fixes.
Setting the language back to the site default language breaks everything when you are not viewing the site in the default language. We should set it back to it's previous value instead. There was no method for getting the default langcode from the stringTranslation service, so I added that.
See attached patch. (patch was against 8.8.4, so migh not validate against latest core)
Comment #21
aleevasTrying to fix failed test from previous patch
Comment #24
raman.b commentedUnrelated test failure
Comment #25
maxpahPatch #21 applied on 9.1 and working well.
Comment #27
duaelfrPatch #21 still applies on 9.2.x and 9.3.x and still works. Thanks! :)
The patch looks good and expands test coverage so let's mark it RTBC to let the testbot do its magic on the last release!
Comment #28
anybodyConfirming RTBC on #21!
Comment #29
larowlanI think we need to provide a BC layer here, i.e. default to NULL, and if not set, use the \Drupal singleton to set the property.
We're adding new API here. Are we sure we want to do that?
Could we instead have setDefaultLangcode return the previously set value (if any)
Tagging for needs subsystem maintainer review for this point.
Comment #30
larowlanComment #31
gábor hojtsy@larowlan asked me to take a look. It is not apparent to me what caching considerations were made, to make sure the tabs are stored / cached with proper caching metadata so language switching will not spill into other versions of the page / component?
Comment #32
philyPatch #21 seems to be working well using Drupal 9.2.1 with French (admin + content) and English (content) languages.
Thanks
Comment #33
jeroentFixed feedback of #29 and #31. Still needs test coverage.
Comment #34
jeroentAlso, as mentioned in #2313309: Admin toolbar, Navigation and contextual links should always be rendered in the admin language (if set) when viewing the tabs in e.g. English when on a RTL language, should we update the styling of the tabs?
Comment #35
jeroentAdded test coverage.
Comment #36
jeroentAs discussed with @Gábor Hojtsy on Slack:
Patch is still missing 2 things:
Comment #37
jeroentFixed 1.
Still need to fix 2. The easiest solution is probably adding a class to the local tasks block and theming the tabs based on that class instead of the dir="rtl" element on the html tag.
Comment #38
jeroentFixed the last item. Tabs are now shown in the preferred admin language.
Comment #40
steveoriolOn D9.2.10 Patch #21 works well.
#38 patch does not apply
and #37 does apply, but is not working for me.
Comment #41
tunicAlthough #21 works well, as reported by #40, several issues were posted later. I think to push forward this issue #38 needs to be rerolled.
Comment #42
jeroentone difference between the patch in #21 and #38 is that the account administration pages detection method should be enabled.
Comment #43
jeroentComment #44
jeroentComment #45
jeroentComment #46
jeroentComment #47
jeroentComment #48
immaculatexavier commentedRerolled an updated patch against #45
Comment #49
immaculatexavier commentedCreated diff for #48
Comment #51
jeroentPatch no longer applies. Needs reroll.
Comment #52
ankithashettyRerolled the patch in #48, thanks!
Comment #53
simohell commentedSomething in this is not working right with 9.4.0.
For first logged in page load on each content page (after clearing Durpal's cache) I get two warnings from the lines added to theme.inc:
Comment #54
jeroentI had the same issue as described in #53. I think something went wrong during the reroll.
I created a new one. Let's see if this one works better.
Comment #55
jeroentLet's see if this fixes the failing tests.
Comment #57
jeroentComment #59
nod_D10 version needed
At this time we would need a D10.1.x patch or MR for this issue.
Comment #60
bhanu951 commentedComment #61
tunicPatch doesn't apply to 10.1.x:
File core/tests/Drupal/KernelTests/Core/Theme/ConfirmClassyCopiesTest.php is not in Drupal 10.1.x. because Classy was removed from core. see #3278415: Remove usages of the JavaScript ES6 build step, the build step itself, and associated dev dependencies.
Comment #63
bhanu951 commentedRerolled patch in #57 for 10.x version.
Comment #64
bhanu951 commentedComment #65
volegerLeft some review comments.
Comment #66
bhanu951 commentedComment #67
phenaproximaLooks like a test still needs an update...?
Comment #68
redwan jamous commentedReroll of #57 for 9.5.x
Comment #69
bhanu951 commentedComment #70
smustgrave commentedHiding files to avoid confusion
Comment #71
sokru commentedSkimmed the code, tested manually and included the manual steps to reproduce the issue.
Comment #72
pwolanin commentedConcept makes sense, I think the patch still needs work, however.
This comment is clearly outdated:
+ @trigger_error('The string_translation service must be passed to ' . __NAMESPACE__ . '\LocalTaskManager::__construct. It was added in Drupal 9.3.0 and will be required before Drupal 10.0.0.', E_USER_DEPRECATED);Also, code style is a little weird - camel case local variables are being added next to snake case existing ones.
This change looks like it's makes calls to
\Drupalmethods instead of using DI:Since you could pass the langcode as an option into the t() call, this seems like a bad idea to change the default langcode:
$this->stringTranslation->setDefaultLangcode($originalLangcode);
Comment #73
pwolanin commentedAlso, I question the approach of setting the langcode when calling getTitle() versus informing the local task plugins about the language they should be using? e.g. set the langcode as part of:
LocalTaskManager::createInstance()I'm also noticing a bug(?) in this local task which is not returning a string:
Or... we should fix the interface/docs
Also… why doesn’t this exist?
\Drupal\Core\StringTranslation\TranslatableMarkup::setOption()looks like to add/change an option you have to extract the string and options and instantiate a new TranslatableMarkup
Comment #74
sokru commentedJust a reroll from #68 to 9.5.9 in case some other need if for their projects. #72 and #73 needs to be addressed.
Comment #76
dieterholvoet commentedThis doesn't seem to work for local tasks added by Views, I guess that's because those translations are stored in config instead of interface translation.
Comment #77
seanbReroll for 10.1
Comment #80
recrit commentedcreated a new issue branch "3054641-11.x" for 11.x with patch #77 and claro templates updated. Let's use this for development and then only post static patches based on the MR 4757
Comment #81
recrit commentedComment #82
recrit commentedAttached is a static patch of MR. 4757 at commit fdb7bfb8.
Comment #83
smustgrave commentedNot sure if it could be 1 change record but think we will need change records for
new template_process hook + secondary_attributes (not sure if these should be separate)
for new parameter needed for LocalTaskManager
Also may need manual visual testing for the css changes.
Also #76 should that be addressed here?
Comment #84
linhnm commentedReroll for 10.3. No other changes.
Comment #85
michael.acampora commentedRe-roll for 11.1.
Comment #89
dench011.3.1
Comment #90
dench011.3.1 patch with fixed preprocess function
Comment #92
kevin w commentedRe-roll the patch for 11.4.4
Comment #93
idiaz.ronceroOn newer Drupal versions, default_admin (heir to gin) theme is shipped and needs this fix as well.
I added support for default_admin on the previous patch against 11.4.4.
Will try to add it also to the MR but since it has changed to be against main branch, there are a lot of conflicts and I don't know if I will have time to sort them out.
Comment #95
idiaz.ronceroI was a little bit worried that the 3054641-11.x branch was misleading as it kept the 11.x in the name even if it was moved to be against main, so I allowed myself to create the 3054641-main branch.
Merge conflicts corrected, and I added the missing default_admin twig template.
Comment #96
tunicIf I'm not wrong this should be "needs review", right?
Comment #97
tunicNot NR, there are tests failing (PHPCS and PHP Stan).