forked from tk-sls.de/linuxfoo-gitlab
improved German translation
This commit is contained in:
@ -3,9 +3,9 @@
|
||||
/*
|
||||
Plugin Name: Gitlab REST API Shortcodes
|
||||
Plugin URI: http://tk-sls.de/ref/gitlab-list-commits
|
||||
Description: <p>Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API.</p><p>Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since="3 month" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago.</p><p>The attributes "url" and "project_id" are mandatory.</p><p>The attributes "since" and "max" are optional (beware, the default is an unlimited list of commits).</p><p>Other optional attributes:</p><ul><li>ref_name=STRING: List only commit from branch or reference name STRING.</li><li>default_branch: If set, list only commits from the project's default branch.</li></ul>
|
||||
Description: Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API. Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since="3 month" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago.
|
||||
Author: Tilman Kranz
|
||||
Version: 1.1
|
||||
Version: 1.2
|
||||
Author URI: https://tk-sls.de
|
||||
*/
|
||||
|
||||
@ -13,8 +13,12 @@ class LinuxfooGitlab {
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
static function load_textdomain() {
|
||||
load_plugin_textdomain('linuxfoo-gitlab', false, dirname(plugin_basename(__FILE__)).'/lang');
|
||||
}
|
||||
|
||||
static function css() {
|
||||
wp_enqueue_style('linuxfoo_gitlab_css', plugins_url('styles.css', __FILE__ ), '', '1.1' );
|
||||
wp_enqueue_style('linuxfoo_gitlab_css', plugins_url('styles.css', __FILE__ ), '', '1.2' );
|
||||
}
|
||||
|
||||
static function error ( $msg ) {
|
||||
@ -26,6 +30,25 @@ class LinuxfooGitlab {
|
||||
'</div>';
|
||||
}
|
||||
|
||||
static function format_since($since) {
|
||||
preg_match('/^([0-9]+)\s+(.*)$/', $since, $m);
|
||||
$num = $m[1];
|
||||
$unit = $m[2];
|
||||
|
||||
if($unit=='days') {
|
||||
$unit = __('days', 'linuxfoo-gitlab');
|
||||
}
|
||||
elseif($unit=='months') {
|
||||
$unit = __('months', 'linuxfoo-gitlab');
|
||||
}
|
||||
elseif($unit=='years') {
|
||||
$unit = __('years', 'linuxfoo-gitlab');
|
||||
}
|
||||
|
||||
/* translators: %d: count, %s unit of time interval*/
|
||||
return sprintf(__('since %d %s ago', 'linuxfoo-gitlab'), $num, $unit);
|
||||
}
|
||||
|
||||
static function list_commits($atts, $content, $tag) {
|
||||
global $post;
|
||||
|
||||
@ -35,6 +58,15 @@ class LinuxfooGitlab {
|
||||
) {
|
||||
return self::error(__('Required parameter missing.', 'linuxfoo-gitlab'));
|
||||
}
|
||||
elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) {
|
||||
return self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitlab'));
|
||||
}
|
||||
elseif(!filter_var($atts['url'], FILTER_VALIDATE_URL)) {
|
||||
return self::error(__('Invalid value for parameter "url".', 'linuxfoo-gitlab'));
|
||||
}
|
||||
elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) {
|
||||
return self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitlab'));
|
||||
}
|
||||
|
||||
$project_url = $atts['url'].'/api/v4/projects/'.$atts['project_id'];
|
||||
$project_json = file_get_contents($project_url);
|
||||
@ -51,12 +83,16 @@ class LinuxfooGitlab {
|
||||
|
||||
$project_header =
|
||||
'<span class="project_header">'.
|
||||
'Gitlab project'.' <a href="'.$project->web_url.'">'.$project->name.'</a>'.
|
||||
__('Gitlab project', 'linuxfoo-gitlab').' <a href="'.$project->web_url.'">'.$project->name.'</a>'.
|
||||
'</span>';
|
||||
|
||||
$commits_url = $project_url.'/repository/commits?';
|
||||
|
||||
if(!is_null($atts['since'])) {
|
||||
if(!preg_match('/^[1-9][0-9]*\s+(days|months|years)$/', $atts['since'])) {
|
||||
return self::error(__('Invalid value for parameter "since".', 'linuxfoo-gitlab'));
|
||||
}
|
||||
|
||||
$since = date(DATE_ISO8601, strtotime('-'.$atts['since']));
|
||||
$commits_url .= '&since='.$since;
|
||||
}
|
||||
@ -95,7 +131,7 @@ class LinuxfooGitlab {
|
||||
'<span class="stats">'.
|
||||
__('No commits', 'linuxfoo-gitlab').
|
||||
(is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitlab').' "'.$branch.'"').
|
||||
(is_null($atts['since']) ? '' : ' since '.$atts['since'].' ago').'.'.
|
||||
(is_null($atts['since']) ? '' : ' '.('since '.$atts['since'].' ago')).'.'.
|
||||
'</span>'.
|
||||
'</div>';
|
||||
}
|
||||
@ -106,9 +142,10 @@ class LinuxfooGitlab {
|
||||
'<div class="linuxfoo_gitlab">'.
|
||||
$project_header.
|
||||
'<span class="stats">'.
|
||||
/* translators: %d: maximum number of commits displayed */
|
||||
sprintf(__('Last %d commits', 'linuxfoo-gitlab'), $commits_count).
|
||||
(is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitlab').' "'.$branch.'"').
|
||||
(is_null($atts['since']) ? '' : ' since '.$atts['since'].' ago').':'.
|
||||
(is_null($atts['since']) ? '' : ' '.self::format_since($atts['since'])).':'.
|
||||
'</span>'.
|
||||
'<ul class="commits">';
|
||||
|
||||
@ -130,10 +167,6 @@ class LinuxfooGitlab {
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
static function load_textdomain() {
|
||||
load_plugin_textdomain('linuxfoo-gitlab', false, dirname(plugin_basename(__FILE__)).'/lang');
|
||||
}
|
||||
}
|
||||
|
||||
add_action('plugins_loaded', 'LinuxfooGitlab::load_textdomain');
|
||||
|
Reference in New Issue
Block a user