When retrieving variables that are strings that should be translated, you are not translating them. I was always under the impression that this is necessary, otherwise that default value cannot be translated.

variable_get('extlink_alert_text', 'This link will take you to an external web site. We are not responsible for their content.')

Should be:

variable_get('extlink_alert_text', t('This link will take you to an external web site. We are not responsible for their content.'))

This occurs in both hook_init() and extlink_admin_settings().

As always, thanks for the great work.

CommentFileSizeAuthor
#4 extlink_translate_default.patch2.6 KBquicksketch

Comments

quicksketch’s picture

Title: Trnaslateable Variable Defaults » Translateable Variable Defaults
Category: bug » support

You do not translate values that can be set by administrators. If we used t() for the default (which is cached) then the language returned would not be based on the user's language, but whatever language the cache was set in. If you want to translate variables, you can use the i18n package to set a value for each language.

quicksketch’s picture

Ah, nope looks like I'm incorrect. At least the default e-mail texts are translated as you say in Drupal core.

http://api.lullabot.com/system_site_maintenance_settings

Though interestingly it seems that user.module does some special tricks to avoid the caching problem I described:

http://api.lullabot.com/_user_mail_text

So it looks like the appropriate fix would be to make a special variable retrieval for translated strings. Something sort of like this:

$variable = variable_get('extlink_alert_text', '');
if (!$variable) {
  $variable = t('This link will take you to an external web site. We are not responsible for their content.');
}

This way the translated string doesn't get cached and will be retrieved in a way that matches the user's current language.

zzolo’s picture

This seems like a bad hack, but I guess it is a fair approach given the Drupal variable system.

You should do a check for NULL, as someone could actually specify a blank string.

$variable = variable_get('extlink_alert_text', NULL);
if ($variable === NULL) {
  $variable = t('This link will take you to an external web site. We are not responsible for their content.');
}
quicksketch’s picture

Category: support » bug
Priority: Normal » Minor
Status: Active » Needs review
StatusFileSize
new2.6 KB

Good point there. How does this patch look?

zzolo’s picture

Status: Needs review » Reviewed & tested by the community

Excellent!

quicksketch’s picture

Title: Translateable Variable Defaults » Translatable Variable Defaults
Status: Reviewed & tested by the community » Fixed

Great, committed #4.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.