The idiom that the community points to for creating menu links usually looks like this (from \Drupal\Tests\language\Functional\LanguageSwitchingTest::testLanguageSessionSwitchLinks()):

// Add a link to the homepage.
$link = MenuLinkContent::create([
  'title' => 'Home',
  'menu_name' => 'main',
  'bundle' => 'menu_link_content',
  'link' => [['uri' => 'entity:user/2']],

Note that the title is not run through t().

But, yet, the idiom for shortcut links (from standard_install()) is:

// Populate the default shortcut set.
$shortcut = Shortcut::create([
  'shortcut_set' => 'default',
  'title' => t('Add content'),
  'weight' => -20,
  'link' => ['uri' => 'internal:/node/add'],

Note that the title is run through t().

Why are shortcut titles run through translation at creation time, but menu link titles are not? Aren't shortcuts a type of menu link? Shouldn't they be handled the same way?

  • You may have found a bug there - shortcuts are content entities and title is a field, so it probably shouldn't go through t
    – Clive
    Feb 28 at 21:04
  • 2
    Just checked, almost definitely a bug - shortcuts don't render using the interface translation on a vanilla install so using t on the title in standard_install is pointless at best
    – Clive
    Feb 28 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.