Hi,

I installed the Date module, and added a Table View which shows the fields of a CCK content type, including a date.
However, the weekdays and months keep getting displayed in the English locale, even though Drupal is set to be in Dutch. The date info shown when posting a page or something, is correctly displayed in the locale, but the dates are still in english.

What can i do to solve this?

Comments

dodorama’s picture

At the moment dropdown boxes and outputted string aren't translated.
Dropdown boxes strings are avaiable for translations but you need to create your own .po file and import it in drupal.
To translate the output strings there's a workaround at the theme level.
If you are using a tpl file to theme your fields you probably know that you have to use something like this to print the date field:

print content_format('field_date', $field_data[0], 'default'));

If you're using spaces as separator for the date field (i.e '13 Nov 2006') you can explode the string and put each single value in a variable and wrap it in the t function:

 $calendardate = explode(' ', content_format('field_data', $field_data[0], 'default')); 
$calendarday = t($calendardate[0]);
$calendarnumber = t($calendardate[1]);
$calendarmonth = t($calendardate[2]);

If you're using slashes as separator try this:

 $calendardate = explode('/', content_format('field_data', $field_data[0], 'default')); 
$calendarday = t($calendardate[0]);
$calendarnumber = t($calendardate[1]);
$calendarmonth = t($calendardate[2]);

Then you can print each part of the date wherever you want in the tpl this way:

print $calendarmonth
print $calendarday
print $calendarnumber

svendecabooter’s picture

Okay thanks i got that working.

But how would i translate datestrings that get displayed in a table view. I don't have a template available for those. How can i translate a date when it's a tablefield?

dodorama’s picture

This is how I do it.

1. Make a list view instead of a table view.
2. Run the theme_wizard and follow the instructions. You will have to copy a chunk of code in your template.php file and create a views-list-VIEWNAME.tpl.php file

3. the template.php code file looks like this (VIEWNAME is your viewname ;) ):

/**
 * views template to output a view.
 * This code was generated by the views theming wizard
 * Date: Sun, 31/12/2006 - 14:12
 * View: tour
 *
 * This function goes in your template.php file
 */
function phptemplate_views_view_list_VIEWNAME($view, $nodes, $type) {
  $fields = _views_get_fields();

  $taken = array();

  // Set up the fields in nicely named chunks.
  foreach ($view->field as $id => $field) {
    $field_name = $field['field'];
    if (isset($taken[$field_name])) {
      $field_name = $field['queryname'];
    }
    $taken[$field_name] = true;
    $field_names[$id] = $field_name;
  }

  // Set up some variables that won't change.
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );

  foreach ($nodes as $i => $node) {
    $vars = $base_vars;
    $vars['node'] = $node;
    $vars['count'] = $i;
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
    foreach ($view->field as $id => $field) {
      $name = $field_names[$id];
      $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
      if (isset($field['label'])) {
        $vars[$name . '_label'] = $field['label'];
      }
    }
    $items[] = _phptemplate_callback('views-list-VIEWNAME', $vars);
  }
  if ($items) {
    return theme('item_list', $items);
  }
}

4. change the last part of the code like this(Again capitols words must be substituted)(at the end of the code where we are adding the tables element don't forget to insert header cells ('td') for each fields (i.e if you have 5 fields you have to insert 5 headers):

// VIEWNAME is the name of your view
function phptemplate_views_view_list_VIEWNAME($view, $nodes, $type) {
  $fields = _views_get_fields();

  $taken = array();

  // Set up the fields in nicely named chunks.
  foreach ($view->field as $id => $field) {
    $field_name = $field['field'];
    if (isset($taken[$field_name])) {
      $field_name = $field['queryname'];
    }
    $taken[$field_name] = true;
    $field_names[$id] = $field_name;
  }

  // Set up some variables that won't change.
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );

  foreach ($nodes as $i => $node) {
    $vars = $base_vars;
    $vars['node'] = $node;
    $vars['count'] = $i;
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
    foreach ($view->field as $id => $field) {
      $name = $field_names[$id];
      $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
      if (isset($field['label'])) {
        $vars[$name . '_label'] = $field['label'];
      }
    }

      $items[] = _phptemplate_callback('views-list-VIEWNAME', $vars);
  }
  if ($items) {
      // here starts the custom code to output the list view as a table
    foreach ($items as $item) {
      $output .= $item ;
    }

    if ($output) {
     // substitute HEADER-n with the labels of your fields
        return '<table class="CUSTOM-CLASS"><tbody><thead><tr><td>HEADER-1</td><td>HEADER-2</td><td>HEADER-3</td><td>HEADER4</td></tr></thead>' . $output . '</tbody></table>';

    }
  }
}

5. Then in your views-list-VIEWNAME.tpl.php substitute all field variables' hyphens with underscore (this because of a <a href="http://drupal.org/node/104459">bug</a> in the view-wizard) and make the code looks something like this (it will change depending from how you want to organize fields in your table (again substitute TYPEn with the corrected values outputted by the view wizard):


<code>
// I got rid of the drupal_add_css function cause we don't need it.
// So you don't need to create the views-list-VIEWNAME.css file as suggested by the view wizard
  <tr class="<?php print $zebra?>">
  <td><?php print $field_TYPE1_value?></td>
  <td><?php print $field_TYPE2_value?></td>
  <td><?php print $field_date_value?></td>
  <td><?php print $title?></td>
  </tr>

6. don't forget to apply the code snippet I posted above to correctly translate the date field

7. It looks more complex than it is but if you have basic knowledge of theming you should be able to have it working.

8. For sure there's a way to do it by theming the table view but I prefer to use the list view (for outputting tables, too) since the view wizard makes things easier and I have more control on it.

ray007’s picture

This issue still holds for current drupal 5 releases.
Is there an intention to fix this?

dodorama’s picture

Status: Active » Closed (duplicate)