Drupal – Panel Pane Title Translation @ 1

In Panel page, we can configure the pane title at the content page.

 

By default, we could not translate these pane titles in Translate Interface. To fix this problem, we can override the template variable before rendering the panel pane. This could be done by add the template_preprocess_panels_pane() function in the theme template.php

function <theme>_preprocess_panels_pane(&$vars) {
    $content = $vars['output'];
    $vars['title'] = !empty($content->title) ? t('@title', array('@title' => $content->title)) : '';
}

 

Reload the panel page in the translate content first, then you can find the pane title in the Translate Interface.

 

Done =)

Next: Drupal – Panel Pane Title Translation @ 2

Update @ 2012-01-23: For Drupal 7 users, there is a patch in Panel which makes the Panel title translatable in Translate interface. For more information, please refer to this discussion. Thanks Anon. =)

17 thoughts on “Drupal – Panel Pane Title Translation @ 1”

  1. Hi and thanks for this useful tutorial. I want to ask you if there is a way to translate the panel title. Thanks in advance.

    Like

    1. 1. Copy the page.tpl.php to your theme folder
      2. Make the changes as follow

      ...
      <div id="content-inner-inner" class="content-inner-inner inner">
        <?php if ($title): ?>
          <!--h1 class="title"><?php print $title; ?></h1-->
          <h1 class="title"><?php print t($title); ?></h1>
        <?php endif; ?>
      ...
      

       

      3. Refresh the page and you should be able to find the title text in translate interface

      Like

      1. Thanks for your answer but it didn’t work for me. I use sky theme (6.x) which already has a page.tpl.php file. There i replaced $title; with t($title); . In the panel i use i override user%user page. There i put as title the “Profile of %user:user-raw” token. Now in the translate interface when i search for the string “Profile of” i see the strings for every user and i have to translate them one by one. Can i fix this?

        Like

      2. ic. Then you can try this
        1. Copy the page.tpl.php to page-user.tpl.php.

        2. Edit the page-user.tpl.php as follow

        ...
        <div id="content-inner-inner" class="content-inner-inner inner">
          <?php if ($title): ?>
            <!--h1 class="title"><?php print $title; ?></h1-->
            <h1 class="title"><?php print t('Profile of ') . $title; ?></h1>
          <?php endif; ?>
        ...
        

         

        3. In you panel page setting, just keep %user:user-raw token.

        4. You should able to find “Profile of ” in translate interface.

        Like

    1. you could try using the page.tpl.php and wrap the h1 title with t().

      ...
      <?php if ($title): ?>
        <h1 class="title"><?php print t($title); ?></h1>
      <?php endif; ?>
      ...
      

      Like

      1. That is the best way. IMHO.
        I’m looking how to translate taxonomy terms in views and panels titles. Have you ever been tried that? Thank You

        Like

      2. For Panel title, you can refer to the approach in my previous comment using the page.tpl.php.

        For Taxonomy terms translation, you can download and enable the i18n module, Then you will find the Multilingual options by editing a vocabulary.

        hope this help =)

        Like

  2. “t($content->title)”
    It’s incorrect.

    From API refs:
    “Because t() is designed for handling code-based strings, in almost all cases, the actual string and not a variable must be passed through t().”

    The correct way is:
    t(‘@title’, array(‘@title’ => $vars[‘output’]->title))

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.