コード例 #1
0
 /**
  * Translates the categories.
  */
 public static function translateCategories($items = array())
 {
     $tids = array();
     foreach ($items as $item) {
         $categories = $item->getEntity()->getCategories();
         foreach ($categories as $category) {
             $categoryId = is_object($category) ? $category->getId() : $category;
             $tids[$categoryId] = $categoryId;
         }
     }
     // Translate the labels.
     if (culturefeed_search_term_translations($tids)) {
         foreach ($items as $item) {
             $categories = $item->getEntity()->getCategories();
             foreach ($categories as $category) {
                 if (is_object($category)) {
                     $category->setName(culturefeed_search_get_term_translation($category->getId()));
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Warm up cache for facets to translate the items.
  */
 private function translateFacets()
 {
     $found_ids = array();
     $found_results = array();
     $translated_terms = array();
     $facets = $this->facetComponent->getFacets();
     foreach ($facets as $key => $facet) {
         // The key should start with 'category_' or 'location_'
         $start = substr($key, 0, 9);
         if (in_array($start, array('category_', 'location_'))) {
             $items = $facet->getResult()->getItems();
             foreach ($items as $item) {
                 $found_ids[$item->getValue()] = $item->getValue();
             }
         }
     }
     // Translate the facets.
     if ($translations = culturefeed_search_term_translations($found_ids, TRUE)) {
         // Preferred language.
         $preferred_language = culturefeed_search_get_preferred_language();
         // Translate the facets labels.
         foreach ($facets as $key => $facet) {
             // The key should start with 'category_' or 'location_'
             $start = substr($key, 0, 9);
             if (in_array($start, array('category_', 'location_'))) {
                 $items = $facet->getResult()->getItems();
                 foreach ($items as $item) {
                     // Translate if found.
                     if (!empty($translations[$item->getValue()][$preferred_language])) {
                         $item->setLabel($translations[$item->getValue()][$preferred_language]);
                     }
                 }
             }
         }
     }
 }