translater/index.php

599 lines
24 KiB
PHP
Raw Normal View History

2021-08-18 19:42:30 +00:00
<?php
2021-09-02 21:44:01 +00:00
/**
* @brief translater, a plugin for Dotclear 2
2021-11-01 21:32:32 +00:00
*
2021-09-02 21:44:01 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-01 21:32:32 +00:00
*
2021-09-02 21:44:01 +00:00
* @author Jean-Christian Denis & contributors
2021-11-01 21:32:32 +00:00
*
2021-09-02 21:44:01 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-08-18 22:48:47 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
2021-08-18 19:42:30 +00:00
dcPage::checkSuper();
2022-11-13 17:40:31 +00:00
$translater = new dcTranslater();
2021-08-18 19:42:30 +00:00
2021-11-01 21:32:32 +00:00
$type = $_REQUEST['type'] ?? $translater->start_page ?: '';
$module = $_REQUEST['module'] ?? '';
2021-11-01 21:32:32 +00:00
$lang = $_REQUEST['lang'] ?? '';
$action = $_POST['action'] ?? '';
2021-08-18 22:48:47 +00:00
if (!in_array($type, ['plugin', 'theme'])) {
$type = '';
2021-08-18 22:48:47 +00:00
}
2021-08-18 19:42:30 +00:00
if (!empty($type) && !empty($module)) {
try {
$module = $translater->getModule($type, $module);
2021-11-01 21:32:32 +00:00
} catch (Exception $e) {
2022-11-13 17:40:31 +00:00
dcCore::app()->error->add($e->getMessage());
$module = '';
}
2021-08-18 19:42:30 +00:00
}
if (!empty($module) && !empty($lang)) {
try {
$lang = $translater->getLang($module, $lang);
2021-11-01 21:32:32 +00:00
} catch (Exception $e) {
2022-11-13 17:40:31 +00:00
dcCore::app()->error->add($e->getMessage());
$lang = '';
}
}
2021-08-18 22:48:47 +00:00
2022-12-26 20:48:51 +00:00
$breadcrumb = [__('Translater') => dcCore::app()->adminurl->get(basename(__DIR__), ['type' => '-'])];
if (empty($type)) {
$breadcrumb = [__('Translater') => ''];
} elseif (empty($module)) {
$breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = '';
} elseif (empty($lang)) {
2022-12-26 20:48:51 +00:00
$breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $type]);
2021-11-01 21:32:32 +00:00
$breadcrumb[html::escapeHTML($module->name)] = '';
} elseif (!empty($lang)) {
2022-12-26 20:48:51 +00:00
$breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $type]);
$breadcrumb[html::escapeHTML($module->name)] = dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $type, 'module' => $module->id]);
$breadcrumb[html::escapeHTML(sprintf(__('%s language edition'), $lang->name))] = '';
}
2021-08-18 22:48:47 +00:00
try {
if ($action == 'module_create_backups') {
if (empty($module) || empty($_POST['codes'])) {
throw new Exception(__('Nothing to backup'));
2021-08-18 22:48:47 +00:00
}
$module_codes = $module->getUsedlangs();
2021-11-01 21:32:32 +00:00
foreach ($module_codes as $code_id) {
if (in_array($code_id, $_POST['codes'])) {
$module->createBackup($code_id);
2021-08-18 22:48:47 +00:00
}
}
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Backup successfully created'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]);
2021-08-18 22:48:47 +00:00
}
if ($action == 'module_restore_backup') {
if (empty($module) || empty($_POST['files'])) {
2021-11-01 21:32:32 +00:00
throw new Exception(__('Nothing to restore'));
2021-08-18 22:48:47 +00:00
}
$module_backups = $module->getBackups(true);
2021-11-01 21:32:32 +00:00
foreach ($module_backups as $backup_file) {
if (in_array($backup_file, $_POST['files'])) {
$module->restoreBackup($backup_file);
2021-08-18 22:48:47 +00:00
}
}
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Backup successfully restored'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]);
}
2021-08-18 22:48:47 +00:00
if ($action == 'module_delete_backup') {
if (empty($module) || empty($_POST['files'])) {
2021-11-01 21:32:32 +00:00
throw new Exception(__('Nothing to delete'));
}
$module_backups = $module->getBackups(true);
2021-11-01 21:32:32 +00:00
foreach ($module_backups as $backup_file) {
if (in_array($backup_file, $_POST['files'])) {
$module->deleteBackup($backup_file);
2021-08-18 22:48:47 +00:00
}
}
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Backup successfully deleted'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]);
}
2021-08-18 22:48:47 +00:00
if ($action == 'module_export_pack') {
if (empty($module) || empty($_POST['codes'])) {
throw new Exception(__('Nothing to export'));
2021-08-18 22:48:47 +00:00
}
$module->exportPack($_POST['codes']);
2021-08-18 22:48:47 +00:00
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Language successfully exported'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]);
}
2021-08-18 22:48:47 +00:00
if ($action == 'module_import_pack') {
if (empty($_FILES['packfile']['name'])) {
throw new Exception(__('Nothing to import'));
}
$module->importPack($_FILES['packfile']);
2021-08-18 22:48:47 +00:00
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Language successfully imported'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]);
}
2021-08-18 22:48:47 +00:00
if ($action == 'module_add_code') {
if (empty($module) || empty($_POST['code'])) {
throw new Exception(__('Nothing to create'));
2021-08-18 22:48:47 +00:00
}
$module->addLang($_POST['code'], $_POST['from'] ?? '');
2021-08-18 22:48:47 +00:00
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Language successfully added'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]);
}
2021-08-18 22:48:47 +00:00
if ($action == 'module_delete_codes') {
if (empty($module) || empty($_POST['codes'])) {
throw new Exception(__('Nothing to delete'));
2021-08-18 22:48:47 +00:00
}
$module_codes = $module->getUsedlangs();
2021-11-01 21:32:32 +00:00
foreach ($module_codes as $code_id) {
if (in_array($code_id, $_POST['codes'])) {
$module->delLang($code_id);
}
}
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Language successfully deleted'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]);
}
2021-08-18 22:48:47 +00:00
if ($action == 'module_update_code') {
if (empty($module) || empty($_POST['code']) || empty($_POST['entries'])) {
throw new Exception(__('Nothing to update'));
2021-08-18 22:48:47 +00:00
}
if (!empty($_POST['update_group'])) {
2021-11-01 21:32:32 +00:00
foreach ($_POST['entries'] as $i => $entry) {
2021-08-18 22:48:47 +00:00
if (isset($entry['check']) && isset($_POST['multigroup'])) {
$_POST['entries'][$i]['group'] = $_POST['multigroup'];
}
}
}
$module->updLang($_POST['code'], $_POST['entries']);
2021-08-18 22:48:47 +00:00
2022-11-13 17:40:31 +00:00
dcAdminNotices::addSuccessNotice(__('Language successfully updated'));
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]);
}
} catch (Exception $e) {
2022-11-13 17:40:31 +00:00
dcCore::app()->error->add($e->getMessage());
2021-08-18 19:42:30 +00:00
}
2021-11-01 21:32:32 +00:00
echo
'<html><head><title>' . __('Translater') . '</title>' .
dcPage::jsPageTabs() .
2022-12-26 20:48:51 +00:00
dcPage::cssModuleLoad(basename(__DIR__) . '/css/translater.css') .
2022-11-13 17:40:31 +00:00
dcPage::jsJson('translater', [
'title_add_detail' => __('Use this text'),
2022-12-26 20:48:51 +00:00
'image_field' => dcPage::getPF(basename(__DIR__) . '/img/field.png'),
'image_toggle' => dcPage::getPF(basename(__DIR__) . '/img/toggle.png'),
]) .
2022-12-26 20:48:51 +00:00
dcPage::jsModuleLoad(basename(__DIR__) . '/js/translater.js') .
2021-08-18 22:48:47 +00:00
# --BEHAVIOR-- translaterAdminHeaders
2022-11-13 17:40:31 +00:00
dcCore::app()->callBehavior('translaterAdminHeaders') .
2021-08-18 22:48:47 +00:00
'</head><body>' .
2021-08-18 22:48:47 +00:00
dcPage::breadcrumb($breadcrumb) .
dcPage::notices();
2021-08-18 22:48:47 +00:00
if (empty($module) && $type != '') {
// modules list
2022-12-26 20:48:51 +00:00
echo '<form id="theme-form" method="post" action="' . dcCore::app()->adminurl->get(basename(__DIR__), ['type' => 'plugin']) . '">';
2021-08-18 22:48:47 +00:00
2021-11-01 21:32:32 +00:00
$res = '';
2021-10-28 21:33:26 +00:00
$modules = $translater->getModules($type);
ksort($modules);
foreach ($modules as $module) {
if ($translater->hide_default && in_array($module->id, $translater::$default_distrib_modules[$type])) {
continue;
2021-08-18 22:48:47 +00:00
}
if ($module->root_writable) {
$res .= sprintf(
'<tr class="line"><td class="nowrap minimal"><a href="%s" title="%s">%s</a></td>',
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $module->type, 'module' => $module->id]),
html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))),
2021-11-01 21:28:43 +00:00
html::escapeHTML($module->id)
);
} else {
$res .= sprintf(
'<tr class="line offline"><td class="nowrap">%s</td>',
2021-11-01 21:28:43 +00:00
html::escapeHTML($module->id)
);
2021-08-18 22:48:47 +00:00
}
$codes = $module->getLangs();
foreach ($codes as $code_id => $code_name) {
if ($module->root_writable) {
$codes[$code_id] = sprintf(
'<a class="wait maximal nowrap" title="%s" href="%s">%s (%s)</a>',
2021-11-01 21:32:32 +00:00
html::escapeHTML(sprintf(__('Edit language %s of module %s'), html::escapeHTML($code_name), __($module->name))),
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]),
html::escapeHTML($code_name),
$code_id
);
2021-08-18 22:48:47 +00:00
} else {
2021-11-01 21:32:32 +00:00
$codes[$code_id] = html::escapeHTML($code_name) . '(' . $code_id . ')';
2021-08-18 22:48:47 +00:00
}
}
$res .= sprintf(
'<td class="nowrap maximal">%s</td><td class="nowrap minimal">%s</td><td class="nowrap minimal count">%s</td></tr>',
implode(', ', $codes),
2021-11-01 21:28:43 +00:00
html::escapeHTML(__($module->name)),
$module->version
);
}
if ($res) {
2021-08-18 22:48:47 +00:00
echo '
<div class="table-outer">
<table class="clear">
2021-11-01 21:32:32 +00:00
<caption>' . sprintf(__('Modules list of type "%s"'), $type) . '</caption>
<tr>
<th class="nowrap">' . __('Id') . '</th>
2021-10-28 21:33:26 +00:00
<th class="nowrap">' . __('Languages') . '</th>
<th class="nowrap">' . __('Name') . '</th>
<th class="nowrap">' . __('Version') . '</th>
</tr>' .
$res .
'</table></div>';
} else {
echo '<tr><td colspan="6">' . __('There is no editable modules') . '</td></tr>';
}
echo '</form>';
dcPage::helpBlock('translater.type');
} elseif (!empty($module) && empty($lang)) {
2021-11-01 21:32:32 +00:00
$codes = $module->getUsedLangs();
$backups = $module->getBackups();
$unused_codes = $module->getUnusedLangs();
2021-11-01 21:32:32 +00:00
// module summary
echo '<h3>' . sprintf(__('Module %s %s by %s'), $module->name, $module->version, $module->author) . '</h3>
<ul class="nice col">
<li><strong>' . __('Root') . '</strong> ' . $module->root . '</li>
<li><strong>' . __('Locales') . '</strong> ' . $module->locales . '</li>
<li><strong>' . __('Backups') . '</strong> ' . $module->getBackupRoot() . '</li>
</ul>
<p>&nbsp;</p>';
// existing languages
if (count($codes)) {
2021-11-01 21:32:32 +00:00
echo
'<div class="clear fieldset"><h3>' . __('Translations') . '</h3>' .
2022-12-26 20:48:51 +00:00
'<form id="module-translations-form" method="post" action="' . dcCore::app()->adminurl->get(basename(__DIR__)) . '">' .
2021-11-01 21:32:32 +00:00
'<table class="clear maximal">' .
'<caption>' . __('Existing languages translations') . '</caption>' .
'<tr>' .
'<th class="nowrap" colspan="2">' . __('Language') . '</th>' .
'<th class="nowrap">' . __('Code') . '</th>' .
'<th class="nowrap">' . __('Backups') . '</th>' .
'<th class="nowrap">' . __('Last backup') . '</th>' .
'</tr>';
2021-08-18 22:48:47 +00:00
2021-11-01 21:32:32 +00:00
foreach ($codes as $code_name => $code_id) {
echo
'<tr class="line">' .
'<td class="minimal">' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '</td>' .
2021-11-01 21:32:32 +00:00
'<td class="nowrap">' .
'<a href="' .
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id])
2021-11-01 21:32:32 +00:00
. '" title="' . sprintf(__('Edit %s language'), html::escapeHTML($code_name)) . '">' . $code_name . '</a>' .
'</td>' .
'<td class="nowrap maximal"> ' . $code_id . '</td>';
2021-09-02 21:44:01 +00:00
if (isset($backups[$code_id])) {
$time[$code_id] = 0;
2021-11-01 21:32:32 +00:00
foreach ($backups[$code_id] as $file => $info) {
$time[$code_id] = isset($time[$code_id]) && $time[$code_id] > $info['time'] ?
$time[$code_id] : $info['time'];
2021-08-18 22:48:47 +00:00
}
2021-11-01 21:32:32 +00:00
echo
'<td class="nowrap">' . count($backups[$code_id]) . '</td>' .
'<td class="nowrap"> ' .
dt::str('%Y-%m-%d %H:%M', (int) $time[$code_id], dcCore::app()->blog->settings->system->blog_timezone) .
'</td>';
2021-08-18 22:48:47 +00:00
} else {
echo '<td class="nowrap">' . __('no backups') . '</td><td class="maximal nowrap">-</td>';
2021-08-18 22:48:47 +00:00
}
echo '</tr>';
2021-08-18 22:48:47 +00:00
}
echo '</table>
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
2021-11-01 21:32:32 +00:00
<p class="col right">' . __('Selected languages action:') . ' ' .
form::combo('action', [
__('Backup languages') => 'module_create_backups',
__('Delete languages') => 'module_delete_codes',
2022-11-13 17:40:31 +00:00
__('Export languages') => 'module_export_pack',
]) . '
<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' .
2022-11-13 17:40:31 +00:00
dcCore::app()->formNonce() .
dcCore::app()->adminurl->getHiddenFormFields(
2022-12-26 20:48:51 +00:00
basename(__DIR__),
['type' => $module->type, 'module' => $module->id]
) . '
</p></div></form><p>&nbsp;</p></div>';
}
2021-08-18 22:48:47 +00:00
// backups
if (!empty($codes) || !empty($backups)) {
// delete / retore backups
if (!empty($backups)) {
2021-11-01 21:32:32 +00:00
echo '<div class="fieldset"><h3>' . __('Backups') . '</h3>' .
2022-12-26 20:48:51 +00:00
'<form id="module-backups-form" method="post" action="' . dcCore::app()->adminurl->get(basename(__DIR__)) . '">' .
2021-11-01 21:32:32 +00:00
'<table class="clear">' .
'<caption>' . __('Existing languages backups') . '</caption>' .
2021-11-01 21:32:32 +00:00
'<tr>' .
'<th class="nowrap" colspan="2">' . __('Language') . '</th>' .
'<th class="nowrap">' . __('Code') . '</th>' .
'<th class="nowrap">' . __('Date') . '</th>' .
'<th class="nowrap">' . __('File') . '</th>' .
'<th class="nowrap">' . __('Size') . '</th>' .
'</tr>';
2021-11-01 21:32:32 +00:00
$table_line = '<tr class="line">' .
'<td class="minimal">%s</td>' .
'<td class="nowrap"><label for="%s">%s</label></td>' .
'<td class="nowrap maximal">%s</td>' .
'<td class="nowrap count">%s</td>' .
2021-11-01 21:32:32 +00:00
'<td class="nowrap">%s</td>' .
'<td class="nowrap count">%s</td>' .
'</tr>';
2021-11-01 21:32:32 +00:00
$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'];
2021-11-01 21:32:32 +00:00
echo sprintf(
$table_line,
form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false),
2021-11-01 21:32:32 +00:00
$form_id,
$backup_code['name'],
$backup_code['code'],
dt::str(
2022-11-13 17:40:31 +00:00
dcCore::app()->blog->settings->system->date_format . ' ' . dcCore::app()->blog->settings->system->time_format,
(int) $backup_code['time'],
2022-11-13 17:40:31 +00:00
dcCore::app()->blog->settings->system->blog_timezone
),
$backup_code['path']['basename'],
files::size($backup_code['size'])
);
}
2021-08-18 22:48:47 +00:00
}
echo '
</table>
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
2021-11-01 21:32:32 +00:00
<p class="col right">' . __('Selected backups action:') . ' ' .
form::combo('action', [
__('Restore backups') => 'module_restore_backup',
2022-11-13 17:40:31 +00:00
__('Delete backups') => 'module_delete_backup',
]) . '
<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' .
2022-11-13 17:40:31 +00:00
dcCore::app()->formNonce() .
dcCore::app()->adminurl->getHiddenFormFields(
2022-12-26 20:48:51 +00:00
basename(__DIR__),
['type' => $module->type, 'module' => $module->id]
) . '
</p></div></form><p>&nbsp;</p></div>';
2021-08-18 22:48:47 +00:00
}
}
2021-08-18 22:48:47 +00:00
echo '<div class="two-cols">';
// add language
if (!empty($unused_codes)) {
echo '<div class="col fieldset"><h3>' . __('Add language') . '</h3>
2022-12-26 20:48:51 +00:00
<form id="muodule-code-create-form" method="post" action="' . dcCore::app()->adminurl->get(basename(__DIR__)) . '">
2021-11-01 21:32:32 +00:00
<p class="field"><label for="code">' . __('Select language:') . '</label>' .
2022-11-13 17:40:31 +00:00
form::combo(['code'], array_merge(['-' => '-'], $unused_codes), dcCore::app()->auth->getInfo('user_lang')) . '</p>';
if (empty($codes)) {
echo '<p>' . form::hidden(['from'], '') . '</p>';
} else {
2021-11-01 21:32:32 +00:00
echo
'<p class="field"><label for="from">' . __('Copy from language:') . '</label>' .
form::combo(['from'], array_merge(['-' => ''], $codes)) . ' (' . __('optionnal') . ')</p>';
}
echo '
2021-11-01 21:32:32 +00:00
<p><input type="submit" name="save" value="' . __('Create') . '" />' .
2022-11-13 17:40:31 +00:00
dcCore::app()->formNonce() .
dcCore::app()->adminurl->getHiddenFormFields(
2022-12-26 20:48:51 +00:00
basename(__DIR__),
['type' => $module->type, 'module' => $module->id, 'action' => 'module_add_code']
) . '
</p></form><p>&nbsp;</p></div>';
}
// Import
echo '<div class="col fieldset"><h3>' . __('Import') . '</h3>
2022-12-26 20:48:51 +00:00
<form id="module-pack-import-form" method="post" action="' . dcCore::app()->adminurl->get(basename(__DIR__)) . '" enctype="multipart/form-data">
<p><label for="packfile">' . __('Select languages package to import:') . '<label> ' .
'<input id="packfile" type="file" name="packfile" /></p>
<p>
2021-11-01 21:32:32 +00:00
<input type="submit" name="save" value="' . __('Import') . '" />' .
2022-11-13 17:40:31 +00:00
dcCore::app()->formNonce() .
dcCore::app()->adminurl->getHiddenFormFields(
2022-12-26 20:48:51 +00:00
basename(__DIR__),
['type' => $module->type, 'module' => $module->id, 'action' => 'module_import_pack']
) . '
</p></form><p>&nbsp;</p></div>';
2021-08-18 22:48:47 +00:00
echo '</div>';
dcPage::helpBlock('translater.module');
} elseif (!empty($lang)) {
2022-11-20 16:42:52 +00:00
$lines = $lang->getMessages();
2022-11-13 17:40:31 +00:00
$allowed_l10n_groups = [];
2021-11-01 21:32:32 +00:00
echo
'<div id="lang-form">' .
2022-12-26 20:48:51 +00:00
'<form id="lang-edit-form" method="post" action="' . dcCore::app()->adminurl->get(basename(__DIR__)) . '">' .
2021-11-01 21:32:32 +00:00
'<table class="table-outer">' .
'<caption>' . sprintf(__('List of %s localized strings'), count($lines)) . '</caption>' .
2021-11-01 21:32:32 +00:00
'<tr>' .
'<th colspan="2">' . __('Group') . '</th>' .
'<th>' . __('String') . '</th>' .
'<th>' . __('Translation') . '</th>' .
'<th>' . __('Existing') . '</th>' .
'<th>' . __('File') . '</th>' .
'</tr>';
2021-11-01 21:32:32 +00:00
$table_line = '<tr class="line%s">' .
'<td class="nowrap minimal">%s</td>' .
'<td class="nowrap minimal">%s</td>' .
'<td>%s</td>' .
'<td class="nowrap translatertarget">%s</td>' .
'<td class="translatermsgstr">%s</td>' .
'<td class="nowrap translatermsgfile">%s</td>' .
'</tr>';
$table_ul = '<div class="subtranslater"><strong>%s</strong><div class="strlist">%s</div></div><br />';
$table_li = '<i>%s</i><br />';
2021-08-18 22:48:47 +00:00
$i = 1;
2021-11-01 21:32:32 +00:00
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);
2022-11-13 17:40:31 +00:00
$t_msgstr = $t_files = $strin = [];
2021-08-18 22:48:47 +00:00
2021-11-01 21:32:32 +00:00
foreach ($rs['o_msgstrs'] as $o_msgstr) {
if (!isset($strin[$o_msgstr['msgstr'][0]])) {
$strin[$o_msgstr['msgstr'][0]] = [];
2021-08-18 22:48:47 +00:00
}
$strin[$o_msgstr['msgstr'][0]][] = ['module' => $o_msgstr['module'], 'file' => $o_msgstr['file']];
}
2021-11-01 21:32:32 +00:00
foreach ($strin as $k => $v) {
$res = [];
2021-11-01 21:32:32 +00:00
foreach ($v as $str) {
$res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file']));
2021-08-18 22:48:47 +00:00
}
$t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res));
}
2021-08-18 22:48:47 +00:00
if (!empty($rs['files'][0])) {
if (count($rs['files']) == 1) {
$t_files[] = $rs['files'][0][0] . ':' . $rs['files'][0][1];
2021-08-18 22:48:47 +00:00
} else {
$res = [];
2021-11-01 21:32:32 +00:00
foreach ($rs['files'] as $location) {
$res[] = sprintf($table_li, implode(' : ', $location));
2021-08-18 22:48:47 +00:00
}
2021-11-01 21:32:32 +00:00
$t_files[] = sprintf($table_ul, sprintf(__('%s occurrences'), count($rs['files'])), implode('', $res));
;
2021-08-18 22:48:47 +00:00
}
}
2021-11-01 21:32:32 +00:00
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),
2021-11-01 21:32:32 +00:00
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)
);
2021-08-18 22:48:47 +00:00
if (!empty($rs['plural'])) {
$t_msgstr = $strin = [];
2021-11-01 21:32:32 +00:00
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]] = [];
}
2021-11-01 21:32:32 +00:00
$strin[$o_msgstr['msgstr'][$j + 1]][] = ['module' => $o_msgstr['module'], 'file' => $o_msgstr['file']];
}
}
2021-11-01 21:32:32 +00:00
foreach ($strin as $k => $v) {
$res = [];
2021-11-01 21:32:32 +00:00
foreach ($v as $str) {
$res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file']));
}
$t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res));
}
2021-08-18 22:48:47 +00:00
2021-11-01 21:32:32 +00:00
echo sprintf(
$table_line,
$in_dc ? ' offline' : ' translaterline',
'+',
2021-11-01 21:32:32 +00:00
sprintf(__('Plural "%s"'), $plural),
sprintf(__('Plural form of "%s"'), $rs['plural']),
form::hidden(['entries[' . $i . '][msgid_plural]'], html::escapeHTML($rs['plural'])) .
2022-11-13 17:40:31 +00:00
form::field(['entries[' . $i . '][msgstr][' . ($j + 1) . ']'], 48, 255, html::escapeHTML($rs['msgstr'][$j + 1] ?? ''), '', '', $in_dc),
implode('', $t_msgstr),
''
);
2021-08-18 22:48:47 +00:00
}
}
$i++;
}
2021-11-01 21:32:32 +00:00
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, ''),
'',
''
);
2021-11-01 21:32:32 +00:00
echo
'</table>' .
'<div class="two-cols">' .
'<div class="col left">' .
'<p class="checkboxes-helpers"></p>' .
'<p><label for="update_group">' .
form::checkbox('update_group', 1) .
2021-11-01 21:32:32 +00:00
__('Change the group of the selected translations to:') . ' ' .
form::combo('multigroup', $allowed_l10n_groups) . '</label></p>' .
'</div>' .
'<p class="col right">' .
'<input id="do-action" type="submit" value="' . __('Save') . ' (s)" accesskey="s" /></p>' .
2022-11-13 17:40:31 +00:00
dcCore::app()->formNonce() .
form::hidden(['code'], $lang->code) .
2022-11-13 17:40:31 +00:00
dcCore::app()->adminurl->getHiddenFormFields(
2022-12-26 20:48:51 +00:00
basename(__DIR__),
['type' => $module->type, 'module' => $module->id, 'lang' => $lang->code, 'action' => 'module_update_code']
2021-11-01 21:32:32 +00:00
) .
'</p></div>' .
2021-11-01 21:32:32 +00:00
'</form>' .
'<p>&nbsp;</p>' .
'</div>';
dcPage::helpBlock('translater.lang');
} else {
$line = '<li><a href="%s"%s>%s</a></li>';
2021-09-25 21:39:10 +00:00
echo '<h4><i>' . __('Translate your Dotclear plugins and themes') . '</i></h4>' .
sprintf(
2021-09-25 21:39:10 +00:00
'<h3><ul class="nice">%s</ul></h3>',
sprintf(
2021-11-01 21:32:32 +00:00
$line,
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->get(basename(__DIR__), ['type' => 'plugin']),
2021-09-25 21:39:10 +00:00
$type == 'plugin' ? ' class="active"' : '',
2021-11-01 21:32:32 +00:00
__('Translate plugins')
) .
2021-09-25 21:39:10 +00:00
sprintf(
2021-11-01 21:32:32 +00:00
$line,
2022-12-26 20:48:51 +00:00
dcCore::app()->adminurl->get(basename(__DIR__), ['type' => 'theme']),
2021-09-25 21:39:10 +00:00
$type == 'theme' ? ' class="active"' : '',
2021-11-01 21:32:32 +00:00
__('Translate themes')
)
2021-09-25 21:39:10 +00:00
);
2021-08-18 19:42:30 +00:00
dcPage::helpBlock('translater.index');
}
2021-08-18 19:42:30 +00:00
2021-11-01 21:32:32 +00:00
echo '</body></html>';