Example #1
0
 /**
  * @return _DevblocksTranslationManager
  */
 static function getTranslationService()
 {
     static $languages = array();
     $locale = DevblocksPlatform::getLocale();
     // Registry
     if (isset($languages[$locale])) {
         return $languages[$locale];
     }
     $cache = self::getCacheService();
     if (null === ($map = $cache->load(self::CACHE_TAG_TRANSLATIONS . '_' . $locale))) {
         /* @var $cache _DevblocksCacheManager */
         $map = array();
         $map_en = DAO_Translation::getMapByLang('en_US');
         if (0 != strcasecmp('en_US', $locale)) {
             $map_loc = DAO_Translation::getMapByLang($locale);
         }
         // Loop through the English string objects
         if (is_array($map_en)) {
             foreach ($map_en as $string_id => $obj_string_en) {
                 $string = '';
                 // If we have a locale to check
                 if (isset($map_loc) && is_array($map_loc)) {
                     @($obj_string_loc = $map_loc[$string_id]);
                     @($string = !empty($obj_string_loc->string_override) ? $obj_string_loc->string_override : $obj_string_loc->string_default);
                 }
                 // If we didn't hit, load the English default
                 if (empty($string)) {
                     @($string = !empty($obj_string_en->string_override) ? $obj_string_en->string_override : $obj_string_en->string_default);
                 }
                 // If we found any match
                 if (!empty($string)) {
                     $map[$string_id] = $string;
                 }
             }
         }
         unset($obj_string_en);
         unset($obj_string_loc);
         unset($map_en);
         unset($map_loc);
         // Cache with tag (tag allows easy clean for multiple langs at once)
         $cache->save($map, self::CACHE_TAG_TRANSLATIONS . '_' . $locale);
     }
     $translate = _DevblocksTranslationManager::getInstance();
     $translate->addLocale($locale, $map);
     $translate->setLocale($locale);
     $languages[$locale] = $translate;
     return $translate;
 }