Hi,

The extractor.php only allows the extraction of strings contained inside, for example t(). Now, let's suppose we have some data in an array, that will be processed by t() later; but we want to extract that information for translation.

Example:

$data = array('One', 'Two', 'Three');
foreach($data as $key => &$value) {
  $value = t($value);
}

How can we extract that data? Could we define a comment, for example

// locale: One, Two, Three

that could allow the extractor.php to work with?

Regards,
Fernando Silva

Comments

cog.rusty’s picture

This example could be even worse:

if (...) {  // some condition is  true at run time
  $data = array('One', 'Two', 'Three');
}
else {
  $data = array('Four', 'Five', 'Six');
}
foreach($data as $key => &$value) {
$value = t($value);
}

Even if t() could evaluate the variable at run time (which it can't, I think), this is impossible for extractor. Apparently this is bad code. A bug. It should be something like:

if (...) {  // some condition is  true
  $data = array(t('One', 'Two', 'Three'));
}
else {
  $data = array(t('Four', 'Five', 'Six'));
}
foreach($data as $key => &$value) {
......
}

Sorry if this is not valid php, I don't know php, but you get the idea.

cog.rusty’s picture

All this said, +1 to extractor support for a "// locale: One, Two, Three" kind of thing for cases where it is difficult to put the t() in the code.

cog.rusty’s picture

Ugh... I meant $data = array(t('One'), t('Two'), t('Three'));

gábor hojtsy’s picture

Project: Translation templates for Drupal core » Translation template extractor
Version: master » 5.x-1.x-dev
Component: Miscellaneous » Code
Status: Active » Postponed (maintainer needs more info)

CogRusty, you have shown how to make this code compatible with t(). These examples are very easy to make t() compatible. Maybe you can show me an example, where it is not possible, and where we would really need some meta stuff?

gábor hojtsy’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

No example.