function saveAddLanguagePanelAction() { $active_worker = PortSensorApplication::getActiveWorker(); // Make sure we're an active worker if (empty($active_worker) || empty($active_worker->id)) { return; } $codes = DAO_Translation::getDefinedLangCodes(); @($add_lang_code = DevblocksPlatform::importGPC($_REQUEST['add_lang_code'], 'string', '')); @($copy_lang_code = DevblocksPlatform::importGPC($_REQUEST['copy_lang_code'], 'string', '')); @($del_lang_ids = DevblocksPlatform::importGPC($_REQUEST['del_lang_ids'], 'array', array())); if (!empty($del_lang_ids)) { if (is_array($del_lang_ids)) { foreach ($del_lang_ids as $lang_id) { DAO_Translation::deleteByLangCodes($lang_id); } } } // Don't add blanks or the same language twice. if (!empty($add_lang_code) && !isset($codes[$add_lang_code])) { // English reference strings (to know our scope) $english_strings = DAO_Translation::getMapByLang('en_US'); $copy_strings = array(); // If we have a desired source language for defaults, load it. if (!empty($copy_lang_code)) { if (0 == strcasecmp('en_US', $copy_lang_code)) { $copy_strings = $english_strings; } else { $copy_strings = DAO_Translation::getMapByLang($copy_lang_code); } } // Loop through English strings for new language if (is_array($english_strings)) { foreach ($english_strings as $string_id => $src_en) { /* @var $src_en Model_Translation */ $override = ''; // If we have a valid source, copy its override or its default (in that order) @($copy_string = $copy_strings[$string_id]); if (is_a($copy_string, 'Model_Translation')) { $override = !empty($copy_string->string_override) ? $copy_string->string_override : $copy_string->string_default; } // Insert the new string as an override. Only official translations are defaults $fields = array(DAO_Translation::STRING_ID => $string_id, DAO_Translation::LANG_CODE => $add_lang_code, DAO_Translation::STRING_DEFAULT => '', DAO_Translation::STRING_OVERRIDE => $override); DAO_Translation::create($fields); } } } // If we added a new language then change the view to display it if (!empty($add_lang_code)) { $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::LANG_CODE => new DevblocksSearchCriteria(SearchFields_Translation::LANG_CODE, DevblocksSearchCriteria::OPER_EQ, $add_lang_code)); /* * If we didn't copy from another language, only show empty strings * which makes it easier to translate in the GUI. */ if (empty($copy_lang_code)) { $view->params[SearchFields_Translation::STRING_OVERRIDE] = new DevblocksSearchCriteria(SearchFields_Translation::STRING_OVERRIDE, DevblocksSearchCriteria::OPER_EQ, ''); } Ps_AbstractViewLoader::setView($view->id, $view); } self::_clearCache(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'translations'))); }