The menu system allows custom callbacks for menu item titles, with t() being the default.

Title_callbacks other than t() are passed insufficient information. Because - unlike code-based strings - admin-entered ones can be updated, we need a way to update existing locale source records, rather than creating new ones each time a change is made and thus orphaning existing records. An example is custom menu items as created via the menu module. To be able to update, we need a unique identifier for a menu item. But currently menu item title callbacks are passed only the string to be translated.

So it looks like a small change is needed: pass mlid as a second argument to title callbacks other than t().

Comments

nedjo’s picture

Status: Active » Needs review
StatusFileSize
new716 bytes

Patch.

One place this could be used is the i18nmenu module, which references menu source strings by mlid.

Status: Needs review » Needs work

The last submitted patch failed testing.

nedjo’s picture

Status: Needs work » Needs review
StatusFileSize
new746 bytes

Forgot to test for isset().

catch’s picture

Looks very reasonable, probably small enough a change that we don't need a test for it, but I'm wondering if there's either somewhere in core we could use it or extend one of the existing menu tests to pick it up.

nedjo’s picture

Issue tags: +i18n sprint
nedjo’s picture

StatusFileSize
new3.62 KB

Here's the patch with a test.

In the menu_test module we create a menu callback declaring a title callback but not options. This is needed to trigger a callback where the ID might be needed. (If there are callbacks, the menu system loads and feeds an object.)

In menu.test, we fetch the test page and determine if it has the title produced by the title callback, which includes the ID passed to the callback.

Status: Needs review » Needs work

The last submitted patch failed testing.

nedjo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.3 KB
nedjo’s picture

Refreshed the patch after a conflicting change to menu tests. Updated the db query to used in the new test to DB api.

jose reyero’s picture

This feature is badly needed. Still this leaves out the item description. Could we think of a 'localize' callback that is passed the full menu item?

nedjo’s picture

Good question. It would be a large rewrite though of how menus are handled. Currently it's only the title that has a callback, and that callback is used in ways that may not apply to descriptions.

We *could* consider e.g. changing the title callback to return an array of title and description, or adding a description callback, or completely changing the approach. But meantime, I think it's worth fixing this issue in the current implementation.

Status: Needs review » Needs work

The last submitted patch failed testing.

stella’s picture

Status: Needs work » Needs review

Patch passes all tests on a clean installation of HEAD on my local machine. May be related to #381004: locale test is failing

Cheers,
Stella

stella’s picture

Status: Needs review » Reviewed & tested by the community

To summarise this patch:

  • It changes one line of existing code, the mlid of a menu item is passed as the 2nd argument to title callbacks other than t()
  • Includes a simpletest, which makes uses of hook_menu() implementation in the menu_test.module
  • All tests pass.

It's a trivial enough change and works well, so I feel it's ready to be marked RTBC.

Cheers,
Stella

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

stella’s picture

Status: Needs work » Needs review
stella’s picture

Status: Needs review » Reviewed & tested by the community

Re-setting to RTBC now that testbot has passed the final patch again.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

this looks incomplete, and possibly just wrong. Are you counting on this for translation of user-entered links? You will never reach this code because of:

  if (!$link_translate || ($item['title'] == $item['link_title'])) {

If nothing else, it's only going to work for the case where there are no title arguments specified.

I agree this is pretty trivial as a patch, but for D7 we should be looking for a more fundamental fix if this is an important issue.

muriqui’s picture

Version: 7.x-dev » 8.x-dev

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lauriii’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

_menu_item_localize has been removed in #2301319: MenuLinkNG part5: Remove dead code; and party!, and the way menu links get generated has changed significantly in Drupal 8, so I'm closing this as outdated. Thanks for all the contributors and sorry that we didn't get to fix this before this occurred.