__('Settings'), 'modules_plugin' => __('Plugins'), 'modules_theme' => __('Themes'), 'pack' => __('Import/Export') ); $combo_backup_limit = array( 5 => 5, 10 => 10, 15 => 15, 20 => 20, 40 => 40, 60 => 60 ); $combo_backup_folder = array( 'module' => __('locales folders of each module'), 'plugin' => __('plugins folder root'), 'public' => __('public folder root'), 'cache' => __('cache folder of Dotclear'), 'translater' =>__('locales folder of translater') ); $succes = array( 'save_setting' => __('Configuration successfully updated'), 'update_lang' => __('Translation successfully updated'), 'add_lang' => __('Translation successfully created'), 'delete_lang' => __('Translation successfully deleted'), 'create_backup' => __('Backups successfully create'), 'restore_backup' => __('Backups successfully restored'), 'delete_backup' => __('Backups successfully deleted'), 'import_pack' => __('Package successfully imported'), 'export_pack' => __('Package successfully exported') ); $errors = array( 'save_setting' => __('Failed to update settings: %s'), 'update_lang' => __('Failed to update translation: %s'), 'add_lang' => __('Failed to create translation: %s'), 'delete_lang' => __('Failed to delete translation: %s'), 'create_backup' => __('Failed to create backups: %s'), 'restore_backup' => __('Failed to restore backups: %s'), 'delete_backup' => __('Failed to delete backups: %s'), 'import_pack' => __('Failed to import package: %s'), 'export_pack' => __('Failed to export package: %s') ); $p_url = 'plugin.php?p=translater'; $start_page = @explode('_',$translater->start_page); if (count($start_page) < 2) $start_page[1] = ''; # # Parse request # $msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : ''; $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : $start_page[0]; $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : $start_page[1]; $module = isset($_REQUEST['module']) ? $_REQUEST['module'] : ''; $from = isset($_POST['from']) && $_POST['from'] != '-' ? $_POST['from'] : ''; $lang = isset($_REQUEST['lang']) && $_REQUEST['lang'] != '-' ? $_REQUEST['lang'] : ''; if ($type == '-' || $module == '-') { $type = $module = ''; } # # Manage action # switch ($action) { case '': break; /** * Create lang for a module */ case 'module_add_lang': try { if (empty($lang)) { throw new Exception(__('No lang to create')); } $translater->addLang($module,$lang,$from); http::redirect($p_url.'&part=lang&module='.$module.'&type='.$type.'&lang='.$lang.'&msg=add_lang'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Delete lang for a module */ case 'module_delete_lang': try { if (empty($lang)) { throw new Exception(__('No lang to delete')); } $translater->delLang($module,$lang); http::redirect($p_url.'&part=module&module='.$module.'&type='.$type.'&tab=module-lang&msg=delete_lang'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Create backup for a module */ case 'module_create_backup': try { if (empty($_POST['modules']) || empty($_POST['langs'])) { throw new Exception(__('No lang to backup')); } foreach($_POST['modules'] as $b_module) { $b_list = $translater->listLangs($b_module); foreach($_POST['langs'] as $b_lang) { if (isset($b_list[$b_lang])) { $translater->createBackup($b_module,$b_lang); } } } http::redirect($p_url.'&part=module&module='.$module.'&type='.$type.'&tab=module-backup&msg=creat_backup'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Restore backup for a module */ case 'module_restore_backup': try { if (empty($_POST['modules']) || empty($_POST['files'])) { throw New Exception(__('No blackup to restore')); } sort($_POST['files']); $done = false; foreach($_POST['modules'] as $b_module) { $b_list = $translater->listBackups($b_module,true); foreach($_POST['files'] as $b_file) { if (in_array($b_file,$b_list)) { $translater->restoreBackup($b_module,$b_file); $done = true; } } } if (!$done) { throw new Exception(__('No bakcup to to restore')); } http::redirect($p_url.'&part=module&module='.$module.'&type='.$type.'&tab=module-backup&msg=restore_backup'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Delete backup for a module */ case 'module_delete_backup': try { if (empty($_POST['modules']) || empty($_POST['files'])) { throw New Exception(__('No backup to delete')); } $done = false; foreach($_POST['modules'] as $b_module) { $b_list = $translater->listBackups($b_module,true); foreach($_POST['files'] as $b_file) { if (in_array($b_file,$b_list)) { $translater->deleteBackup($b_module,$b_file); $done = true; } } } if (!$done) { throw new Exception(__('No backup to delete')); } http::redirect($p_url.'&part=module&module='.$module.'&type='.$type.'&tab=module-backup&msg=delete_backup'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Import language package for a module */ case 'module_import_pack': try { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } $translater->importPack($_POST['modules'],$_FILES['packfile']); http::redirect($p_url.'&part=module&module='.$module.'&type='.$type.'&tab=module-pack&msg=import_pack'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Export language package for a module */ case 'module_export_pack': try { if (empty($_POST['modules']) || empty($_POST['entries'])) { throw new Exception(__('Nothing to export')); } $translater->exportPack($_POST['modules'],$_POST['entries']); http::redirect($p_url.'&part=module&module='.$module.'&type='.$type.'&tab=module-pack&msg=export_pack'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Update language */ case 'update_lang': try { if (empty($_POST['entries']) || empty($lang) || empty($module)) { throw new Exception(__('No language to update')); } foreach($_POST['entries'] as $i => $entry) { if (isset($entry['check']) && isset($_POST['multigroup'])) { $_POST['entries'][$i]['group'] = $_POST['multigroup']; unset($_POST['entries'][$i]['check']); } } $translater->updLang($module,$lang,$_POST['entries']); http::redirect($p_url.'&part=lang&module='.$module.'&type='.$type.'&lang='.$lang.'&msg='.$action); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Import language packages */ case 'import_pack': try { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } $translater->importPack($_POST['modules'],$_FILES['packfile']); http::redirect($p_url.'&part=pack&msg='.$action.'&tab=pack-import'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Export language packages */ case 'export_pack': try { if (empty($_POST['modules']) || empty($_POST['entries'])) { throw new Exception(__('Nothing to export')); } $translater->exportPack($_POST['modules'],$_POST['entries']); http::redirect($p_url.'&part=pack&msg='.$action.'&tab=pack-export'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Save settings */ case 'save_setting': try { if (empty($_POST['translater_write_po']) && empty($_POST['translater_write_langphp'])) { throw new Exception('You must choose one file format at least'); } foreach($translater->getDefaultSettings() as $k => $v) { $translater->set($k,(isset($_POST['translater_'.$k]) ? $_POST['translater_'.$k] : '')); } foreach($translater->proposal->getTools() AS $k => $v) { $v->save(); } http::redirect($p_url.'&part=setting&msg='.$action); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Modules / Unknow / None */ default: break; } # # Fill in title and prepare display # switch ($part) { /** * Modules */ case 'modules': $title = ''.($type == 'theme' ? __('Themes') : __('Plugins')).''; break; /** * Module */ case 'module': # Get info about requested module try { $M = $translater->getModule($module,$type); } catch(Exception $e) { $core->error->add(sprintf(__('Failed to launch translater: %s'),$e->getMessage())); $action = $module = $type = ''; $M = false; } if (!empty($module) && !empty($type) && !$M) { $action = $module = $type = ''; $M = false; } $M->langs = $translater->listLangs($module); $M->backups = $translater->listBackups($module); $M->unused_langs = array_flip(array_diff($translater->getIsoCodes(),$M->langs)); $M->used_langs = array_flip(array_diff($M->langs,array_flip($translater->getIsoCodes()))); $allowed_groups = array_combine( dcTranslater::$allowed_l10n_groups, dcTranslater::$allowed_l10n_groups ); $title = ''.($type == 'theme' ? __('Themes') : __('Plugins')).''. ' › '.$module.''; break; /** * Lang */ case 'lang': # Get infos on module wanted try { $M = $translater->getModule($module,$type); # Retrieve some infos $M->langs = $translater->listLangs($module); $M->backups = $translater->listBackups($module); $M->unused_langs = array_flip(array_diff($translater->getIsoCodes(),$M->langs)); $M->used_langs = array_flip(array_diff($M->langs,array_flip($translater->getIsoCodes()))); $allowed_groups = array_combine( dcTranslater::$allowed_l10n_groups, dcTranslater::$allowed_l10n_groups ); } catch(Exception $e) { $core->error->add(sprintf(__('Failed to launch translater: %s'),$e->getMessage())); $action = $module = $type = ''; $M = false; } if (!empty($module) && !empty($type) && !$M) { $action = $module = $type = ''; $M = false; } $title = ''.($type == 'theme' ? __('Themes') : __('Plugins')).''. ' › '. ''.$module.''; if (!empty($M->langs) && isset($M->langs[$lang])) { $title .= ' › '.$M->langs[$lang].''; } break; /** * Import/Export (pack) */ case 'pack': $title = ''.__('Import/Export').''; break; /** * Settings */ case 'setting': default: $title = ''.__('Settings').''; break; } # # Display page # echo ' '.__('Translater').''. dcPage::jsPageTabs($tab). dcPage::jsLoad('js/_posts_list.js'). dcPage::jsLoad('index.php?pf=translater/js/jquery.translater.js'); if ('' != $translater->proposal_tool) { echo '\n". "\n"; } # --BEHAVIOR-- translaterAdminHeaders $core->callBehavior('translaterAdminHeaders'); echo '

'.__('Translater').' › '.$title. ' - '.__('Plugins').''. ' - '.__('Themes').''. ' - '.__('Import/Export').''. '

'; if (isset($succes[$msg])) { dcPage::message($succes[$msg]); } switch ($part) { /** * Modules */ case 'modules': echo '
'; $res = ''; foreach ($translater->listModules($type) as $k => $v) { if ($translater->hide_default && in_array($k,dcTranslater::$default_dotclear_modules[$type])) { continue; } if ($v['root_writable']) { $res .= ''. ''. ''.$k.''; } else { $res .= ''. ''.$k.''; } $res .= ''.$v['version'].''. ''; $array_langs = array(); foreach ($translater->listLangs($k) as $lang_name => $lang_infos) { $array_langs[$lang_name] = ''. $lang_name.''; } $res .= implode(', ',$array_langs). ''. ''; } if ($res) { echo ' '. $res. '
'.__('Id').' '.__('Version').' '.__('Languages').'
'; } else { echo ''.__('There is no editable modules').''; } echo '

 

'; break; /** * Module */ case 'module': # Summary echo '

'.__('Module').'

'.__('About').'
'.__('Name').' '.$M->name.'
'.__('Version').' '.$M->version.'
'.__('Author').' '.$M->author.'
'.__('Type').' '.$M->type.'
'.__('Root').' '.$M->root.'
'.__('Backups').' '. $translater->getBackupFolder($module).'

 

'; if (count($M->langs)) { echo '

'.__('l10n').'

'. ''. ''. ''. ''. ''. ''. ''; foreach($M->langs AS $lang => $name) { echo ''. ''. ''; if (isset($M->backups[$lang])) { foreach($M->backups[$lang] AS $file => $info) { $time[$lang] = isset($time[$lang]) && $time[$lang] > $info['time'] ? $time[$lang] : $info['time']; } echo ''. ''; } else { echo ''; } echo ''; } echo '
'.__('Languages').''.__('Code').''.__('Backups').''.__('Last backup').'
'. ''.$name.''. ' '.$lang.''.count($M->backups[$lang]).' '. dt::str('%Y-%m-%d %H:%M',$time[$lang],$core->blog->settings->system->blog_timezone). ''.__('no backup').'
'; } echo '
'; # Add/Remove/Edit lang echo '
'; # Edit lang if (!empty($M->langs)) { echo '

'.__('Edit language').'

'.__('Select language:').' '. form::combo(array('lang'),$M->used_langs,$lang).'

'. $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),''). form::hidden(array('part'),'lang'). form::hidden(array('p'),'translater').'

 

'; } # New lang if (!empty($M->unused_langs)) { echo '

'.__('Add language').'

'.__('Select language:').' '. form::combo(array('lang'),array_merge(array('-'=>'-'),$M->unused_langs),$core->auth->getInfo('user_lang')).'

'; if (!empty($M->used_langs)) { echo '

'.__('Copy from language:').' '. form::combo(array('from'),array_merge(array('-'=>'-'),$M->used_langs)). ' ('.__('Optionnal').')

'; } else { echo '

'.form::hidden(array('from'),'').'

'; } echo '

'. $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'module_add_lang'). form::hidden(array('part'),'module'). form::hidden(array('tab'),'module-lang'). form::hidden(array('p'),'translater').'

 

'; } # Delete lang if (!empty($M->used_langs)) { echo '

'.__('Delete language').'

'.__('Select language:').' '. form::combo(array('lang'),array_merge(array('-'=>'-'),$M->used_langs)).'

'. $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'module_delete_lang'). form::hidden(array('part'),'module'). form::hidden(array('tab'),'module-lang'). form::hidden(array('p'),'translater').'

 

'; } echo '
'; # Create/delete/restore backups if (!empty($M->used_langs) || !empty($M->backups)) { echo '
'; if (!empty($M->used_langs)) { echo '

'.__('Create backups').'

'.__('Choose languages to backup').'

'; $i=0; foreach($M->used_langs AS $name => $lang) { $i++; echo ' '; } echo '
'.form::checkbox(array('langs[]'),$lang,'','','',false).' '.$name.' '.$lang.'

 

 

'. form::hidden(array('modules[]'),$module). $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'module_create_backup'). form::hidden(array('part'),'module'). form::hidden(array('tab'),'module-backup'). form::hidden(array('p'),'translater').'

 

'; } if (!empty($M->backups)) { echo '

'.__('List of backups').'

'. '
'. ''. ''. ''. ''. ''. ''. ''; $i=0; foreach($M->backups as $lang => $langs) { foreach($langs as $file => $infos) { $i++; echo ''. ''. ''. ''. ''. ''. ''; } } echo '
'.__('File').''.__('Date').''.__('Language').''.__('Size').'
'.form::checkbox(array('files[]'),$file,'','','',false).''.$file.''. dt::str(__('%Y-%m-%d %H:%M:%S'),$infos['time'],$core->blog->settings->system->blog_timezone). ''.$translater->isIsoCode($lang).''.files::size($infos['size']).'

 

'.__('Selected backups action:').' '. form::combo('action',array( __('Restore backups') => 'module_restore_backup', __('Delete backups') => 'module_delete_backup') ).' '. form::hidden(array('modules[]'),$module). $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('part'),'module'). form::hidden(array('tab'),'module-backup'). form::hidden(array('p'),'translater').'

 

'; } echo '
'; } // end if (!empty($M->used_langs) || !empty($M->backups)) { # Import/Export pack echo '
'; # Import echo '

'.__('Import').'

'.__('Choose language package to import').'

'. form::hidden(array('modules[]'),$module). $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'module_import_pack'). form::hidden(array('part'),'module'). form::hidden(array('tab'),'module-pack'). form::hidden(array('p'),'translater').'

 

'; # Export if (!empty($M->used_langs)) { echo '

'.__('Export').'

'. '
'. '

'.__('Choose languages to export').'

'. ''. ''; $i=0; foreach($M->used_langs AS $name => $lang) { $i++; echo ''. ''. ''. ''. ''; } echo '
'. form::checkbox(array('entries[]'),$lang,'','','',false). ''.$name.''.$lang.'
'. '
'. '

 

'. '

 

'. '
'. '

'. ''. form::hidden(array('modules[]'),$module). $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'module_export_pack'). form::hidden(array('part'),'module'). form::hidden(array('tab'),'module-pack'). form::hidden(array('p'),'translater'). '

'. '
'. '

 

'; } echo '
'; break; /** * Lang */ case 'lang': # Existing langs if (empty($M->langs) || !isset($M->langs[$lang])) { break; } $iso = $M->langs[$lang]; $i = 0; $sort_order = 'asc'; $lines = $translater->getMsgs($module,$lang); # Sort array if (isset($_GET['sort']) && !empty($lines)) { $sort = explode(',',$_GET['sort']); $sort_by = $sort[0]; $sort_order = isset($sort[1]) && $sort[1] == 'desc' ? 'asc' : 'desc'; switch($sort_by) { case 'group': foreach($lines AS $k => $v) { $sort_list[] = $v['group']; } break; case 'msgid': foreach($lines AS $k => $v) { $sort_list[] = strtolower($k); } break; case 'file': foreach($lines AS $k => $v) { $file = array(); foreach($v['files'] as $fv) { $file[] = empty($fv[0]) || empty($fv[1]) ? '' : $fv[0].($fv[1] /1000); } sort($file); $sort_list[] = $file[0]; } break; case 'msgstr': foreach($lines AS $k => $v) { $sort_list[] = strtolower($v['msgstr']); } break; default: $sort_list = false; break; } if ($sort_list) { array_multisort( $sort_list, ($sort_order == 'asc' ? SORT_DESC : SORT_ASC), SORT_STRING, $lines ); } } echo '
'. '
'. ''. ''. ''. ''. ''. ''. ''. ''; foreach ($lines AS $msgid => $rs) { $i++; $in_dc = ($rs['in_dc'] && $translater->parse_nodc); echo ''. ''. 'proposal_tool ? ' class="translatermsgid"' : '' ).'>'. html::escapeHTML($msgid).''. ''. ''. ''. ''; } $i++; echo ''. ''. ''. ''. ''. ''. ''. '
'.__('Group').''.__('String').''.__('Translation').''.__('Existing').''.__('File').'
'. form::checkbox(array('entries['.$i.'][check]'),1).' '. form::combo(array('entries['.$i.'][group]'), $allowed_groups,$rs['group'],'','',$in_dc ). ''. form::hidden(array('entries['.$i.'][msgid]'),html::escapeHTML($msgid)). form::field(array('entries['.$i.'][msgstr]'), 75,255,html::escapeHTML($rs['msgstr']),'','',$in_dc). ''; $strin = array(); foreach($rs['o_msgstrs'] AS $o_msgstr) { if (!isset($strin[$o_msgstr['msgstr']])) { $strin[$o_msgstr['msgstr']] = ''; } $strin[$o_msgstr['msgstr']][] = array('module'=>$o_msgstr['module'],'file'=>$o_msgstr['file']); } foreach($strin as $k => $v) { echo '
'.html::escapeHTML($k).'
'; foreach($v as $str) { echo ''.html::escapeHTML($str['module'].' => '.$str['file']).'
'; } echo '

'; } echo '
'; if (empty($rs['files'][0])) { echo ' '; } elseif (count($rs['files']) == 1) { echo $rs['files'][0][0].' : '.$rs['files'][0][1]; } else { echo ''.sprintf(__('%s occurrences'),count($rs['files'])).''. '
'; foreach($rs['files'] as $location) { echo ''.implode(' : ',$location).'
'; } echo '
'; } echo '
'. form::checkbox(array('entries['.$i.'][check]'),1).' '. form::combo(array('entries['.$i.'][group]'),$allowed_groups,'main'). ''.form::field(array('entries['.$i.'][msgid]'),75,255,'').''.form::field(array('entries['.$i.'][msgstr]'),75,255,'').'  
'. '

'.sprintf(__('Total of %s strings.'),$i-1).'

'. '

'. '

'.__('Change the group of the selected entries to:').' '. form::combo(array('multigroup'),$allowed_groups). '

'. '

'. ''. $core->formNonce(). form::hidden(array('lang'),$lang). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'update_lang'). form::hidden(array('part'),'lang'). form::hidden(array('p'),'translater'). '

'. '
'. '

 

'. '
'; break; /** * Import/Export (Pack) */ case 'pack': # Import echo '

'.__('Choose language package to import').'

'; $i=0; foreach($translater->listModules() AS $k => $v) { if ($translater->hide_default && ( in_array($k,dcTranslater::$default_dotclear_modules['plugin']) || in_array($k,dcTranslater::$default_dotclear_modules['theme']))) continue; echo form::hidden(array('modules[]'),$k);$i++; } echo $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'import_pack'). form::hidden(array('part'),'pack'). form::hidden(array('tab'),'pack-import'). form::hidden(array('p'),'translater').'

'; # Export echo '

'.__('Choose modules to export').'

'; $i=0; $langs_list = array(); foreach($translater->listModules() AS $k => $v) { if ($translater->hide_default && ( in_array($k,dcTranslater::$default_dotclear_modules['plugin']) || in_array($k,dcTranslater::$default_dotclear_modules['theme']))) continue; $info_lang = $translater->listLangs($k); if (!is_array($info_lang) || 1 > count($info_lang)) continue; $i++; $langs_list = array_merge($langs_list,$info_lang); echo ' '; } echo '
'.__('Modules').''.__('Languages').'
'.form::checkbox(array('modules[]'),$k,'','','',false).' '.$v['name'].' '.implode(', ',$info_lang).'

'.__('Choose languages to export').'

'; $i=0; foreach($langs_list AS $k => $v) { $i++; echo ' '; } echo '
'.__('Languages').''.__('Code').'
'.form::checkbox(array('entries[]'),$k,'','','',false).' '.$v.' '.$k.'

 

'. $core->formNonce(). form::hidden(array('type'),$type). form::hidden(array('module'),$module). form::hidden(array('action'),'export_pack'). form::hidden(array('part'),'pack'). form::hidden(array('tab'),'pack-export'). form::hidden(array('p'),'translater').'

'; break; /** * Settings */ case 'setting': default: echo '


'.form::field('translater_parse_userinfo',65,255,$translater->parse_userinfo).'

'.__('Select and configure the tool to use to translate strings:').'

'; foreach($translater->proposal->getTools() AS $k => $v) { $form = $v->form(); echo '
'. (empty($form) ? '

'.sprintf(__('Nothing to configure for %s tool.'),$v->getName()).'

' : $form ).'
'; } echo '

'. $core->formNonce(). form::hidden(array('p'),'translater'). form::hidden(array('part'),'setting'). form::hidden(array('action'),'save_setting').'

'; break; } dcPage::helpBlock('translater'); echo '

'. ''.__('Settings').' - '. 'translater - '.$core->plugins->moduleInfo('translater','version').'  '.__('Translater').'

'; ?>