Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Olen on
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.
Rgds.
Comments
Sure it is
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.