/** * Edit translation file in chosen language * * @param void * @return void */ function edit_translation_file() { if ($this->active_language->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $translation_id = $this->request->get('filename'); if (!$translation_id) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $dictionary_filename = Languages::getDictionaryPath($translation_id); if (!is_file($dictionary_filename)) { flash_error('Dictionary does not exists'); $this->redirectToUrl($this->active_language->getViewUrl()); } // if $dictionary = Languages::getDictionary($translation_id); $translation_file = Languages::getTranslationPath($this->active_language, $translation_id); if (!is_file($translation_file)) { flash_error('Translation file does not exists. You need to create it first.'); $this->redirectToUrl($this->active_language->getViewUrl()); } // if $translation_data = Languages::getTranslation($this->active_language, $translation_id); $prepared_form_data = $this->request->post('form_data'); if (!is_array($prepared_form_data)) { $prepared_form_data = array(); foreach ($dictionary as $dictionary_id => $dictionary_value) { $prepared_form_data[$dictionary_id] = array("dictionary_value" => $dictionary_value, "translated_value" => array_var($translation_data, $dictionary_value)); } // foreach $this->smarty->assign(array("prepared_form_data" => $prepared_form_data)); } // if $this->smarty->assign(array("translation_file" => $translation_id, "form_url" => $this->active_language->getEditTranslationFileUrl($translation_id))); if ($this->request->isSubmitted()) { if (is_foreachable($prepared_form_data)) { $new_prepared_data = array(); $translation_data = array(); foreach ($prepared_form_data as $prepared_form_data_key => $prepared_form_data_value) { $translation_data[array_var($dictionary, $prepared_form_data_key)] = $prepared_form_data_value; $new_prepared_data[$prepared_form_data_key] = array("dictionary_value" => array_var($dictionary, $prepared_form_data_key), "translated_value" => $prepared_form_data_value); } // foreach } // if file_put_contents($translation_file, '<?php return ' . var_export($translation_data, true) . ' ?>'); cache_remove_by_pattern('lang_cache_for_*'); if (module_loaded('incoming_mail')) { // set config option for translation if (array_key_exists(EMAIL_SPLITTER, $translation_data)) { $config_option = ConfigOptions::getValue('email_splitter_translations'); $config_option[$this->active_language->getLocale()] = $translation_data[EMAIL_SPLITTER]; ConfigOptions::setValue('email_splitter_translations', $config_option); } // if } // if $this->smarty->assign(array("prepared_form_data" => $new_prepared_data)); } // if }
/** * Creates dictionary file in localization path * * @param string $dictionary_name */ function createTranslationFile($dictionary_name) { $dictionary_file = Languages::getDictionaryPath($dictionary_name); if (!is_file($dictionary_file)) { return false; } // if $translation_file = Languages::getTranslationPath($this, $dictionary_name); if (!folder_is_writable(dirname($translation_file))) { return false; } // if if (is_file($translation_file)) { return true; } // if $dictionary = Languages::getDictionary($dictionary_name); $translation = array(); if (is_foreachable($dictionary)) { foreach ($dictionary as $dictionary_word) { $translation[$dictionary_word] = ''; } // foreach } // if $result = file_put_contents($translation_file, "<?php return " . var_export($translation, true) . " ?>"); if (!$result) { return false; } // if return true; }