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.
The Commerce project, specifically commerce_product_ui.module, adds menu callbacks like admin/commerce/products/add/product
for each product type. It works like this:
foreach (commerce_product_types() as $type => $product_type) {
$items['admin/commerce/products/add/' . strtr($type, array('_' => '-'))] = array(
'title' => 'Create !name',
'title arguments' => array('!name' => $product_type['name']),
'description' => $product_type['description'],
'page callback' => 'commerce_product_ui_product_form_wrapper',
'page arguments' => array(commerce_product_new($type)),
'access callback' => 'commerce_product_access',
'access arguments' => array('create', commerce_product_new($type)),
'file' => 'includes/commerce_product_ui.products.inc',
);
}
Note how the 'title arguments' element takes care of inserting the product type name into the translatable string "Create !name". When I enable Administration Language this breaks, and all product creation pages get the literal title "Create !name".
Comments
Comment #1
das-peter CreditAttribution: das-peter at Cando commentedJust stumbled over this and following adjustment (see patch) seems to fix the behaviour.
Comment #2
marcvangendThanks for looking into this. Maybe you can add a couple of lines of documentation? Even though it's only a 2-line patch, I don't understand what's going on...
Comment #3
das-peter CreditAttribution: das-peter at Cando commented@marcvangend Added some documentation. Not sure if it really helps. The idea is to pass following condition on
_menu_item_localize()
:if (!$link_translate || ($item['title'] == $item['link_title'])) {
We need to ensure title and link_title are equal to re-run the translation process. While this seems to work I'm not entirely sure this is the right approach.
Comment #4
marcvangendThanks. It's a bit of a hack indeed, but at least the inline docs and your explanation here helps understand why it works.