Local tasks should honor selected admin interface language (if set)

Created on 14 May 2019, over 5 years ago
Updated 21 June 2024, 6 months ago

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 🐛 Admin toolbar and contextual links should always be rendered in the admin language (if set) Needs work , 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.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Menu system 

Last updated 1 day ago

Created by

🇪🇸Spain tunic Madrid

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    Hiding files to avoid confusion

  • Status changed to RTBC almost 2 years ago
  • 🇫🇮Finland sokru

    Skimmed the code, tested manually and included the manual steps to reproduce the issue.

  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States pwolanin

    Concept 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 \Drupal methods instead of using DI:

    +++ b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php
    @@ -86,6 +86,18 @@ public function build() {
         $config = $this->configuration;
         $cacheability = new CacheableMetadata();
         $cacheability->addCacheableDependency($this->localTaskManager);
    +
    +    $userAdminLangcode = \Drupal::currentUser()->getPreferredAdminLangcode(FALSE);
    +    $negotiation_method_enabled = \Drupal::moduleHandler()->moduleExists('language') && \Drupal::service('language_negotiator')->isNegotiationMethodEnabled('language-user-admin');
    +
    

    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);

  • 🇺🇸United States pwolanin

    Also, 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:

    \Drupal\comment\Plugin\Menu\LocalTask\UnapprovedComments::getTitle()
    

    Or... we should fix the interface/docs

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & pgsql-14.1
    last update over 1 year ago
    Patch Failed to Apply
  • 🇫🇮Finland sokru

    Just a reroll from #68 to 9.5.9 in case some other need if for their projects. #72 and #73 needs to be addressed.

  • 🇧🇪Belgium dieterholvoet Brussels

    This 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.

  • 🇳🇱Netherlands seanB Netherlands

    Reroll for 10.1

  • last update over 1 year ago
    29,458 pass
  • First commit to issue fork.
  • 31:46
    30:44
    Running
  • @recrit opened merge request.
  • 🇺🇸United States recrit

    created 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

  • last update over 1 year ago
    30,151 pass
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    30,151 pass
  • 🇺🇸United States recrit

    Attached is a static patch of MR. 4757 at commit fdb7bfb8.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Not 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?

  • 🇻🇳Vietnam linhnm

    Reroll for 10.3. No other changes.

Production build 0.71.5 2024