Skip to content
Snippets Groups Projects
Commit 3a60e043 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

Merge branch 'translations' into 'main'

fixes #21

See merge request studip/tools/TracToGitlabPlugin!3
parents a3228846 b33838be
No related branches found
No related tags found
1 merge request!3fixes #21
......@@ -111,6 +111,16 @@ final class TracToGitlabPlugin extends StudIPPlugin implements StandardPlugin, S
{
$navigation = new Navigation(_('Dashboard'), PluginEngine::getURL($this, [], 'dashboard'));
$navigation->setImage(Icon::create($this->getPluginURL() . '/assets/cardiogram.svg', Icon::ROLE_NAVIGATION));
$navigation->addSubnavigation(
'dashboard',
new Navigation(_('Dashboard'), PluginEngine::getURL($this, [], 'dashboard'))
);
$navigation->addSubnavigation(
'translations',
new Navigation(_('Übersetzungen'), PluginEngine::getURL($this, [], 'translations'))
);
Navigation::addItem('/gitlab-dashboard', $navigation);
}
}
......@@ -15,6 +15,7 @@ final class DashboardController extends TracToGitlab\Controller
{
parent::before_filter($action, $args);
Navigation::activateItem('/gitlab-dashboard/dashboard');
PageLayout::setTitle(_('Übersicht der Issues in gitlab'));
$this->setupSidebar();
......
<?php
final class TranslationsController extends \TracToGitlab\Controller
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
Navigation::activateItem('/gitlab-dashboard/translations');
PageLayout::setTitle(_('Status der Übersetzungen'));
}
public function index_action()
{
$temp = $this->fetch('resources', [
'filter' => [
'project' => 'o:' . Config::get()->TRAC2GITLAB_TRANSIFEX_ORGANISATION . ':p:' . Config::get()->TRAC2GITLAB_TRANSIFEX_PROJECT
]
]);
$resources = [];
foreach ($temp as $r) {
$resources[$r['id']] = $r['attributes']['name'];
}
$temp = $this->fetch('resource_language_stats', [
'filter' => [
'project' => 'o:' . Config::get()->TRAC2GITLAB_TRANSIFEX_ORGANISATION . ':p:' . Config::get()->TRAC2GITLAB_TRANSIFEX_PROJECT,
'language' => 'l:en',
]
]);
$stats = [];
foreach ($temp as $s) {
$id = preg_replace('/:l:.*$/', '', $s['id']);
$name = $resources[$id];
$stats[$name] = $s['attributes']['translated_strings'] / $s['attributes']['total_strings'];
}
$this->stats = array_reverse($stats);
}
private function fetch(...$args): array
{
$parameters = [];
if (is_array(end($args))) {
$parameters = array_pop($args);
}
$url = Config::get()->TRAC2GITLAB_TRANSIFEX_ENDPOINT . implode('/', $args);
if ($parameters) {
$url .= '?' . http_build_query($parameters);
}
$context = [
'http' => [
'method' => 'GET',
'header' => 'Authorization: Bearer ' . Config::get()->TRAC2GITLAB_TRANSIFEX_TOKEN . "\r\n",
]
];
$response = file_get_contents($url, false, stream_context_create($context));
if ($response === false) {
throw new Exception('Request failed');
}
$temp = $http_response_header[0];
if (!preg_match('/^HTTP.*?\s(\d+)\s/', $temp, $match)) {
throw new Exception('Could not parse http status');
}
$status = (int)$match[1];
if ($status !== 200) {
throw new Exception('Not implemented');
}
$data = json_decode($response, true);
if ($data === null) {
throw new Exception('Could not parse data');
}
return $data['data'];
}
}
......@@ -16,28 +16,28 @@ final class SetupPlugin extends Migration
)";
DBManager::get()->exec($query);
Config::get()->create('TRAC2GITLAB_TRAC_URL', [
$this->safelyCreateConfigEntry('TRAC2GITLAB_TRAC_URL', [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'URL zur Trac-Instanz',
]);
Config::get()->create('TRAC2GITLAB_GITLAB_URL', [
$this->safelyCreateConfigEntry('TRAC2GITLAB_GITLAB_URL', [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'URL zur gitlab-Instanz',
]);
Config::get()->create('TRAC2GITLAB_GITLAB_TOKEN', [
$this->safelyCreateConfigEntry('TRAC2GITLAB_GITLAB_TOKEN', [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'Token für die gitlab-Instanz',
]);
Config::get()->create('TRAC2GITLAB_GITLAB_PROJECT_ID', [
$this->safelyCreateConfigEntry('TRAC2GITLAB_GITLAB_PROJECT_ID', [
'value' => '',
'type' => 'integer',
'range' => 'global',
......@@ -56,4 +56,13 @@ final class SetupPlugin extends Migration
$query = "DROP TABLE IF EXISTS `trac_to_gitlab`";
DBManager::get()->exec($query);
}
private function safelyCreateConfigEntry(string $name, array $data)
{
try {
Config::get()->create($name, $data);
} catch (Exception $e) {
}
}
}
<?php
final class SetupTransifex extends Migration
{
public function up()
{
Config::get()->create('TRAC2GITLAB_TRANSIFEX_TOKEN', [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'Token für transifex',
]);
Config::get()->create('TRAC2GITLAB_TRANSIFEX_ENDPOINT', [
'value' => 'https://rest.api.transifex.com/',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'Endpunkt für transifex',
]);
Config::get()->create('TRAC2GITLAB_TRANSIFEX_ORGANISATION', [
'value' => 'studip',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'Organisation für transifex',
]);
Config::get()->create('TRAC2GITLAB_TRANSIFEX_PROJECT', [
'value' => 'studip',
'type' => 'string',
'range' => 'global',
'section' => 'Trac2Gitlab',
'description' => 'Project für transifex',
]);
}
public function down()
{
Config::get()->delete('TRAC2GITLAB_TRANSIFEX_TOKEN');
Config::get()->delete('TRAC2GITLAB_TRANSIFEX_ENDPOINT');
Config::get()->delete('TRAC2GITLAB_TRANSIFEX_ORGANISATION');
Config::get()->delete('TRAC2GITLAB_TRANSIFEX_PROJECT');
}
}
<table class="default">
<thead>
<tr>
<th><?= _('Version') ?></th>
<th><?= _('Status') ?></th>
</tr>
</thead>
<tbody>
<? foreach ($stats as $version => $status): ?>
<tr>
<td><?= htmlReady($version) ?></td>
<td><?= number_format($status * 100, 2, ',', '.') ?>%</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment