Is it possible to translates strings stored in variables?

Concider the following example code:

$sizes = array("Big", "Medium", "Small");

foreach ($sizes as $size) {
  print t("$size");

If the array is small, or well defined, one could easily get around this with something like
switch ($size) {
  case "Big":
  print t("Big");

but with big arrays or many options, this would could get really ugly.



Gábor Hojtsy’s picture

The extractor script is unable to find these out, so if you generate a pot file out of your module, it will not contain those generated dynamically. This is why core and most of contrib modules keep away from doing this. It is advised against, however will work quite fine.