2

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']],
]);
$link->save();

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'],
]);
$shortcut->save();

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?

2
  • 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
    Commented Feb 28, 2021 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
    Commented Feb 28, 2021 at 21:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.