Consider the following code:

          $message = t('Credit card encryption key file creation failed. Check your filepath settings and directory permissions.');
          drupal_set_message($message, 'error');
          watchdog('uc_credit', $message, NULL, WATCHDOG_ERROR);

When extracting translation strings, the watchdog() line throws an error because $message is not a literal string. However, the API page says the third parameter should be NULL if the message is already translated, or not translatable. _potx_find_watchdog_calls() should have an is_null() check on that parameter before throwing an error or calling $save_callback.

Comments

gábor hojtsy’s picture

Status: Active » Closed (works as designed)

Well, the matter of fact is such drupal_set_message() and watchdog() combinations are an unlucky situation as far as code reuse goes. Let me explain.

While drupal_set_message() requires t() (or friends) to be able to translate the strings, watchdog() disallows usage of t() (or friends), because it needs to store the text in English. The drupal_set_message() is displayed to a user watching the page and that user understands the language used for the page with t(). Let's say French, German or Polish. The watchdog() message is potentially displayed to various site admins who might not know all of these languages. If we store the output of t() with watchdog(), a site admin would need to be able to understand messages in all languages used on the site. Also, watchdog() input might end up in server logs depending on your setup, and server logs would not be happy with French, German or Polish text mixing with vanilla English messages from all other apps.

You should pass on the literal string exactly so that Drupal can store it and translate it when the target language of the site admin is known. This is why we ask for the replacement variables separately as well. I say and acknowledge it is unlikely since you need to repeat the same string two times. But this makes it possible to get to a site administrator friendly result in a multilanguage environment.

We are not silencing the watchdog() warning if you use NULL, since as your example shows using NULL does not mean you understood the implications of what is happening, so we'd better tell you that you should double check your code and ignore the warning if you are really sure you are doing it right.

(Yes, I am also in the process of writing better docs about this).

gábor hojtsy’s picture

Erm, "I say and acknowledge it is unlikely" was intended to be "I say and acknowledge it is unlucky".