start_page ?: ''; $module = $_REQUEST['module'] ?? ''; $lang = $_REQUEST['lang'] ?? ''; $action = $_POST['action'] ?? ''; if (!in_array($type, ['plugin', 'theme'])) { $type = ''; } if (!empty($type) && !empty($module)) { try { $module = $translater->getModule($type, $module); } catch(Exception $e) { $core->error->add($e->getMessage()); $module = ''; } } if (!empty($module) && !empty($lang)) { try { $lang = $translater->getLang($module, $lang); } catch(Exception $e) { $core->error->add($e->getMessage()); $lang = ''; } } $breadcrumb = [__('Translater') => $core->adminurl->get('translater', ['type' => '-'])]; if (empty($type)) { $breadcrumb = [__('Translater') => '']; } elseif (empty($module)) { $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = ''; } elseif (empty($lang)) { $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = $core->adminurl->get('translater', ['type' => $type]); $breadcrumb[html::escapeHTML($module->name)] = ''; } elseif (!empty($lang)) { $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = $core->adminurl->get('translater', ['type' => $type]); $breadcrumb[html::escapeHTML($module->name)] = $core->adminurl->get('translater', ['type' => $type, 'module' => $module->id]); $breadcrumb[html::escapeHTML(sprintf(__('%s language edition'), $lang->name))] = ''; } try { if ($action == 'module_create_backups') { if (empty($module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to backup')); } $module_codes = $module->getUsedlangs(); foreach($module_codes as $code_id) { if (in_array($code_id, $_POST['codes'])) { $module->createBackup($code_id); } } dcPage::addSuccessNotice(__('Backup successfully created')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_restore_backup') { if (empty($module) || empty($_POST['files'])) { throw New Exception(__('Nothing to restore')); } $module_backups = $module->getBackups(true); foreach($module_backups as $backup_file) { if (in_array($backup_file, $_POST['files'])) { $module->restoreBackup($backup_file); } } dcPage::addSuccessNotice(__('Backup successfully restored')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_delete_backup') { if (empty($module) || empty($_POST['files'])) { throw New Exception(__('Nothing to delete')); } $module_backups = $module->getBackups(true); foreach($module_backups as $backup_file) { if (in_array($backup_file, $_POST['files'])) { $module->deleteBackup($backup_file); } } dcPage::addSuccessNotice(__('Backup successfully deleted')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_export_pack') { if (empty($module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to export')); } $module->exportPack($_POST['codes']); dcPage::addSuccessNotice(__('Language successfully exported')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_import_pack') { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } $module->importPack($_FILES['packfile']); dcPage::addSuccessNotice(__('Language successfully imported')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_add_code') { if (empty($module) || empty($_POST['code'])) { throw new Exception(__('Nothing to create')); } $module->addLang($_POST['code'], $_POST['from'] ?? ''); dcPage::addSuccessNotice(__('Language successfully added')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } if ($action == 'module_delete_codes') { if (empty($module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to delete')); } $module_codes = $module->getUsedlangs(); foreach($module_codes as $code_id) { if (in_array($code_id, $_POST['codes'])) { $module->delLang($code_id); } } dcPage::addSuccessNotice(__('Language successfully deleted')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } if ($action == 'module_update_code') { if (empty($module) || empty($_POST['code']) || empty($_POST['entries'])) { throw new Exception(__('Nothing to update')); } if (!empty($_POST['update_group'])) { foreach($_POST['entries'] as $i => $entry) { if (isset($entry['check']) && isset($_POST['multigroup'])) { $_POST['entries'][$i]['group'] = $_POST['multigroup']; } } } $module->updLang($_POST['code'], $_POST['entries']); dcPage::addSuccessNotice(__('Language successfully updated')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } } catch (Exception $e) { $core->error->add($e->getMessage()); } echo '' . __('Translater') . '' . dcPage::jsPageTabs() . dcPage::cssLoad(dcPage::getPF('translater/css/translater.css')) . dcpage::jsJson('translater', [ 'title_add_detail' => __('Use this text'), 'image_field' => dcPage::getPF('translater/img/field.png'), 'image_toggle' => dcPage::getPF('translater/img/toggle.png') ]) . dcPage::jsLoad(dcPage::getPF('translater/js/translater.js')) . # --BEHAVIOR-- translaterAdminHeaders $core->callBehavior('translaterAdminHeaders') . '' . dcPage::breadcrumb($breadcrumb) . dcPage::notices(); if (empty($module) && $type != '') { // modules list echo '
'; $res = ''; $modules = $translater->getModules($type); ksort($modules); foreach ($modules as $module) { if ($translater->hide_default && in_array($module->id, $translater::$default_distrib_modules[$type])) { continue; } if ($module->root_writable) { $res .= sprintf( '%s', $core->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id]), html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))), html::escapeHTML(__($module->id)) ); } else { $res .= sprintf( '%s', html::escapeHTML(__($module->id)) ); } $codes = $module->getLangs(); foreach ($codes as $code_id => $code_name) { if ($module->root_writable) { $codes[$code_id] = sprintf( '%s (%s)', html::escapeHTML(sprintf(__('Edit language %s of module %s'), html::escapeHTML($code_name), __($module->name))), $core->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), html::escapeHTML($code_name), $code_id ); } else { $codes[$code_id] = html::escapeHTML($code_name) . '(' .$code_id . ')'; } } $res .= sprintf( '%s%s%s', implode(', ', $codes), html::escapeHTML($module->name), $module->version ); } if ($res) { echo '
' . $res . '
' . sprintf(__('Modules list of type "%s"'), $type) .'
' . __('Id') . ' ' . __('Languages') . ' ' . __('Name') . ' ' . __('Version') . '
'; } else { echo '' . __('There is no editable modules') . ''; } echo '
'; dcPage::helpBlock('translater.type'); } elseif (!empty($module) && empty($lang)) { $codes = $module->getUsedLangs(); $backups = $module->getBackups(); $unused_codes = $module->getUnusedLangs(); // module summary echo '

' . sprintf(__('Module %s %s by %s'), $module->name, $module->version, $module->author) . '

 

'; // existing languages if (count($codes)) { echo '

' . __('Translations') . '

' . '
' . '' . '' . '' . '' . '' . '' . '' . ''; foreach($codes AS $code_name => $code_id) { echo '' . '' . '' . ''; if (isset($backups[$code_id])) { foreach($backups[$code_id] AS $file => $info) { $time[$code_id] = isset($time[$code_id]) && $time[$code_id] > $info['time'] ? $time[$code_id] : $info['time']; } echo '' . ''; } else { echo ''; } echo ''; } echo '
' . __('Existing languages translations') .'
' . __('Language') . '' . __('Code') . '' . __('Backups') . '' . __('Last backup') . '
' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '' . '' . $code_name . '' . ' ' . $code_id . '' . count($backups[$code_id]) . ' ' . dt::str('%Y-%m-%d %H:%M', $time[$code_id], $core->blog->settings->system->blog_timezone) . '' . __('no backups') . '-

' . __('Selected languages action:') . ' ' . form::combo('action', [ __('Backup languages') => 'module_create_backups', __('Delete languages') => 'module_delete_codes', __('Export languages') => 'module_export_pack' ]) . '

' . $core->formNonce() . $core->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id] ) . '

 

'; } // backups if (!empty($codes) || !empty($backups)) { // delete / retore backups if (!empty($backups)) { echo '

' . __('Backups') . '

' . '
' . '' . '' . '' . '' . '' . '' . '' . '' . ''; $table_line = '' . '' . '' . '' . '' . '' . '' . ''; $i=0; foreach($backups as $backup_codes) { foreach($backup_codes as $backup_file => $backup_code) { $i++; $form_id = 'form_file_' . $backup_code['code'] . $backup_code['time']; echo sprintf($table_line, form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false), $form_id, $backup_code['name'], $backup_code['code'], dt::str( $core->blog->settings->system->date_format . ' ' . $core->blog->settings->system->time_format, $backup_code['time'], $core->blog->settings->system->blog_timezone ), $backup_code['path']['basename'], files::size($backup_code['size']) ); } } echo '
' . __('Existing languages backups') . '
' . __('Language') . '' . __('Code') . '' . __('Date') . '' . __('File') . '' . __('Size') . '
%s%s%s%s%s

' . __('Selected backups action:') . ' ' . form::combo('action', [ __('Restore backups') => 'module_restore_backup', __('Delete backups') => 'module_delete_backup' ]) . '

' . $core->formNonce() . $core->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id] ) . '

 

'; } } echo '
'; // add language if (!empty($unused_codes)) { echo '

' . __('Add language') . '

' . form::combo(['code'], array_merge(['-' => '-'], $unused_codes), $core->auth->getInfo('user_lang')) . '

'; if (empty($codes)) { echo '

' . form::hidden(['from'], '') . '

'; } else { echo '

' . form::combo(['from'], array_merge(['-' => ''], $codes)) . ' (' . __('optionnal') . ')

'; } echo '

' . $core->formNonce() . $core->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id, 'action' => 'module_add_code'] ) . '

 

'; } // Import echo '

' . __('Import') . '

' . $core->formNonce() . $core->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id, 'action' => 'module_import_pack'] ) . '

 

'; echo '
'; dcPage::helpBlock('translater.module'); } elseif (!empty($lang)) { $lines = $lang->getMessages(); echo '
' . '
' . '' . '' . '' . '' . '' . '' . '' . '' . ''; $table_line = '' . '' . '' . '' . '' . '' . '' . ''; $table_ul = '
%s
%s

'; $table_li = '%s
'; $i = 1; foreach ($lines AS $msgid => $rs) { $in_dc = ($rs['in_dc'] && $translater->parse_nodc); $allowed_l10n_groups = array_combine($translater::$allowed_l10n_groups, $translater::$allowed_l10n_groups); $t_msgstr = $t_files = $strin = []; foreach($rs['o_msgstrs'] as $o_msgstr) { if (!isset($strin[$o_msgstr['msgstr'][0]])) { $strin[$o_msgstr['msgstr'][0]] = []; } $strin[$o_msgstr['msgstr'][0]][] = ['module' => $o_msgstr['module'], 'file' => $o_msgstr['file']]; } foreach($strin as $k => $v) { $res = []; foreach($v as $str) { $res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file'])); } $t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res)); } if (!empty($rs['files'][0])) { if (count($rs['files']) == 1) { $t_files[] = $rs['files'][0][0] . ':' . $rs['files'][0][1]; } else { $res = []; foreach($rs['files'] as $location) { $res[] = sprintf($table_li, implode(' : ', $location)); } $t_files[] = sprintf($table_ul, sprintf(__('%s occurrences'), count($rs['files'])), implode('', $res));; } } echo sprintf($table_line, $in_dc ? ' offline' : ' translaterline', form::checkbox(['entries[' . $i . '][check]'], 1), form::combo(['entries[' . $i . '][group]'], $allowed_l10n_groups, $rs['group'], '', '', $in_dc), html::escapeHTML($msgid), form::hidden(['entries[' . $i . '][msgid]'], html::escapeHTML($msgid)) . form::field(['entries[' . $i . '][msgstr][0]'], 48, 255, html::escapeHTML($rs['msgstr'][0]), '', '', $in_dc), implode('', $t_msgstr), implode('', $t_files) ); if (!empty($rs['plural'])) { $t_msgstr = $strin = []; foreach($lang->plural as $j => $plural) { foreach($rs['o_msgstrs'] as $o_msgstr) { if (isset($o_msgstr['msgstr'][$j+1])) { if (!isset($strin[$o_msgstr['msgstr'][$j+1]])) { $strin[$o_msgstr['msgstr'][$j+1]] = []; } $strin[$o_msgstr['msgstr'][$j+1]][] = ['module' => $o_msgstr['module'], 'file' => $o_msgstr['file']]; } } foreach($strin as $k => $v) { $res = []; foreach($v as $str) { $res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file'])); } $t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res)); } echo sprintf($table_line, $in_dc ? ' offline' : ' translaterline', '+', sprintf(__('Plural "%s"'), $plural), sprintf(__('Plural form of "%s"'), $rs['plural']), form::hidden(['entries[' . $i . '][msgid_plural]'], html::escapeHTML($rs['plural'])) . form::field(['entries[' . $i . '][msgstr][' . $j+1 . ']'], 48, 255, html::escapeHTML($rs['msgstr'][$j+1] ?? ''), '', '', $in_dc), implode('', $t_msgstr), '' ); } } $i++; } echo sprintf($table_line, ' offline', form::checkbox(['entries[' . $i . '][check]'], 1), form::combo(['entries[' . $i . '][group]'], $allowed_l10n_groups, 'main'), form::field(['entries[' . $i . '][msgid]'], 48, 255, ''), form::field(['entries[' . $i . '][msgstr][0]'], 48, 255, ''), '', '' ); echo '
' . sprintf(__('List of %s localized strings'), count($lines)) . '
' . __('Group') . '' . __('String') . '' . __('Translation') . '' . __('Existing') . '' . __('File') . '
%s%s%s%s%s%s
' . '
' . '
' . '

' . '

' . '
' . '

' . '

' . $core->formNonce() . form::hidden(['code'], $lang->code) . $core->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $lang->code, 'action' => 'module_update_code'] ) . '

' . '
' . '

 

' . '
'; dcPage::helpBlock('translater.lang'); } else { $line = '
  • %s
  • '; echo '

    ' . __('Translate your Dotclear plugins and themes') . '

    ' . sprintf( '

    ', sprintf( $line, $core->adminurl->get('translater', ['type' => 'plugin']), $type == 'plugin' ? ' class="active"' : '', __('Translate plugins')) . sprintf( $line, $core->adminurl->get('translater', ['type' => 'theme']), $type == 'theme' ? ' class="active"' : '', __('Translate themes')) ); dcPage::helpBlock('translater.index'); } echo '';