Hi,

I've got Panels 3.0 installed. Love it. Thanks.

One issue: I've got a bi-lingual site, and I can't figure out how to translate the overridden Pane titles. Let's say I've got a Pane that uses the title "coming events". If I search for that text in the "translate interface" admin page, it doesn't show up.

Suggestions?

dru

CommentFileSizeAuthor
#36 translate-pane-titles-568740-36.patch902 bytesemattias

Comments

druojajay’s picture

Here's my rather hacky workaround for now. In page.tpl.php, I replaced:

print $content;

With:

/* hacky translation for certain things that Drupal translation doesn't handle */
        
$content_trans1 = str_replace('<h2 class="pane-title">What\'s New?</h2>', '<h2 class="pane-title">Quoi de Neuf?</h2>', $content);

$content_trans2 = str_replace('<h2 class="pane-title">Coming Events</h2>', '<h2 class="pane-title">&Eacute;v&eacute;nements &agrave; venir</h2>', $content_trans1);

$content_trans3 = str_replace('<h2 class="pane-title">About</h2>', '<h2 class="pane-title">&Agrave; propos</h2>', $content_trans2);
        
global $language; 
if($language->name != "English") {

                print $content_trans3;

        } else { 

                print $content;

        }

...where "What's New" and the like are the pane titles I wanted to translate. Would love to know if there's a better way, though.

dasjo’s picture

i have this problem as well. would be great, if panels added its panel-page-title-overrides to translation as for example views does it for block titles...

the hack stated above might work, but it's kind of dirty ;)

Ghostthinker’s picture

Issue tags: +i18n, +localization, +translate

Hi,
I have the same problem. The i18n module is great, just like panels. I think the problem with this is, that the use of the translation function t() in a field with dynamic content (user generated text, just like "empty text" of views) would probably spam the string table? I don't know.

I had a quick look over the (massiv)panels module and was able to t() the titel of panes, not of panles

. Maybe it's a cache thing, maybe the related stuff is in ctools, I again don't know. Anyone with more info about that?

merlinofchaos’s picture

Unlike Views, Panels actually has no mechanism at all for translation. This is something that we need to consider and figure out how to architect in. It's something that will probably happen after the Views 3 translation system is complete. We can then try to rework Panels to utilize the same architecture so that translators have a consistent experience.

zilverdistel’s picture

I altered the folowing code (panels.module, line 1030 starting with $vars['title'])

  $vars['admin_links'] = '';
  if (user_access('view pane admin links') && !empty($content->admin_links)) {
    $vars['admin_links'] = theme('links', $content->admin_links);
  }

  $vars['title'] = !empty($content->title) ? $content->title : '';

  $vars['feeds'] = !empty($content->feeds) ? implode(' ', $content->feeds) : '';
  $vars['content'] = !empty($content->content) ? $content->content : '';

to

  $vars['admin_links'] = '';
  if (user_access('view pane admin links') && !empty($content->admin_links)) {
    $vars['admin_links'] = theme('links', $content->admin_links);
  }

  $vars['title'] = !empty($content->title) ? t($content->title) : '';

  $vars['feeds'] = !empty($content->feeds) ? implode(' ', $content->feeds) : '';
  $vars['content'] = !empty($content->content) ? $content->content : '';

and my problem is fixed (for now) ...

blueblade’s picture

same problem here...

ducdebreme’s picture

Found a solution: there are some panel hooks available.
The translation can be done by implementing hook_ctools_context_converter_alter()
Mind the call by reference to value

/**
 * Implementation of hook_ctools_context_converter_alter()
 * 
 * @param $context
 * @param $converter
 * @param $value
 * @return unknown_type
 */
function my_module_ctools_context_converter_alter(&$context, $converter, &$value) {
  // translate the taxonomy term (vocabulary is in mode "Localize terms")
  $tid = $context->data->tid;
  $value = tt("taxonomy:term:$tid:name", $context->data->name);
}
blueblade’s picture

Hi ducdebreme,

What a great news! how do you implement that tho?

BB

iamjon’s picture

subscribing

iamjon’s picture

Component: Display rendering » Code

I'm not too sure which way is the best to do this, here is my solution.

I exported all my panels, panes and mini panels to code using the bulk export module. I then searched for the specific titles that needed translating.
I first tried wrapping the text title in the t() function so
'override_title_text' => 'Some Text', became 'override_title_text' => t('Some Text'),
Unfortunately that did not work. (At least it did not work instantly)

What did work was at the beginning of the the mymodule_default_page_manager function that created the text, I declared a variable which was string wrapped in the t() function.
function mymodule_default_page_manager_pages() {
$somevarible= t('Some Text');
....
}

Searching for the string worked instantly and I was able to translate.

The reason I chose to go this route was because it didn't involve hacking the module. I would love if someone could let us know which of the above workarounds is recommended until this issue is fixed.

merlinofchaos’s picture

Exporting and wrapping in t() is a lovely workaround until we can get a proper translation method into the exports.

iamjon’s picture

Thank you so much for the response. Can we mark this as postponed?

nhck’s picture

Can you provide a little longer example iamjon, ducdebreme - i don't really understand how you implemented this?

paymentadmin’s picture

Hello, here is my recipe:

I'm using token + page title modules, and I set in "/admin/content/page_title" [page-title] for all pages

Then I made some changes in panels include file "modules/panels/includes/display-render.inc":

Here it is:


function panels_display_get_title($display) {
  switch ($display->hide_title) {
    case PANELS_TITLE_NONE:
      return '';
    case PANELS_TITLE_PANE:
      //return isset($display->stored_pane_title) ? $display->stored_pane_title : '';
        return NULL;
    case PANELS_TITLE_FIXED:
    case FALSE; // For old exported panels that are not in the database.
      if (!empty($display->title)) {
        return filter_xss_admin(ctools_context_keyword_substitute($display->title, array(), $display->context));
      }
      return NULL;
  }
}

I changed the way of title rendering for PANELS_TITLE_PANE. It returns NULL.
So I set "title type: from pane" for any panels page. And I created two content-panes with PHP-Filter and with language rules (One for English, and one for Russian).

In english pane I wrote:

 drupal_set_title("Hello!");

And I've got needed title. And the same way for russian pane:

 drupal_set_title("Привет!");

Good luck!

iamjon’s picture

nhck

I used the bulk exporter module .
Basically the module allows you to take all your panels and put them into a custom module of your own.

Go to admin/build/bulkexport
It gives you a list of all your panels you can either select the ones that need to be translated or select all
It also asks you for a module name. Give it a name. For the rest of the example we are going to use "yourmodule"

When you click the export button you are taken to a new screen which tells you what to put into the various module files
Go to sites/all/modules and create a folder with the module name you created earlier ("yourmodule").
In it you need to create 4 files:
yourmodule.info, yourmodule.module, yourmodule.panels_default.inc, yourmodule.pages_default.inc

You copy the contents of the the four text areas into the four files.

Go to admin/build/modules/list turn on the module just made.

Clear the caches And go to /admin/build/pages

If everything worked well you will see overridden instead of normal. This means that the panel exists in code but the system is using the version that is in the db.
Click revert (Please back up your db before) and the panel will switch to "in code".

In yourmodule.panels_default.inc abd yourmodule.pages_default.inc search for the specific strings you want translated and wrap the strings in a t() function.
I needed 'override_title_text' => 'Some Text', to become 'override_title_text' => t('Some Text'), and $display->title = 'Articles'; to be $display->title = t('Articles');

Once you've wrapped them in the t() function
Clear your cache again and go to admin/build/translate/search if everything works you can find the string there and translate it with the system

Good luck

sagannotcarl’s picture

Subscribing. Thanks for the workaround.

@iamjon: the Features module is also handy for exporting panels (in addition to so much more!)

Vote_Sizing_Steve’s picture

Subscribing.

drewish’s picture

subscribing.

henrijs.seso’s picture

subscribing. cheering.

fnikola’s picture

Hi iamjon,

Thanks for the detailed instructions. I'm having an issue when I export the panel pages I only see 3 text areas (yourmodule.info, yourmodule.module, yourmodule.pages_default.inc) - the yourmodule.panels_default.inc is not created so I have no code to place in that file and therefore did not include that file in the yourmodule folder. I went ahead with the rest of the steps (clear cache, revert, wrap the page title in the t() function, clear the cache), but I do not see the page titles in the translation.

I'm trying to determine what is missing in the yourmodule.panels_default.inc file so I can add it.

Thanks.

iamjon’s picture

hi fnikola,
The latest version of panels and bulk exporter will give you another text area called pipelines.
I think the reason you have three is because you don't have any mini panels.
I tried on a site that didn't have a mini panels and I also had three (four if you include pipelines).
Export everything to code.
Installl/turn on the module.
To check if the module is catching once it's on check sure that all your pages have been switched to overridden instead of normal (admin/build/pages/list) , revert them to code (click edit revert...just make sure to backup your db before)
Once this is done, search for the string your want to translate in your editor, (I just search for 'title') and wrap it in t(), clear caches, and hopefully it will work.

Good luck.

eliosh’s picture

I found another solution, very quick to implement:


function MYMODULE_preprocess_panels_pane(&$vars) {
    $content = $vars['output'];
    $vars['title'] = !empty($content->title) ? t($content->title) : '';
}

this way I can change PANE title but not the whole PANEL title :-|

minghui.yu’s picture

How about this:

Create a View that contains the tile (this view can contain argument to choose language on the fly).

Instead of directly putting Node:Title in your panels, use the title from the View to put it in panel.

Vote_Sizing_Steve’s picture

My developer came up with this solution - which I added to my sites/all/themes/{My Theme}/panels/panels-pane.tpl.php:

<?php
// $Id: panels-pane.tpl.php,v 1.1.2.1 2009/10/13 21:38:52 merlinofchaos Exp $
/**
 * @file panels-pane.tpl.php
 * Main panel pane template
 *
 * Variables available:
 * - $pane->type: the content type inside this pane
 * - $pane->subtype: The subtype, if applicable. If a view it will be the
 *   view name; if a node it will be the nid, etc.
 * - $title: The title of the content
 * - $content: The actual content
 * - $links: Any links associated with the content
 * - $more: An optional 'more' link (destination only)
 * - $admin_links: Administrative links associated with the content
 * - $feeds: Any feed icons or associated with the content
 * - $display: The complete panels display object containing all kinds of
 *   data including the contexts and all of the other panes being displayed.
 */
?>
<div class="<?php print $classes; ?>" <?php print $id; ?>>
  <?php if ($admin_links): ?>
    <div class="admin-links panel-hide">
      <?php print $admin_links; ?>
    </div>
  <?php endif; ?>

  <?php if ($title): ?>
    <h2 class="pane-title"><?php print t($title); ?></h2>
  <?php endif; ?>

  <?php if ($feeds): ?>
    <div class="feed">
      <?php print $feeds; ?>
    </div>
  <?php endif; ?>

  <div class="pane-content">
    <?php print $content; ?>
  </div>

  <?php if ($links): ?>
    <div class="links">
      <?php print $links; ?>
    </div>
  <?php endif; ?>

  <?php if ($more): ?>
    <div class="more-link">
      <?php print $more; ?>
    </div>
  <?php endif; ?>
</div> 
perceptum’s picture

Thanks. This worked very well. Appreciate the hint!

Bryan

perceptum’s picture

Just a side note... once you pass the strings through t() and start looking for them in the translate interface UI - dont forget the search is case sensitive. I spent a little while looking for the strings, thinking the template wasnt working ... but my search was in lower case and the string was in upper case.

HTH

joachim’s picture

AFAIK, using t() for user or admin-input strings is wrong, though I'm not quite sure what you're meant to do instead.

bibo’s picture

Even if the solution of #24 is dirty, it's the easiest way that actually works no matter the pane source (block, view, quicktab etc).

This method easily leads to re-translating the same strings like: original => custom => (custom treated as original) => custom, which will get messy and confusing really fast. Not to mention the unnecessary localization string duplicates, and mixups. Some pane titles are translated through their sources (like views), and we don't want to re-translate these.

I avoided this problem by translating only titles that I've overridden in the panel settings, as I noticed overridden titles just don't get translated. I took the panels-pane.tpl.php template approach, but changed:
<h2 class="pane-title"><?php print t($title); ?></h2>

.. to this:

 if($title && $pane->configuration['override_title'] && $pane->configuration['override_title_text']){
   	$title = t($title);
  }

You could also make sure it doesnt get mixed up with other identical strings, by replacing the second line with:
$title = substr(t('Panel:'. $title), 6);

This is still dirty, but it's easy and it works.

AFAIK, using t() for user or admin-input strings is wrong, though I'm not quite sure what you're meant to do instead.

Afaik the non-dirty way would be using tt(), or rather tt() through a wrapper, in a custom module. Something like this. #7 does it by lending the implementation of the taxonomy-module. I believe it would make sense for panels use a similar approach like taxonomy or notifications (for multilingual pane titles).

moritzz’s picture

Issue tags: +panels

@joachim In D6 "admin-input strings" should be translated though i18n_strings to provide "context" so translation do not get lost every time you change the source string (i.e. the string you enter in pannels admin interface). Implementing this directly in panels would built up another dependency, and it might therefore be better to provide - if possible - a separate i18n_panels (sub-)module.

Therefore: Subscribing as well.

Rhicreate’s picture

For those who need a quick fix for translating Panel titles, you could try this... (probably classed as dirty in this issue, and by no means a permanent solution!)

In the panels where I need a translation of a title I have set them as "No Title" then added a custom block with input type PHP code as follows -

<h1 class="title" id="page-title">
<?php print t('%term:name'); ?>
</h1>

and translated the string in the interface. I presume you could also replace %term:name with other title substitutions...

I'm not sure if this will work in every instance, my panels are receiving an argument of Taxonomy Term ID from the URL, so I only have a couple of panel types to update in this way, it may not be fun to implement if your site has a lot of different panels!

xamount’s picture

In my pane (which happens to be "new custom content"), I just put this php line at the top of my content:

<?php drupal_set_title(t('Your page title goes here')); ?>

Don't forget to set your input format for the pane to be PHP

Rhicreate’s picture

A much better semantic solution! Can't seem to get to work with an argument though... E.g. for all taxonomy term pages? At least not with this code:

drupal_set_title(t('%term:name'));

so guessing that's wrong... what value can I use to put the current term in that translatable title please?

**update** Know I'm not being completely stupid now, because I can't even get a basic string to print out in panels with the set_title function... wonder if it's because Panels has already dealt with this, and it won't reset again.

zilverdistel’s picture

The method in #24 could be improved by using a template_preprocess function. Something like

function mytheme_preprocess_panels_pane(&$vars) {
  $vars['title'] = t($vars['title']);
}

should also work. Less code, less redundancy, and it wouldn't be in the way of future changes in panels templates.

Haven't tried it though, but imho, it should work.

If you want to do this in a module, you would actualy use hook_theme_registry_alter() to add a preproccess function to the theme hook 'panels_pane'.

function mymodule_theme_registry_alter(&$theme_registry) {
  $theme_registry['panels_pane']['preprocess functions'][] = 'mymodule_translate_title';
}

function mymodule_translate_title(&$vars) {
  $vars['title'] = t($vars['title']);
}

If this works, we could instead use tt() or even i18n_strings() instead of t(), as pointed out by moritzz in #29.

lestu’s picture

This is very good advice! :)

Actually, for my case it was even easier.
All I had to do was set the panel title to manually, leave the title field empty and create a custom content:

drupal_set_title(t("Hello!"));

Be sure to wrap that text in t().

The title of the panel is now translatable even without a language based visibility rule.

Thanks,
Lestu

henrijs.seso’s picture

Any plans on actually fixing this? Maybe at least in 7x version?

emattias’s picture

Version: 6.x-3.0 » 6.x-3.9
Status: Active » Needs review
StatusFileSize
new902 bytes

Here's a patch that adds the t function to the get_title function in panels.module

zilverdistel’s picture

Status: Needs review » Active

@emattias: These titles are dynamic strings and should not be run through the t() function. See http://api.drupal.org/api/drupal/includes--common.inc/function/t/6 for more information.

emattias’s picture

@zilverdistel: Hmm, ok but how do I then make the titles translatable?

zilverdistel’s picture

@emattias: maybe this post may be of help for you: http://groups.drupal.org/node/87864#comment-276909.

heyyo’s picture

The template overriding or the modification in template.php doesn't work anymore on my website on taxonomy override with Panels. I have no problem with Title in Node ovveride.
I'm using panels 6.x-3.9.
Any idea ?

Letharion’s picture

Status: Active » Closed (duplicate)
Issue tags: -i18n, -panels, -localization, -translate

Closing this as there is now a suggested patch over here: #1179034: Translatable panel titles: Implement i18n_strings.

Jérôme Brunel’s picture

Hi,
You just have to modify panels-pane.tpl.php in your Panel module directory/templates: modify print $title; by print t($title); and this will add your pane titles to "translate interface".