From 2e70c48528bd720c609211eb71ffd88401bc2356 Mon Sep 17 00:00:00 2001
From: Christian Spitzlay <christian.spitzlay@bio.logis.de>
Date: Tue, 16 Oct 2012 16:32:35 +0200
Subject: [PATCH 1/2] [#1270624] cspitzlay: make user-defined strings in
 commerce tax instances translatable via i18n_string

---
 modules/tax/commerce_tax.i18n.inc | 47 +++++++++++++++++++++++++++++++++++++++
 modules/tax/commerce_tax.module   |  6 ++++-
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 modules/tax/commerce_tax.i18n.inc

diff --git a/modules/tax/commerce_tax.i18n.inc b/modules/tax/commerce_tax.i18n.inc
new file mode 100644
index 0000000..80dacbb
--- /dev/null
+++ b/modules/tax/commerce_tax.i18n.inc
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * Implements hook_i18n_object_info().
+ */
+function commerce_tax_i18n_object_info() {
+  $info['commerce_tax'] = array(
+    'title' => t('Commerce tax'),
+    'key' => 'name',
+    'class' => 'i18n_string_object_wrapper',
+    'string translation' => array(
+      'textgroup' => 'commerce_tax',
+      'type' => 'name',
+      'properties' => array(
+        'title' => t('Title'),
+        'display_title' => t('Display title', array(), array('context' => 'title for display purposes')),
+        'description' => t('Description'),
+      ),
+    ),
+  );
+  return $info;
+}
+
+/**
+ * Implements hook_i18n_string_info().
+ */
+function commerce_tax_i18n_string_info() {
+  $groups['commerce_tax'] = array(
+    'title' => t('Commerce tax'),
+    'description' => t("Translatable user-defined strings of the commerce tax module."),
+    'format' => FALSE, // This group doesn't have strings with format
+    'list' => FALSE, // This group cannot list all strings
+  );
+  return $groups;
+}
+
+/**
+ * Implements hook_i18n_string_objects().
+ */
+function commerce_tax_i18n_string_objects($type) {
+  if ($type == 'commerce_tax') {
+    return db_select('commerce_tax_rate', 'ctr')
+      ->fields('ctr', array('name', 'title', 'display_title', 'description'))
+      ->execute()
+      ->fetchAllAssoc('name', PDO::FETCH_ASSOC);
+  }
+}
\ No newline at end of file
diff --git a/modules/tax/commerce_tax.module b/modules/tax/commerce_tax.module
index bb56e77..bad8f26 100644
--- a/modules/tax/commerce_tax.module
+++ b/modules/tax/commerce_tax.module
@@ -168,8 +168,12 @@ function commerce_tax_rates() {
           'calculation_callback' => 'commerce_tax_rate_calculate',
           'module' => $module,
         );
-
         $tax_rates[$name] = array_merge($defaults, $tax_rate);
+        if (module_exists('i18n_string')) {
+          // translate user-defined strings
+          global $language;
+          $tax_rates[$name] = i18n_object('commerce_tax', $tax_rates[$name])->translate($language->language);
+        }
       }
     }
 
-- 
1.7.12.2


From a45c4398c427e93131685a48b895158057e31900 Mon Sep 17 00:00:00 2001
From: Christian Spitzlay <christian.spitzlay@bio.logis.de>
Date: Tue, 16 Oct 2012 17:22:52 +0200
Subject: [PATCH 2/2] [#1270624] cspitzlay: make user-defined strings in tax
 types translatable, too.

---
 modules/tax/commerce_tax.i18n.inc | 26 +++++++++++++++++++++++---
 modules/tax/commerce_tax.module   |  7 ++++++-
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/modules/tax/commerce_tax.i18n.inc b/modules/tax/commerce_tax.i18n.inc
index 80dacbb..1fa6b04 100644
--- a/modules/tax/commerce_tax.i18n.inc
+++ b/modules/tax/commerce_tax.i18n.inc
@@ -4,8 +4,22 @@
  * Implements hook_i18n_object_info().
  */
 function commerce_tax_i18n_object_info() {
-  $info['commerce_tax'] = array(
-    'title' => t('Commerce tax'),
+  $info['commerce_tax_rate'] = array(
+    'title' => t('Commerce tax rate'),
+    'key' => 'name',
+    'class' => 'i18n_string_object_wrapper',
+    'string translation' => array(
+      'textgroup' => 'commerce_tax',
+      'type' => 'name',
+      'properties' => array(
+        'title' => t('Title'),
+        'display_title' => t('Display title', array(), array('context' => 'title for display purposes')),
+        'description' => t('Description'),
+      ),
+    ),
+  );
+  $info['commerce_tax_type'] = array(
+    'title' => t('Commerce tax type'),
     'key' => 'name',
     'class' => 'i18n_string_object_wrapper',
     'string translation' => array(
@@ -38,10 +52,16 @@ function commerce_tax_i18n_string_info() {
  * Implements hook_i18n_string_objects().
  */
 function commerce_tax_i18n_string_objects($type) {
-  if ($type == 'commerce_tax') {
+  if ($type == 'commerce_tax_rate') {
     return db_select('commerce_tax_rate', 'ctr')
       ->fields('ctr', array('name', 'title', 'display_title', 'description'))
       ->execute()
       ->fetchAllAssoc('name', PDO::FETCH_ASSOC);
   }
+  if ($type == 'commerce_tax_type') {
+    return db_select('commerce_tax_type', 'ctt')
+      ->fields('ctt', array('name', 'title', 'display_title', 'description'))
+      ->execute()
+      ->fetchAllAssoc('name', PDO::FETCH_ASSOC);
+  }
 }
\ No newline at end of file
diff --git a/modules/tax/commerce_tax.module b/modules/tax/commerce_tax.module
index bad8f26..3b222be 100644
--- a/modules/tax/commerce_tax.module
+++ b/modules/tax/commerce_tax.module
@@ -76,6 +76,11 @@ function commerce_tax_types() {
         );
 
         $tax_types[$name] = array_merge($defaults, $tax_type);
+        if (module_exists('i18n_string')) {
+          // translate user-defined strings
+          global $language;
+          $tax_types[$name] = i18n_object('commerce_tax_type', $tax_types[$name])->translate($language->language);
+        }
       }
     }
 
@@ -172,7 +177,7 @@ function commerce_tax_rates() {
         if (module_exists('i18n_string')) {
           // translate user-defined strings
           global $language;
-          $tax_rates[$name] = i18n_object('commerce_tax', $tax_rates[$name])->translate($language->language);
+          $tax_rates[$name] = i18n_object('commerce_tax_rate', $tax_rates[$name])->translate($language->language);
         }
       }
     }
-- 
1.7.12.2

