Пример #1
0
 static function importTmxFile($filename)
 {
     $db = DevblocksPlatform::getDatabaseService();
     if (!file_exists($filename)) {
         return;
     }
     /*
      * [JAS] [TODO] This could be inefficient when reading a lot 
      * of TMX sources, but it could also be inefficient always
      * keeping it in memory after using it once.  I'm going to err
      * on the side of a little extra DB work for the few times it's 
      * called.
      */
     $hash = array();
     foreach (DAO_Translation::getWhere() as $s) {
         /* @var $s Model_TranslationDefault */
         $hash[$s->lang_code . '_' . $s->string_id] = $s;
     }
     if (false == @($xml = simplexml_load_file($filename))) {
         /* @var $xml SimpleXMLElement */
         return;
     }
     $namespaces = $xml->getNamespaces(true);
     foreach ($xml->body->tu as $tu) {
         /* @var $tu SimpleXMLElement */
         $msgid = strtolower((string) $tu['tuid']);
         foreach ($tu->tuv as $tuv) {
             /* @var $tuv SimpleXMLElement */
             $attribs = $tuv->attributes($namespaces['xml']);
             $lang = (string) $attribs['lang'];
             $string = (string) $tuv->seg[0];
             // [TODO] Handle multiple segs?
             @($hash_obj = $hash[$lang . '_' . $msgid]);
             /* @var $hash_obj Model_Translation */
             // If not found in the DB
             if (empty($hash_obj)) {
                 $fields = array(DAO_Translation::STRING_ID => $msgid, DAO_Translation::LANG_CODE => $lang, DAO_Translation::STRING_DEFAULT => $string);
                 $id = DAO_Translation::create($fields);
                 // Add to our hash to prevent dupes
                 $new = new Model_Translation();
                 $new->id = $id;
                 $new->string_id = $msgid;
                 $new->lang_code = $lang;
                 $new->string_default = $string;
                 $new->string_override = '';
                 $hash[$lang . '_' . $msgid] = $new;
                 // If exists in DB and the string has changed
             } elseif (!empty($hash_obj) && 0 != strcasecmp($string, $hash_obj->string_default)) {
                 $fields = array(DAO_Translation::STRING_DEFAULT => $string);
                 DAO_Translation::update($hash_obj->id, $fields);
             }
         }
     }
     unset($xml);
 }
Пример #2
0
 function saveFindStringsPanelAction()
 {
     $active_worker = PortSensorApplication::getActiveWorker();
     // Make sure we're an active worker
     if (empty($active_worker) || empty($active_worker->id)) {
         return;
     }
     @($lang_codes = DevblocksPlatform::importGPC($_REQUEST['lang_codes'], 'array', array()));
     @($lang_actions = DevblocksPlatform::importGPC($_REQUEST['lang_actions'], 'array', array()));
     $strings_en = DAO_Translation::getMapByLang('en_US');
     // Build a hash of all existing strings so we can quickly INSERT/UPDATE check
     $hash = array();
     $all_strings = DAO_Translation::getWhere();
     foreach ($all_strings as $s) {
         /* @var $s Model_TranslationDefault */
         $hash[$s->lang_code . '_' . $s->string_id] = $s;
     }
     unset($all_strings);
     // free()
     // Find all en_US strings that aren't translated
     if (is_array($strings_en) && is_array($lang_codes) && !empty($lang_codes)) {
         foreach ($strings_en as $key => $string) {
             foreach ($lang_codes as $idx => $lang_code) {
                 @($lang_action = $lang_actions[$idx]);
                 if (!isset($hash[$lang_code . '_' . $key])) {
                     $fields = array(DAO_Translation::STRING_ID => $key, DAO_Translation::LANG_CODE => $lang_code, DAO_Translation::STRING_DEFAULT => '', DAO_Translation::STRING_OVERRIDE => 'en_US' == $lang_action ? $string : '');
                     DAO_Translation::create($fields);
                 }
             }
         }
     }
     $defaults = new Ps_AbstractViewModel();
     $defaults->class_name = 'Ps_TranslationView';
     $defaults->id = Ps_TranslationView::DEFAULT_ID;
     // Clear the existing view
     $view = Ps_AbstractViewLoader::getView(Ps_TranslationView::DEFAULT_ID, $defaults);
     $view->doResetCriteria();
     // Set search to untranslated strings that aren't English
     $view->renderSortBy = SearchFields_Translation::STRING_ID;
     $view->renderSortAsc = true;
     $view->params = array(SearchFields_Translation::STRING_OVERRIDE => new DevblocksSearchCriteria(SearchFields_Translation::STRING_OVERRIDE, DevblocksSearchCriteria::OPER_EQ, ''), SearchFields_Translation::LANG_CODE => new DevblocksSearchCriteria(SearchFields_Translation::LANG_CODE, DevblocksSearchCriteria::OPER_NEQ, 'en_US'));
     Ps_AbstractViewLoader::setView($view->id, $view);
     self::_clearCache();
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'translations')));
 }