From a2a366227e23d837b8d760c4d122daffa1fba44e Mon Sep 17 00:00:00 2001 From: tom behets Date: Mon, 29 Oct 2012 03:35:42 +0100 Subject: tom behets: Generated with Drush iq --- uc_attribute/uc_attribute.module | 51 ++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) create mode 100644 uc_attribute_locale_d7-436684-32.patch diff --git a/uc_attribute/uc_attribute.module b/uc_attribute/uc_attribute.module index e9e0d0c..3784e7c 100644 --- a/uc_attribute/uc_attribute.module +++ b/uc_attribute/uc_attribute.module @@ -730,6 +730,7 @@ function uc_attribute_load($aid, $id = NULL, $type = '') { foreach ($result as $option) { $attribute->options[$option->oid] = $option; } + uc_attribute_translate($attribute); } return $attribute; @@ -1485,3 +1486,53 @@ function _uc_attribute_get_name($attribute, $title = TRUE) { return (empty($attribute->label) || ($attribute->label == '' && $title) ? $attribute->name : $attribute->label); } } + +/** + * Implements hook_i18n_string_info(). + */ +function uc_attribute_i18n_string_info() { + $groups['uc_attribute'] = array( + 'title' => t('Ubercart attributes WAAA'), + 'description' => t('Translatable ubercart attributes'), + 'format' => FALSE, // This group has strings with format. + 'list' => TRUE, // This group can list all strings. + ); + return $groups; +} + +/** + * Refresh all strings. + */ +function uc_attribute_i18n_string_refresh() { + $attributes = db_query("SELECT aid, name, label, description FROM {uc_attributes}"); + foreach ($attributes as $attribute) { + i18n_string_update('uc_attribute:attribute:'. $attribute->aid .':name', $attribute->name); + i18n_string_update('uc_attribute:attribute:'. $attribute->aid .':label', $attribute->label); + i18n_string_update('uc_attribute:attribute:'. $attribute->aid .':description', $attribute->description); + + $options = db_query("SELECT oid, name FROM {uc_attribute_options} WHERE aid = :aid", array(':aid' => $attribute->aid)); + foreach($options as $option) { + i18n_string_update('uc_attribute:option:'. $option->oid .':name', $option->name); + } + } + + return TRUE; +} + +/** + * Translate an attribute. + * + * @param &$attribute + * The attribute object to translate. + */ +function uc_attribute_translate(&$attribute) { + if (function_exists('i18n_string')) { + $attribute->name = i18n_string('uc_attribute:attribute:'. $attribute->aid .':name', $attribute->name); + $attribute->label = i18n_string('uc_attribute:attribute:'. $attribute->aid .':label', $attribute->label); + $attribute->description = i18n_string('uc_attribute:attribute:'. $attribute->aid .':description', $attribute->description); + + foreach ($attribute->options as &$option) { + $option->name = i18n_string('uc_attribute:option:'. $option->oid .':name', $option->name); + } + } +} diff --git a/uc_attribute_locale_d7-436684-32.patch b/uc_attribute_locale_d7-436684-32.patch new file mode 100644 index 0000000..e69de29 -- 1.7.4.4