Drupal Commerce - Translate Order total, Shipping Information, Billing information

If you do not want to use i18n_string and i18n_field in order to translate the Order total, Shipping & Billing Information texts, that show up in the cart and on the checkout pages when using Drupal Commerce, the following hacky approach should do the trick.

First, the following funcion can be used in your template.php file:

<?php
/**
* Implements hook_form_alter();
*/
function YOURTHEME_form_alter(&$form, &$form_state, $form_id) {
 
// Fix order total translation
 
if (isset($form['cart_contents'])){
   
$form['cart_contents']['cart_contents_view']['#markup'] = str_replace('Order total', t('Order total'), $form['cart_contents']['cart_contents_view']['#markup']);
  }
 
// Fix translation on checkout form
 
if ($form['#id'] == 'commerce-checkout-form-checkout'){
    if(isset(
$form['customer_profile_billing'])){
     
$form['customer_profile_billing']['#title'] = t('Billing information');
    }
    if (isset(
$form['customer_profile_shipping'])){
     
$form['customer_profile_shipping']['#title'] = t('Shipping information');
    }
  }
 
// Fix translation on checkout review
 
if ($form['#id'] == 'commerce-checkout-form-review'){
    if (isset(
$form['checkout_review']['review']['#data']['customer_profile_billing'])){
     
$form['checkout_review']['review']['#data']['customer_profile_billing']['title'] = t('Billing information');
    }
    if (isset(
$form['checkout_review']['review']['#data']['customer_profile_shipping'])){
     
$form['checkout_review']['review']['#data']['customer_profile_shipping']['title'] = t('Shipping information');
    }
  }
}
?>

The above function (as seen in https://drupal.org/node/1451132#comment-6437052 ) is also available as a module and can be used instead: https://github.com/kaido24/commerce_lang_repair

In addition, there is this patch, that will also handle the Order total text in the cart:

https://drupal.org/files/Total_order_translation-1776644-17.patch

Tags: 
Drupal 7, Drupal Commerce, Drupal Quick Tips

Recent Comments

Forward by Dries Buytaert, Founder and Project Lead, Drupal; CTO Acquia.

Order now from:

Managing Expectations Podcast with DrupalEasy

Author Interview http://tinyurl.com/8a8nxno

We provide the most Shiny Drupal Bits & Pixels

Since Drupal 4.x

Konordo OÜ
Drupal Services

Reg No. 14623621
VAT ID. EE102121939

Director: Konstantin Ordoulidis

Get in touch

  • Konordo OÜ
  • Sepapaja 6, 15551 Tallinn, Estonia
  • +4917698807355
  • info [at] konordo [dot] com