One of the menu tasks.

The huge size is due to removing t() from all the titles. The guts are in includes/menu.inc and modules/system/system.install.

This will need an extractor.php change, warn goba.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ChrisKennedy’s picture

I haven't done any translation, but what about adding a third parameter to t() as a flag that would tell it to just return the original string without any translation? That would allow extractor.php to still find the string and include it as an item to be translated. It seems like it would be useful in this context as well as others.

ChrisKennedy’s picture

Two other simple options would be to make an entirely separate function or to overload the second parameter to t() (e.g. if it's NO_TRANSLATE don't translate the string).

bdragon’s picture

I *DO* have a working extractor.php for this. I just haven't shared it because it still has a bunch of debug code and stuff left in.

bdragon’s picture

FileSize
20.06 KB

To put my code where my mouth is:

Here is an extractor.php that's

A) More than twice as fast.
B) Cleaner.
C) Supports the new way of doing menu titles.
D) 6 lines shorter.

chx’s picture

FileSize
74.21 KB

I cut some corners. No significant change. Very nicely done.

Gábor Hojtsy’s picture

@bdragon: Could you please submit "extractor.php" improvements to the relevant project: Translation template extractor. Also note that the extractor is now split into a common include file shared with a web interface and a cli file (potx-cli.php), which is the new command line tool. After a cursory look, your changes seem to be easily ported to the current extractor code. http://drupal.org/project/potx

Gábor Hojtsy’s picture

Status: Needs review » Needs work

@chx: I checked your latest patch. As you noted on the mailing list, the descriptions still need to be t()-ed at runtime. I also noticed that title arguments are not serialized when stored, although unserialized when used, so there is a small bug in there.

TODO:
- serialize title arguments on storage
- t() description on runtime (noted by chx on the dev list)
- reroll patch against current HEAD (noted by chx on the dev list)

Gábor Hojtsy’s picture

Wait! Isn't it a "PHP injection via the database" vulnerability that this patch blindly executes every callback that comes out of the database? Even not checking for whether that callback exists... Hm... A single weak module on the site to achieve some DB poisoning, and (close to) arbitrary code can be run with defining a desired callback and a parameter list.

chx’s picture

Well, if you have a weak module then that can directly execute b0rken code without running through the database...

Gábor Hojtsy’s picture

I mean a db security hole is immediately extended to a PHP level security hole with this module. It is comparable to having the PHP input format kept intact (which is another nice example of possible database security problems taken to a new level). By the way, as long as the PHP input format is there, we are not introducing new possibilities for holes, so maybe this approach can be left alone.

Any takers to finalize the implementation?

AmrMostafa’s picture

subscribing

Gábor Hojtsy’s picture

Assigned: bdragon » Gábor Hojtsy
Status: Needs work » Needs review
FileSize
81.46 KB

Since nobody was working on this, I took some time to get the patch to core commit level (hopefully). Updates:

- updated to latest 6.x-dev (alls hunks applied with some offset, many hunks failed, needed to fix them manually)
- watchdog became dblog and syslog, apply the changes to these new modules too (php.module required no changes)
- remove t() calls from descriptions and add runtime t() call to menu.inc

Installed and tested this and it works fine, the values are properly added to the menu table, string for localization appear in the locales_source table. Everything seems to be fine. I would welcome reviews, so we can get this fixed soon.

Note that the required system.install table definition changes were already committed earlier by Dries, in anticipation that this menu localization patch will get in soon. Also note that there is no update path for menus yet, but as chx informed me that is postponed to later, as soon as all menu changes accumulate. So system.install is not changed here.

Bdragon, please file an issue against potx module (http://drupal.org/project/potx) with your changes to the extractor. I would be very glad, if you could update your changes to the actual potx-cli.php and potx.inc codebase.

AmrMostafa’s picture

Applied the patch, tested and it works fine

Just a minor typo in block.module:

+      'title_arguments' => array('!key' => $theme->info['name']),

Should be:

+      'title arguments' => array('!key' => $theme->info['name']),
Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
81.46 KB

OK, fixed that small glitch. Seems to be ready(?)

chx’s picture

Status: Reviewed & tested by the community » Needs work

I would not t() the description every time. That's a waste IMO, it's not used anywhere else but the admin* pages, is it?

Gábor Hojtsy’s picture

chx: we only t() the description if it is not empty, be it an admin page or not! Anyway, the node/add/$type menu items also have the descriptions of the node types set as descriptions of the menu items. I don't know of other non-admin parts where a description is used. But how checking for $_GET['q'] and !empty($item->description) would be quicker then simply checking for !empty($item->description) (if the former is what you actually suggest)?

chx’s picture

I was thinking on t'ing in theme_admin_block_content . Or maybe write a preprocess for that theme function, and t() there. It's not used anywhere else, why bother?

Gábor Hojtsy’s picture

Well, it could be used to provide tooltips on menu items (depending on your theme), as well as used on the node/add pages as I have examined. Why close that possibility?

chx’s picture

Status: Needs work » Reviewed & tested by the community

Let it be.

Dries’s picture

Both this issue and the patch have little or no details about the motivation of this patch. I assume this has to do with translating custom menu items? I think some PHP comments are in order to provide some background on the rationale.

When this can be used to translate custom menu items, shouldn't these go into a separate domain?

Gábor Hojtsy’s picture

Oh, yes, missing rationale. The rationale of this patch is to *fix* a localization bug in the menu system. Because all menu items are gathered and stored in the menu table, you need to return menu item titles and descriptions with hook_menu(), which are possible to display in all languages. Therefore t()-ing titles and descriptions in hook_menu() is prohibited, because you get menu items stored in one language, not possible to translate menu items into another language. So we need to store English source strings and translate menu items and descriptions runtime.

Description is simple, since if we have it, we can simply t() it for now. Title is a bit more complex since sometimes we have user defined strings in need of some sanitisation, and so on. So we need a callback stored in the database to invoke when the title needs to be "translated". This patch has nothing to do with translatable user defined menu items yet. In fact it introduces a misuse of t() for user defined menu item titles and descriptions, but because we have no way to translate them to another language in core yet, we are swallowing that up for now.

I just noticed, that we also have descriptions for user defined menu items which are "displayed when hovering over a menu item" according to the help text, so we can have descriptions for menu items anytime, not only on the admin interface.

Gábor Hojtsy’s picture

Or to be shorter, the rationale is very similar to the "later t() with watchdog" patch, where strings needed to be stored in English, and translated later. The menu issue is more complex because we might need a custom callback.

Gábor Hojtsy’s picture

Title: Menu Tasks -- Localization » Allow localization of built-in menu items

Changed title to be more descriptive of the issue at hand

Dries’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the explanation. Can you document this a bit in the PHP code? It's helpful for people who want to get up-to-speed on the menu system. Two or three sentences of text should be enough to make people understand faster what this is about and why it is done on output. Thanks Goba.

If the menu hook or the menu $item struct is documented in the code, we should probably document these two parameters as well. If not in the code, it should go into the handbook here on drupal.org.

Other than the documentation issue, this patch is RTBC. Feel free to mark this RTBC once you went over the PHPdoc/code comments once more. Thanks.

Gábor Hojtsy’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
82.54 KB

OK, updated patch:

- updated to latest Drupal 6.x-dev
- added code comments to _drupal_translate() that it also does translation :)
- added code comments to above the title translation code why we do it there

Was unable to find documentation in the source code about the $items arguments.

Updated online documentation:

- updated all subpages of "the new menu system", removing t() from titles and descriptions: http://drupal.org/node/102338
- added new info to the "upgrading" part: http://drupal.org/node/103114
- added extensive docs with core examples, explaining how titles and descriptions are handled: http://drupal.org/node/140311

New patch attached.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Thanks Gabor! Committed to CVS HEAD.

pwolanin’s picture

note- I'm think I'll have to have to redo the menu.inc part in the patch to enable the multiple menus.

Can you follow up here: http://drupal.org/node/137767

Gábor Hojtsy’s picture

@bdragon: grabbed your extractor.php improvements, worked on it for a day to get it updated to the current potx-cli.php/potx.inc implementation, and committed your changes to the potx module (although commented out your menu implementation for now, as it is not appropriate for Drupal 5). Seems like you really did doubled the speed of the extractor. Thanks! Please submit issues against the potx project in the future, so we can get use of your improvements more smoothly.

Anonymous’s picture

Status: Fixed » Closed (fixed)
dww’s picture

Status: Closed (fixed) » Needs work
Issue tags: +Needs documentation

This change was never documented at http://drupal.org/update/modules/6/7

I found this issue via a lot of cvs archeology while trying to figure out what's going wrong with #818136: Some strings in update.module are not translatable. Seems like perhaps it's just an extractor bug (or at least, input that the extractor is going to have a hard time finding), but if any of the localization experts in here care to take a look, that'd be much appreciated. ;)

Thanks,
-Derek

dww’s picture

Status: Needs work » Closed (fixed)
Issue tags: -Needs documentation

Sorry, I'm an idiot. ;) That's because this change happened in D6 and I was looking in the wrong place. ;) /me facepalms.

That said, if anyone who's familiar with how all this works could take a look at #818136: Some strings in update.module are not translatable that'd be Real Nice(tm)...

Thanks,
-Derek