Use translation wrapper functions
Use translation wrapper functions

--- a/include/controller/ControllerBase.class.php
+++ b/include/controller/ControllerBase.class.php
@@ -81,7 +81,7 @@
 		if (isset($_GET['p'])) {
 			$this->project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
 			if (!$this->project) {
-				throw new GitPHP_MessageException(sprintf(GitPHP_Resource::GetInstance()->translate('Invalid project %1$s'), $_GET['p']), true);
+				throw new GitPHP_MessageException(sprintf(__('Invalid project %1$s'), $_GET['p']), true);
 			}
 		}
 
@@ -237,7 +237,7 @@
 		$this->tpl->assign('stylesheet', GitPHP_Config::GetInstance()->GetValue('stylesheet', 'gitphp.css'));
 		$this->tpl->assign('javascript', GitPHP_Config::GetInstance()->GetValue('javascript', true));
 		$this->tpl->assign('pagetitle', GitPHP_Config::GetInstance()->GetValue('title', $gitphp_appstring));
-		$this->tpl->assign('homelink', GitPHP_Config::GetInstance()->GetValue('homelink', GitPHP_Resource::GetInstance()->translate('projects')));
+		$this->tpl->assign('homelink', GitPHP_Config::GetInstance()->GetValue('homelink', __('projects')));
 		$this->tpl->assign('action', $this->GetName());
 		$this->tpl->assign('actionlocal', $this->GetName(true));
 		if ($this->project)

--- a/include/controller/Controller_Blame.class.php
+++ b/include/controller/Controller_Blame.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -76,7 +76,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('blame');
+			return __('blame');
 		}
 		return 'blame';
 	}

--- a/include/controller/Controller_Blob.class.php
+++ b/include/controller/Controller_Blob.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -75,7 +75,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('blob');
+			return __('blob');
 		}
 		return 'blob';
 	}

--- a/include/controller/Controller_Blobdiff.class.php
+++ b/include/controller/Controller_Blobdiff.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -76,7 +76,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('blobdiff');
+			return __('blobdiff');
 		}
 		return 'blobdiff';
 	}

--- a/include/controller/Controller_Commit.class.php
+++ b/include/controller/Controller_Commit.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -76,7 +76,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('commit');
+			return __('commit');
 		}
 		return 'commit';
 	}

--- a/include/controller/Controller_Commitdiff.class.php
+++ b/include/controller/Controller_Commitdiff.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -76,7 +76,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('commitdiff');
+			return __('commitdiff');
 		}
 		return 'commitdiff';
 	}

--- a/include/controller/Controller_Heads.class.php
+++ b/include/controller/Controller_Heads.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -73,7 +73,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('heads');
+			return __('heads');
 		}
 		return 'heads';
 	}

--- a/include/controller/Controller_History.class.php
+++ b/include/controller/Controller_History.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -73,7 +73,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('history');
+			return __('history');
 		}
 		return 'history';
 	}

--- a/include/controller/Controller_Log.class.php
+++ b/include/controller/Controller_Log.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -77,12 +77,12 @@
 	{
 		if (isset($this->params['short']) && ($this->params['short'] === true)) {
 			if ($local) {
-				return GitPHP_Resource::GetInstance()->translate('shortlog');
+				return __('shortlog');
 			}
 			return 'shortlog';
 		}
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('log');
+			return __('log');
 		}
 		return 'log';
 	}

--- a/include/controller/Controller_Project.class.php
+++ b/include/controller/Controller_Project.class.php
@@ -30,7 +30,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -72,7 +72,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('summary');
+			return __('summary');
 		}
 		return 'summary';
 	}

--- a/include/controller/Controller_ProjectList.class.php
+++ b/include/controller/Controller_ProjectList.class.php
@@ -81,17 +81,17 @@
 	{
 		if (isset($this->params['opml']) && ($this->params['opml'] === true)) {
 			if ($local) {
-				return GitPHP_Resource::GetInstance()->translate('opml');
+				return __('opml');
 			}
 			return 'opml';
 		} else if (isset($this->params['txt']) && ($this->params['txt'] === true)) {
 			if ($local) {
-				return GitPHP_Resource::GetInstance()->translate('project index');
+				return __('project index');
 			}
 			return 'project index';
 		}
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('projects');
+			return __('projects');
 		}
 		return 'projects';
 	}

--- a/include/controller/Controller_Rss.class.php
+++ b/include/controller/Controller_Rss.class.php
@@ -32,7 +32,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -74,7 +74,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('rss');
+			return __('rss');
 		}
 		return 'rss';
 	}

--- a/include/controller/Controller_Search.class.php
+++ b/include/controller/Controller_Search.class.php
@@ -35,13 +35,13 @@
 	public function __construct()
 	{
 		if (!GitPHP_Config::GetInstance()->GetValue('search', true)) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Search has been disabled'), true);
+			throw new GitPHP_MessageException(__('Search has been disabled'), true);
 		}
 
 		parent::__construct();
 
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 
 	}
@@ -87,7 +87,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('search');
+			return __('search');
 		}
 		return 'search';
 	}
@@ -106,13 +106,13 @@
 
 		if ($this->params['searchtype'] == GITPHP_SEARCH_FILE) {
 			if (!GitPHP_Config::GetInstance()->GetValue('filesearch', true)) {
-				throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('File search has been disabled'), true);
+				throw new GitPHP_MessageException(__('File search has been disabled'), true);
 			}
 
 		}
 
 		if ((!isset($this->params['search'])) || (strlen($this->params['search']) < 2)) {
-			throw new GitPHP_MessageException(sprintf(GitPHP_Resource::GetInstance()->ngettext('You must enter search text of at least %1$d character', 'You must enter search text of at least %1$d characters', 2), 2), true);
+			throw new GitPHP_MessageException(sprintf(__n('You must enter search text of at least %1$d character', 'You must enter search text of at least %1$d characters', 2), 2), true);
 		}
 
 		if (isset($_GET['h']))
@@ -156,13 +156,13 @@
 					$results = $co->SearchFiles($this->params['search'], 101, ($this->params['page'] * 100));
 					break;
 				default:
-					throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Invalid search type'));
+					throw new GitPHP_MessageException(__('Invalid search type'));
 
 			}
 		}
 
 		if (count($results) < 1) {
-			throw new GitPHP_MessageException(sprintf(GitPHP_Resource::GetInstance()->translate('No matches for "%1$s"'), $this->params['search']), false);
+			throw new GitPHP_MessageException(sprintf(__('No matches for "%1$s"'), $this->params['search']), false);
 		}
 
 		if (count($results) > 100) {

--- a/include/controller/Controller_Snapshot.class.php
+++ b/include/controller/Controller_Snapshot.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -73,7 +73,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('snapshot');
+			return __('snapshot');
 		}
 		return 'snapshot';
 	}

--- a/include/controller/Controller_Tag.class.php
+++ b/include/controller/Controller_Tag.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -76,7 +76,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('tag');
+			return __('tag');
 		}
 		return 'tag';
 	}

--- a/include/controller/Controller_Tags.class.php
+++ b/include/controller/Controller_Tags.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -73,7 +73,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('tags');
+			return __('tags');
 		}
 		return 'tags';
 	}

--- a/include/controller/Controller_Tree.class.php
+++ b/include/controller/Controller_Tree.class.php
@@ -31,7 +31,7 @@
 	{
 		parent::__construct();
 		if (!$this->project) {
-			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+			throw new GitPHP_MessageException(__('Project is required'), true);
 		}
 	}
 
@@ -73,7 +73,7 @@
 	public function GetName($local = false)
 	{
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('tree');
+			return __('tree');
 		}
 		return 'tree';
 	}

--- a/include/git/Blob.class.php
+++ b/include/git/Blob.class.php
@@ -176,26 +176,26 @@
 		$mode = octdec($octMode);
 		if (($mode & 0x4000) == 0x4000) {
 			if ($local) {
-				return GitPHP_Resource::GetInstance()->translate('directory');
+				return __('directory');
 			} else {
 				return 'directory';
 			}
 		} else if (($mode & 0xA000) == 0xA000) {
 			if ($local) {
-				return GitPHP_Resource::GetInstance()->translate('symlink');
+				return __('symlink');
 			} else {
 				return 'symlink';
 			}
 		} else if (($mode & 0x8000) == 0x8000) {
 			if ($local) {
-				return GitPHP_Resource::GetInstance()->translate('file');
+				return __('file');
 			} else {
 				return 'file';
 			}
 		}
 
 		if ($local) {
-			return GitPHP_Resource::GetInstance()->translate('unknown');
+			return __('unknown');
 		} else {
 			return 'unknown';
 		}

--- a/include/git/FileDiff.class.php
+++ b/include/git/FileDiff.class.php
@@ -613,19 +613,19 @@
 		$tmpdir = GitPHP_Config::GetInstance()->GetValue('gittmp', '/tmp/gitphp/');
 
 		if (empty($tmpdir)) {
-			throw new Exception(GitPHP_Resource::GetInstance()->translate('No tmpdir defined'));
+			throw new Exception(__('No tmpdir defined'));
 		}
 
 		if (file_exists($tmpdir)) {
 			if (is_dir($tmpdir)) {
 				if (!is_writeable($tmpdir)) {
-					throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('Specified tmpdir %1$s is not writable'), $tmpdir));
+					throw new Exception(sprintf(__('Specified tmpdir %1$s is not writable'), $tmpdir));
 				}
 			} else {
-				throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('Specified tmpdir %1$s is not a directory'), $tmpdir));
+				throw new Exception(sprintf(__('Specified tmpdir %1$s is not a directory'), $tmpdir));
 			}
 		} else if (!mkdir($tmpdir, 0700)) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('Could not create tmpdir %1$s'), $tmpdir));
+			throw new Exception(sprintf(__('Could not create tmpdir %1$s'), $tmpdir));
 		}
 	}
 

--- a/include/git/GitObject.class.php
+++ b/include/git/GitObject.class.php
@@ -92,7 +92,7 @@
 	protected function SetHash($hash)
 	{
 		if (!(preg_match('/[0-9a-f]{40}/i', $hash))) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('Invalid hash %1$s'), $hash));
+			throw new Exception(sprintf(__('Invalid hash %1$s'), $hash));
 		}
 		$this->hash = $hash;
 	}

--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -209,21 +209,21 @@
 		$fullPath = realpath($path);
 
 		if (!is_dir($fullPath)) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('%1$s is not a directory'), $project));
+			throw new Exception(sprintf(__('%1$s is not a directory'), $project));
 		}
 
 		if (!is_file($fullPath . '/HEAD')) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('%1$s is not a git repository'), $project));
+			throw new Exception(sprintf(__('%1$s is not a git repository'), $project));
 		}
 
 		if (preg_match('/(^|\/)\.{0,2}(\/|$)/', $project)) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('%1$s is attempting directory traversal'), $project));
+			throw new Exception(sprintf(__('%1$s is attempting directory traversal'), $project));
 		}
 
 		$pathPiece = substr($fullPath, 0, strlen($realProjectRoot));
 
 		if ((!is_link($path)) && (strcmp($pathPiece, $realProjectRoot) !== 0)) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('%1$s is outside of the projectroot'), $project));
+			throw new Exception(sprintf(__('%1$s is outside of the projectroot'), $project));
 		}
 
 		$this->project = $project;

--- a/include/git/ProjectListDirectory.class.php
+++ b/include/git/ProjectListDirectory.class.php
@@ -44,7 +44,7 @@
 	public function __construct($projectDir)
 	{
 		if (!is_dir($projectDir)) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('%1$s is not a directory'), $projectDir));
+			throw new Exception(sprintf(__('%1$s is not a directory'), $projectDir));
 		}
 
 		$this->projectDir = $projectDir;

--- a/include/git/ProjectListFile.class.php
+++ b/include/git/ProjectListFile.class.php
@@ -35,7 +35,7 @@
 	public function __construct($projectFile)
 	{
 		if (!(is_string($projectFile) && is_file($projectFile))) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('%1$s is not a file'), $projectFile));
+			throw new Exception(sprintf(__('%1$s is not a file'), $projectFile));
 		}
 
 		$this->projectConfig = $projectFile;
@@ -54,7 +54,7 @@
 	protected function PopulateProjects()
 	{
 		if (!($fp = fopen($this->projectConfig, 'r'))) {
-			throw new Exception(sprintf(GitPHP_Resource::GetInstance()->translate('Failed to open project list file %1$s'), $this->projectConfig));
+			throw new Exception(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig));
 		}
 
 		$projectRoot = GitPHP_Config::GetInstance()->GetValue('projectroot');

--- a/include/smartyplugins/block.t.php
+++ b/include/smartyplugins/block.t.php
@@ -94,9 +94,9 @@
 	
 	// use plural if required parameters are set
 	if (isset($count) && isset($plural)) {
-		$text = GitPHP_Resource::GetInstance()->ngettext($text, $plural, $count);
+		$text = __n($text, $plural, $count);
 	} else { // use normal
-		$text = GitPHP_Resource::GetInstance()->translate($text);
+		$text = __($text);
 	}
 
 	// run strarg if there are parameters

--- a/include/smartyplugins/modifier.agestring.php
+++ b/include/smartyplugins/modifier.agestring.php
@@ -9,46 +9,44 @@
 
 function smarty_modifier_agestring($age)
 {
-	$resource = GitPHP_Resource::GetInstance();
-
 	if ($age > 60*60*24*365*2) {
 
 		$years = (int)($age/60/60/24/365);
-		return sprintf($resource->ngettext('%1$d year ago', '%1$d years ago', $years), $years);
+		return sprintf(__n('%1$d year ago', '%1$d years ago', $years), $years);
 
 	} else if ($age > 60*60*24*(365/12)*2) {
 
 		$months = (int)($age/60/60/24/(365/12));
-		return sprintf($resource->ngettext('%1$d month ago', '%1$d months ago', $months), $months);
+		return sprintf(__n('%1$d month ago', '%1$d months ago', $months), $months);
 
 	} else if ($age > 60*60*24*7*2) {
 
 		$weeks = (int)($age/60/60/24/7);
-		return sprintf($resource->ngettext('%1$d week ago', '%1$d weeks ago', $weeks), $weeks);
+		return sprintf(__n('%1$d week ago', '%1$d weeks ago', $weeks), $weeks);
 
 	} else if ($age > 60*60*24*2) {
 
 		$days = (int)($age/60/60/24);
-		return sprintf($resource->ngettext('%1$d day ago', '%1$d days ago', $days), $days);
+		return sprintf(__n('%1$d day ago', '%1$d days ago', $days), $days);
 
 	} else if ($age > 60*60*2) {
 
 		$hours = (int)($age/60/60);
-		return sprintf($resource->ngettext('%1$d hour ago', '%1$d hours ago', $hours), $hours);
+		return sprintf(__n('%1$d hour ago', '%1$d hours ago', $hours), $hours);
 
 	} else if ($age > 60*2) {
 
 		$min = (int)($age/60);
-		return sprintf($resource->ngettext('%1$d min ago', '%1$d min ago', $min), $min);
+		return sprintf(__n('%1$d min ago', '%1$d min ago', $min), $min);
 
 	} else if ($age > 2) {
 
 		$sec = (int)$age;
-		return sprintf($resource->ngettext('%1$d sec ago', '%1$d sec ago', $sec), $sec);
+		return sprintf(__n('%1$d sec ago', '%1$d sec ago', $sec), $sec);
 
 	}
 
-	return $resource->translate('right now');
+	return __('right now');
 }
 
 ?>

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -110,7 +110,7 @@
 	}
 
 	if (!GitPHP_Config::GetInstance()->GetValue('projectroot', null)) {
-		throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('A projectroot must be set in the config'), true);
+		throw new GitPHP_MessageException(__('A projectroot must be set in the config'), true);
 	}
 
 	/*

comments