public function testGetDbUntranslated_filterBySearch() { global $prefs; $prefs['record_untranslated'] = 'y'; $expectedResult = array('translations' => array('Untranslated string 3' => array('source' => 'Untranslated string 3', 'tran' => null)), 'total' => 1); $this->assertEquals($expectedResult, $this->obj->getDbUntranslated(-1, 0, 'string 3')); }
/** * Translations in the database will be merged with the other translations in language.php. Note that after writing translations to language.php they are removed from the database. * @param $input * @return language.php file */ function action_write_to_language_php($input) { //check preference Services_Exception_Disabled::check('lang_use_db'); //check permissions $perms = Perms::get('tiki'); if (!$perms->tiki_p_edit_languages) { throw new Services_Exception_Denied(tr('Permission denied')); } //get language from input $language = $input->language->text(); //prepare language list -> seems useless... $langLib = TikiLib::lib('language'); $db_languages = $langLib->getDbTranslatedLanguages(); $db_languages = $langLib->format_language_list($db_languages); //TODO: get count of available translations in the database //$db_translation_count = $this->getDbTranslationCount($language); //check if lang directory is writable for the selected language $langIsWritable = $this->checkLangIsWritable($language); if ($langIsWritable === false) { throw new Services_Exception_Denied(tr('lang/$language directory is not writable')); } $confirm = $input->confirm->int(); if ($confirm) { //set export language $export_language = new LanguageTranslations($language); //write to language.php try { $stats = $export_language->writeLanguageFile(); } catch (Exception $e) { //TODO: this is messy $smarty->assign('msg', $e->getMessage()); $smarty->display('error.tpl'); die; } //TODO: expose expmsg properly $expmsg = sprintf(tra('Wrote %d new strings and updated %d to lang/%s/language.php'), $stats['new'], $stats['modif'], $export_language->lang); } return array('title' => tr('Write to language.php'), 'db_languages' => $db_languages, 'db_translation_count' => $db_translation_count, 'langIsWritable' => $langIsWritable); }
<?php /** * Script to export translations from the database * to language.php files. */ die("REMOVE THIS LINE TO USE THE SCRIPT.\n"); if (!isset($argv[1])) { echo "\nUsage: php export_translations_to_file.php langCode\n"; echo "Example: php export_translations_to_file.php de\n"; die; } require_once 'tiki-setup.php'; require_once 'lang/langmapping.php'; require_once 'lib/language/Language.php'; require_once 'lib/language/LanguageTranslations.php'; $langCode = $argv[1]; if (!array_key_exists($langCode, $langmapping)) { die("Invalid language code.\n"); } $language = new LanguageTranslations($langCode); try { $stats = $language->writeLanguageFile(); } catch (Exception $e) { die("{$e->getMessage()}\n"); } echo sprintf("Wrote %d new strings and updated %d to lang/%s/language.php\n", $stats['new'], $stats['modif'], $language->lang);
// display only database stored translations $data = $translations->getDbTranslations($sort_mode, $maxRecords, $offset, $find); } else { // display all available translations (db + custom.php + language.php) $data = $translations->getAllTranslations($maxRecords, $offset, $find); } } $smarty->assign_by_ref('translations', $data['translations']); $smarty->assign('total', $data['total']); $smarty->assign('hasDbTranslations', $translations->hasDbTranslations); } if (isset($_REQUEST["exp_language"])) { $exp_language = $_REQUEST["exp_language"]; $export_language = new LanguageTranslations($exp_language); $smarty->assign('exp_language', $exp_language); } else { $smarty->assign('exp_language', $prefs['language']); } // Export if (isset($_REQUEST['downloadFile'])) { check_ticket('edit-languages'); $data = $export_language->createCustomFile(); header("Content-type: application/unknown"); header("Content-Disposition: inline; filename=language.php"); header("Content-encoding: UTF-8"); echo $data; exit (0); }
require_once 'lib/language/LanguageTranslations.php'; $access->check_feature('lang_use_db'); $access->check_permission('tiki_p_edit_languages'); // Get available languages $langLib = TikiLib::lib('language'); $languages = $langLib->list_languages(); $smarty->assign_by_ref('languages', $languages); // preserving variables if (isset($_REQUEST["edit_language"])) { $smarty->assign('edit_language', $_REQUEST["edit_language"]); $edit_language = $_REQUEST["edit_language"]; } else { $smarty->assign('edit_language', $prefs['language']); $edit_language = $prefs['language']; } $translations = new LanguageTranslations($edit_language); if (!isset($_REQUEST["action"])) { $_REQUEST['action'] = 'edit_tran_sw'; } $smarty->assign('action', $_REQUEST["action"]); if (isset($_REQUEST['only_db_translations']) && $_REQUEST['only_db_translations'] != 'n') { $smarty->assign('only_db_translations', 'y'); } else { $smarty->assign('only_db_translations', 'n'); } if (isset($_REQUEST['only_db_untranslated']) && $_REQUEST['only_db_untranslated'] != 'n') { $smarty->assign('only_db_untranslated', 'y'); } else { $smarty->assign('only_db_untranslated', 'n'); } // Adding strings
* @package tikiwiki */ // (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project // // All Rights Reserved. See copyright.txt for details and a complete list of authors. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. // $Id$ require_once 'tiki-setup.php'; require_once 'lib/language/LanguageTranslations.php'; $access->check_feature('lang_use_db'); $access->check_permission('tiki_p_edit_languages'); // start interactive translation session if (!empty($_REQUEST['interactive_translation_mode'])) { $_SESSION['interactive_translation_mode'] = $_REQUEST['interactive_translation_mode']; if ($_REQUEST['interactive_translation_mode'] == 'off') { $cachelib->empty_cache('templates_c'); } header('Location: ' . $_SESSION['last_mid_php']); exit; } /* Called by the JQuery ajax request. No response expected. * Save strings translated using interactive translation to database. */ if (isset($_REQUEST['source'], $_REQUEST['trans']) && count($_REQUEST['source']) == count($_REQUEST['trans'])) { $translations = new LanguageTranslations(); foreach ($_REQUEST['trans'] as $k => $translation) { $source = $_REQUEST['source'][$k]; $translations->updateTrans($source, $translation); } exit; }
/** * Get the count of database stored translations for a language * @param language * @return true/false */ private function getDbTranslationCount($language) { $db_language = new LanguageTranslations($language); $db_language_translations = $db_language->getDbTranslations(); $db_translation_count = $db_language_translations["total"]; return $db_translation_count; }