Hi!

I'm trying to use hook_nodeapi to set a message to the user just before the node is being rendered in the $op = 'view' stage. I'm wrapping this message in the t() function to make it available for translation via 'translate interface' but it doesn't show up when I search for it!

The message displays fine and i've extracted the code into it's own separate module containing only the hook_nodeapi to make it easier to search for errors. This is my code:

function my_module_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
      $message = t("Translate this please.");
      drupal_set_message($message);
      break;
  }
}

I first tried thie code with only the Locale and Content Translation modules activated, no luck. I then installed i18n and enabled all it's features, tried everything again and still no luck. I've emptied the cach a zillion times, run cron and tried to execute the code in Devel's 'Execute php' block to make sure the string must have passed through, still it doesn't show up when I search for it.

I really must be missing something fundamentally here, please assist!

Comments

JoeMcGuire’s picture

What were you hoping to find when you searched? My understand is you'll need to create the language .po document.

If you're looking for a more automated system perhaps the Translation template extractor can help: http://drupal.org/project/potx

More documentation here: http://drupal.org/contribute/translations

jaypan’s picture

Make sure you cause the message to display somewhere first. Translated items will not appear in search results until they have been seen somewhere by someone first.

Contact me to contract me for D7 -> D10/11 migrations.

span’s picture

Thank you for your response.

Unfortunately I've made sure the message has been displayed already. I've had it display as a message with drupal_set_message(), as a title with drupal_set_title() and I've even created a block with hook_block() with the string 'Translate this please.' and of course I've made sure all of these strings have been displayed before trying to search for it in the 'Translate interface'.

I'm really clueless as to what could be at fault here. The way I understand the t() function to work is when it is being run, it checks if the string exists and if it does it shows the right 'language version'. If the string doesn't exist it adds it to the database for future reference.

After looking in the database (locale_source table?) it doesn't seem like the string is ever added, this would implicate the string hasn't been displayed but I've made sure it's been displayed many many times now.

I'd appreciate any comments or pointers as to what I might have missed. Do you have any suggestion on where I can try to ouput my string through t() to make sure it's been shown in an appropriate way?

@JoeMcGuire
I think you misunderstand my problem. I'm not looking for a way to automate the process nor use .po files. I just want the string that is being passed through t() to show up when I search for it in 'Translate interface'. Thank you for your response though.

jaypan’s picture

I'm a little clueless as to why it wouldn't work myself, seems a little strange to me. But one other thing you can try is installing the Localization Client (l10n) module, which allows you to do translations on the page where they appear. Make the error appear on that page, then translate it right there.

Contact me to contract me for D7 -> D10/11 migrations.

jmlavarenne’s picture

This happens to me once in a while. Sometimes switching language on the page while the untranslated string in printed seems to do the trick, i.e. view the original string while browsing your site in another language.

span’s picture

Truly remarkable, thank you for wise word Blackguard (and the rest of you although Blackguard solved it :P).

After making sure the string had been displayed in another language (not default) page by creating a new node on which the message was displayed I could finally find it in the search results. This seems like a bug to me and I will see if I can file a bug report with the locale module.

Thank you.