diff --git a/uc_attribute/uc_attribute.module b/uc_attribute/uc_attribute.module index 03daf9e..abc5aa2 100644 --- a/uc_attribute/uc_attribute.module +++ b/uc_attribute/uc_attribute.module @@ -433,6 +433,58 @@ function uc_attribute_node_reset($node) { uc_attribute_node_insert($node); } +/** + * Implementation of hook_locale(). + */ +function uc_attribute_locale($op = 'groups') { + switch ($op) { + case 'groups': + return array('uc_attribute' => t('Ubercart attributes')); + + case 'info': + $info['uc_attribute']['refresh callback'] = 'uc_attribute_locale_refresh'; + $info['uc_attribute']['format'] = FALSE; + return $info; + } +} + +/** + * Refresh translated attribute and option strings. + */ +function uc_attribute_locale_refresh() { + $attributes = db_query("SELECT aid, name, label, description FROM {uc_attributes}"); + while ($attribute = db_fetch_object($attributes)) { + i18nstrings_update('uc_attribute:attribute:'. $attribute->aid .':name', $attribute->name); + i18nstrings_update('uc_attribute:attribute:'. $attribute->aid .':label', $attribute->label); + i18nstrings_update('uc_attribute:attribute:'. $attribute->aid .':description', $attribute->description); + + $options = db_query("SELECT oid, name FROM {uc_attribute_options} WHERE aid = %d", array($attribute->aid)); + while ($option = db_fetch_object($options)) { + i18nstrings_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('i18nstrings')) { + $attribute->name = i18nstrings('uc_attribute:attribute:'. $attribute->aid .':name', $attribute->name); + $attribute->label = i18nstrings('uc_attribute:attribute:'. $attribute->aid .':label', $attribute->label); + $attribute->description = i18nstrings('uc_attribute:attribute:'. $attribute->aid .':description', $attribute->description); + + foreach ($attribute->options as $oid => $option) { + $attribute->options[$oid]->name = i18nstrings('uc_attribute:option:'. $oid .':name', $option->name); + } + } +} + /****************************************************************************** * Ubercart Hooks * ******************************************************************************/ @@ -725,6 +777,8 @@ function uc_attribute_load($aid, $id = NULL, $type = '') { while ($option = db_fetch_object($result)) { $attribute->options[$option->oid] = $option; } + + $attribute = uc_attribute_translate($attribute); } return $attribute;