Fix the way HTTP_ACCEPT_LANGUAGE is parsed
[gitphp.git] / include / Resource.class.php
blob:a/include/Resource.class.php -> blob:b/include/Resource.class.php
--- a/include/Resource.class.php
+++ b/include/Resource.class.php
@@ -12,13 +12,20 @@
 require_once(GITPHP_BASEDIR . 'lib/php-gettext/streams.php');
 require_once(GITPHP_BASEDIR . 'lib/php-gettext/gettext.php');
 
+/**
+ * Constant of the locale cookie in the user's browser
+ */
 define('GITPHP_LOCALE_COOKIE', 'GitPHPLocale');
 
 /**
- * Resource
+ * Locale cookie lifetime
+ */
+define('GITPHP_LOCALE_COOKIE_LIFETIME', 60*60*24*365);		// 1 year
+
+/**
+ * Resource factory class
  *
  * @package GitPHP
- * @subpackage Resource
  */
 class GitPHP_Resource
 {
@@ -116,6 +123,10 @@
 				return 'English';
 			case 'fr_FR':
 				return 'Français';
+			case 'de_DE':
+				return 'Deutsch';
+			case 'ru_RU':
+				return 'Русский';
 			case 'zz_Debug':
 				return 'Gibberish';
 		}
@@ -242,3 +253,35 @@
 
 }
 
+
+/**
+ * Gettext wrapper function for readability, single string
+ *
+ * @param string $str string to translate
+ * @return string translated string
+ */
+function __($str)
+{
+	if (GitPHP_Resource::Instantiated())
+		return GitPHP_Resource::GetInstance()->translate($str);
+	return $str;
+}
+
+/**
+ * Gettext wrapper function for readability, plural form
+ *
+ * @param string $singular singular form of string
+ * @param string $plural plural form of string
+ * @param int $count number of items
+ * @return string translated string
+ */
+function __n($singular, $plural, $count)
+{
+	if (GitPHP_Resource::Instantiated())
+		return GitPHP_Resource::GetInstance()->ngettext($singular, $plural, $count);
+	if ($count > 1)
+		return $plural;
+	return $singular;
+}
+
+

comments