コード例 #1
0
ファイル: DAO.php プロジェクト: jstanden/devblocks
 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
ファイル: App.php プロジェクト: jstanden/portsensor
 function saveViewAction()
 {
     @($row_ids = DevblocksPlatform::importGPC($_REQUEST['row_ids'], 'array', array()));
     @($translations = DevblocksPlatform::importGPC($_REQUEST['translations'], 'array', array()));
     // Save the form strings
     if (is_array($row_ids)) {
         foreach ($row_ids as $idx => $row_id) {
             $fields = array(DAO_Translation::STRING_OVERRIDE => $translations[$idx]);
             DAO_Translation::update($row_id, $fields);
         }
     }
     self::_clearCache();
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'translations')));
 }