diff --git a/apachesolr_search.module b/apachesolr_search.module index 68372d2..693bb80 100644 --- a/apachesolr_search.module +++ b/apachesolr_search.module @@ -655,7 +655,7 @@ function apachesolr_search_taxonomy_facet_block($response, $query, $delta) { } // Check that we have a response and a valid vid. - if (is_object($response->facet_counts->facet_fields->$delta) && ($vocab = taxonomy_vocabulary_load($vid))) { + if (is_object($response->facet_counts->facet_fields->$delta) && ($vocab = apachesolr_taxonomy_vocabulary_load($vid))) { $reflect_hierarchy = apachesolr_search_get_hierarchical_vocabularies(); $contains_active = FALSE; $facets = array(); @@ -686,6 +686,7 @@ function apachesolr_search_taxonomy_facet_block($response, $query, $delta) { // @todo: faster as 2x separate queries? $result = db_query("SELECT tid, parent FROM {term_hierarchy} WHERE parent > 0 AND (tid IN ($placeholders) OR parent IN ($placeholders))", array_merge($tids, $tids)); while ($term = db_fetch_object($result)) { + $term = apachesolr_search_localize_taxonomy_term($term); // Mark all terms that are parents for later CSS class. // We assume data in the Solr index is complete - potential for some // breakage here. @@ -801,6 +802,60 @@ function apachesolr_search_nested_facet_items($query, $facets, $num_found, $sort } /** + * Localizes taxonomy term + * + * @param $term + * The taxonomy term object to localize. + * @return + * A localized version of the term object. + */ +function apachesolr_search_localize_taxonomy_term($term) { + if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { + $term->name = i18nstrings("taxonomy:term:{$term->tid}:name", $term->name); + } + return $term; +} + +/** + * Localizes taxonomy vocabulary + * + * @param $vocab + * The taxonomy vocabulary object to localize. + * @return + * The localized version of the vocabulary object. + */ +function apachesolr_search_localize_taxonomy_vocabulary($vocab) { + if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($vocab->vid) == I18N_TAXONOMY_LOCALIZE) { + $vocab->name = i18nstrings("taxonomy:vocabulary:{$vocab->vid}:name", $vocab->name); + } + return $vocab; +} + +/** + * Detects if taxonomy object should be localized + * + * @param $obj + * A taxonomy vocabulary or term object. + * @return + * TRUE if the object should be localized. + */ +function apachesolr_search_taxonomy_needs_localization($obj) { + static $localize = array(); + + if (module_exists('i18ntaxonomy')) { + if (empty($localize)) { + $localize = i18ntaxonomy_vocabulary(NULL, I18N_TAXONOMY_LOCALIZE); + } + } + + if (in_array($obj->vid, $localize)) { + return TRUE; + } + + return FALSE; +} + +/** * Callback function for the 'Filter by book' facet block. */ function apachesolr_search_get_book($facet, &$options) { @@ -1155,7 +1210,7 @@ function theme_apachesolr_breadcrumb_uid($uid) { */ function theme_apachesolr_breadcrumb_tid($tid) { if (function_exists('taxonomy_get_term')) { - if ($term = taxonomy_get_term($tid)) { + if ($term = apachesolr_search_localize_taxonomy_term(taxonomy_get_term($tid))) { return $term->name; } } @@ -1247,7 +1302,7 @@ function apachesolr_search_currentsearch_block($response, $query) { $facets = array(); foreach ($fields as $index => $field) { if ($field['#name'] && 'tid' == $field['#name']) { - $term = taxonomy_get_term($field['#value']); + $term = apachesolr_taxonomy_get_term($field['#value']); if ($reflect_hierarchy[$term->vid]) { $fields[$index] += array('#parent' => 0, '#children' => array()); // Just save the index for later lookup. @@ -1320,3 +1375,45 @@ function apachesolr_search_get_hierarchical_vocabularies() { return $result; } + +/** + * Wrapper for taxonomy_get_term(). Localizes a taxonomy term when applicable. + * + * @param $tid + * A term's ID + * + * @return + * A localized version of the term object, or the unchanged term if no + * localization could be applied. + * + * @see taxonomy_get_term() + */ +function apachesolr_taxonomy_get_term($tid) { + $term = taxonomy_get_term($tid); + if (is_object($term) && module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { + $term->name = i18nstrings("taxonomy:term:{$term->tid}:name", $term->name); + } + return $term; +} + +/** + * Wrapper for taxonomy_vocabulary_load(). Localizes taxonomy vocabulary, if + * applicable. + * + * @param $vid + * The vocabulary's ID + * + * @return + * The localized version of the vocabulary object, or the unchanged vocabulary + * if no localization could be applied. + * + * @see taxonomy_vocabulary_load() + */ +function apachesolr_taxonomy_vocabulary_load($vid) { + $vocab = taxonomy_vocabulary_load($vid); + if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($vocab->vid) == I18N_TAXONOMY_LOCALIZE) { + $vocab->name = i18nstrings("taxonomy:vocabulary:{$vocab->vid}:name", $vocab->name); + } + return $vocab; +} +