How to translate "New custom content" in a panel? I have a lot of panels to which I have added bits of text/HTML using the "New custom content" option of the Panels module.

By default, such text does not show up on the Translate Interface screen.  How should I go about translating them?

Two approaches I have found are:


Changing the custom content text format to PHP code and printing the string(s) of text using t().  This then allows me to translate the strings on the Translate Interface screen, but I worry that injecting PHP code like this is a bad precedent.
Since I only have two languages, I can add a second piece of custom content that is localized in the other language.  Then, I can add a visibility rule to each piece of custom content in Panels and set each piece to show only when the user's language matches the content language.  This works but it is time consuming and ugly on the backend.  It would be even worse if I decide to add more languages to my site in the future, which I may do.


Is there a more efficient, maintainable way to translate such custom content?
First of all, I would like to explain why this doesn't "just work", so that you have been given fair warning before I give you new problems. :)
Consider a custom content pane content like:

Welcome %user:name, you have %field_num_messages new messages waiting.


The text here would be substituted before passed to t(), meaning that for each variation of user and number of messages, you would get an entirely new string to translate. For such panes, go with having two separate panes.

A long term solution is slowly being worked on here: Translatable panel titles: Implement i18n_strings but focuses on the pane titles initially.

Generally speaking, the solution is to avoid custom content panes, but I also realize that using them can be very convenient at times.

Finally, here's a piece of code I've used to "force" pane titles to become translatable. I will attempt to later modify it better to your situation, but I figured having a useful answer quickly was better than not. :) You should be able to use $pane to figure out if this is a custom pane, and then pass the text through t().

/**
 * Implements hook_panels_pane_content_alter().
 */
function HOOK_panels_pane_content_alter($content, $pane, $args, $context) {
  if ($content-&gt;title) {
    $content-&gt;title = t($content-&gt;title);
  }
  return $content;
}