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. =)

About these ads

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

  1. Pavlos

    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.

    Reply
    1. ykyuen Post author

      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

      Reply
      1. Pavlos

        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?

      2. ykyuen Post author

        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.

    1. ykyuen Post author

      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; ?>
      ...
      
      Reply
      1. Dark

        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

      2. ykyuen Post author

        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 =)

  2. Pingback: Drupal – Panel Pane Title Translation @ 2 | Eureka!

  3. Vasiliy Grotov

    “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))

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s