Hi,

I'm translating a site but I haven't been able to translate the headers from the matrix fields I'm using, any piece of advice?

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torsti’s picture

I need this info also! I tried this:

function mytheme_table($header, $rows, $attributes = array(), $caption = NULL) {
   if(count($header)){
    foreach($header as $key => $cell) {
      $header[$key]['data'] = t($header[$key]['data']);
    }
  }
  return theme_table($header, $rows, $attributes, $caption);
}

but it didn't work.

maijs’s picture

Any solution to this problem? Can column and row labels be translated?

levacjeep’s picture

On line 398 of matrix.module

Change to:


foreach ($cols as $col) {
    if ($col['#required'] == TRUE) {
      $header[] = t($col['#title']) .'<span class="form-required" title="This field is required.">*</span>';
    }
    else {
      $header[] = t($col['#title']);
    }
  }
mdubnz’s picture

I'm in need of a solution that works for version 1.4
It appears you solution is for a later version levacjeep
Any help appreciated..
Cheers

perceptum’s picture

Here is the git diff for our solution to this problem

git diff matrix.module
diff --git a/sites/all/modules/matrix/matrix.module b/sites/all/modules/matrix/matrix.module
index 951cca4..4d9bea4 100644
--- a/sites/all/modules/matrix/matrix.module
+++ b/sites/all/modules/matrix/matrix.module
@@ -286,6 +286,11 @@ function theme_matrix_formatter_default($element) {
$header = $field_info['cols_header'];
array_unshift($header, '');

+ // Translatable headers - PERCEPTUM
+ foreach($header as $i => $h) {
+ $header[$i] = t($h);
+ }
+
static $rendered; //since we are rendering the whole thing in one go, we don't want to rerender for each fow

if ($rendered[$element['#field_name']] != TRUE) {

aaron1234nz’s picture

Status: Active » Fixed

Issue fixed. The solution was similar to that in comment #5, however it I put it inside the matrix_process function instead.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

chinita7’s picture

Version: 6.x-1.4 » 6.x-2.0-alpha1

Thanks to #3, I did it as below for 6.2 version and it works.

  if ($col['#required'] == TRUE) {
      $header[] = t($col['#title']) .'<span class="form-required" title="This field is required.">*</span>';
    }
    else {
      $header[] = t($col['#title']);
    }
  }
  
  //generate first column
  foreach ($rows as $row) {
    if ($row['#required'] == TRUE) {
      $first_col[] = t($row['#title']) .'<span class="form-required" title="This field is required.">*</span>';
    }
    else {
      $first_col[] = t($row['#title']);
    }
  }
tanmoy1981’s picture

Issue summary: View changes
FileSize
3.22 KB

This patch will work for D7, module version is 7.x-2.3.

tanmoy1981’s picture

Version: 6.x-2.0-alpha1 » 7.x-2.3
Status: Closed (fixed) » Needs review
FileSize
481 bytes

The last patch file was not correct, use this one instead. Its for D7, version 7.x-2.3.

intrafusion’s picture

FileSize
481 bytes

Re-upload patch from #11 to trigger test-bot

intrafusion’s picture

Status: Needs review » Fixed

Patch OK, added to repo

  • intrafusion committed add53aa on
    Issue #604280 by tanmoy1981, intrafusion: How to translate headers?
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.