0

I need to translate the Label of the panes in a page. For example, Title and Body are not translated in my pages.

Note: I do not mean the content of panes! I only mean their label! Which is generally called TITLE.

  • Have you tried to use Panels translation (i18n_panels)? See also: How to translate a panel page title and a pane title – kenorb Jan 28 '15 at 10:55
  • Thank you for your comment. I have already activated this module. The issue is that, consider there is an edit node form, and no field caption is translated! such as: Title*, Body, ... – Ehsan Jan 28 '15 at 11:09
0

Sounds like i18n_panels would be overkill. You can do it like this:

/**
 * Preprocess panels panes to translate their title.
 */
function MY_THEME_preprocess_panels_pane(&$variables) {
  $pane_config = $variables['pane']->configuration;
  if (!empty($pane_config['override_title'])) {
    // Translate pane title via t().
    $variables['title'] = t($pane_config['override_title_text']);
  }
}

Or, if appropriate, just:

/**
 * Preprocess panels panes to translate their title.
 */
function MY_MODULE_preprocess_panels_pane(&$variables) {
  $variables['title'] = t($variables['title']);
}

The first will process the title only if defined in the pane settings as a title override. The second will translate the title regardless of whether it's the override title or original title from elsewhere.

Tested under Drupal 7, the same or similar approach would probably work for Drupal 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.