diff options
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/acctfuncs.inc.php | 124 | ||||
-rw-r--r-- | web/lib/aur.inc.php | 11 | ||||
-rw-r--r-- | web/lib/gettext.php | 432 | ||||
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 86 | ||||
-rw-r--r-- | web/lib/translator.inc.php | 50 |
5 files changed, 111 insertions, 592 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index b2f0548e..3bdd8d0c 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -39,34 +39,34 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="", print "<tr><td colspan='2'> </td></tr>\n"; print "<tr>"; - print "<td align='left'>".__("Username").":</td>"; + print "<td align='left'>"._("Username").":</td>"; print "<td align='left'><input type='text' size='30' maxlength='64'"; - print " name='U' value='".htmlspecialchars($U,ENT_QUOTES)."' /> (".__("required").")</td>"; + print " name='U' value='".htmlspecialchars($U,ENT_QUOTES)."' /> ("._("required").")</td>"; print "</tr>\n"; # Only TUs or Devs can promote/demote/suspend a user if ($UTYPE == "Trusted User" || $UTYPE == "Developer") { print "<tr>"; - print "<td align='left'>".__("Account Type").":</td>"; + print "<td align='left'>"._("Account Type").":</td>"; print "<td align='left'><select name=T>\n"; print "<option value='1'"; $T == "User" ? print " selected>" : print ">"; - print __("Normal user")."\n"; + print _("Normal user")."\n"; print "<option value='2'"; $T == "Trusted User" ? print " selected>" : print ">"; - print __("Trusted user")."\n"; + print _("Trusted user")."\n"; # Only developers can make another account a developer if ($UTYPE == "Developer") { print "<option value='3'"; $T == "Developer" ? print " selected>" : print ">"; - print __("Developer")."\n"; + print _("Developer")."\n"; } print "</select></td>"; print "</tr>\n"; print "<tr>"; - print "<td align='left'>".__("Account Suspended").":</td>"; + print "<td align='left'>"._("Account Suspended").":</td>"; print "<td align='left'><input type='checkbox' name='S'"; if ($S) { print " checked=\"checked\" />"; @@ -77,43 +77,43 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="", } print "<tr>"; - print "<td align='left'>".__("Email Address").":</td>"; + print "<td align='left'>"._("Email Address").":</td>"; print "<td align='left'><input type='text' size='30' maxlength='64'"; - print " name='E' value='".htmlspecialchars($E,ENT_QUOTES)."' /> (".__("required").")</td>"; + print " name='E' value='".htmlspecialchars($E,ENT_QUOTES)."' /> ("._("required").")</td>"; print "</tr>\n"; print "<tr>"; - print "<td align='left'>".__("Password").":</td>"; + print "<td align='left'>"._("Password").":</td>"; print "<td align='left'><input type='password' size='30' maxlength='32'"; print " name='P' value='".$P."' />"; if ($A != "UpdateAccount") { - print " (".__("required").")"; + print " ("._("required").")"; } print "</td></tr>\n"; print "<tr>"; - print "<td align='left'>".__("Re-type password").":</td>"; + print "<td align='left'>"._("Re-type password").":</td>"; print "<td align='left'><input type='password' size='30' maxlength='32'"; print " name='C' value='".$C."' />"; if ($A != "UpdateAccount") { - print " (".__("required").")"; + print " ("._("required").")"; } print "</td></tr>\n"; print "<tr>"; - print "<td align='left'>".__("Real Name").":</td>"; + print "<td align='left'>"._("Real Name").":</td>"; print "<td align='left'><input type='text' size='30' maxlength='32'"; print " name='R' value='".htmlspecialchars($R,ENT_QUOTES)."' /></td>"; print "</tr>\n"; print "<tr>"; - print "<td align='left'>".__("IRC Nick").":</td>"; + print "<td align='left'>"._("IRC Nick").":</td>"; print "<td align='left'><input type='text' size='30' maxlength='32'"; print " name='I' value='".htmlspecialchars($I,ENT_QUOTES)."' /></td>"; print "</tr>\n"; print "<tr>"; - print "<td align='left'>".__("Language").":</td>"; + print "<td align='left'>"._("Language").":</td>"; print "<td align='left'><select name=L>\n"; reset($SUPPORTED_LANGS); @@ -134,12 +134,12 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="", if ($A == "UpdateAccount") { print "<input type='submit' class='button'"; - print " value='".__("Update")."' /> "; + print " value='"._("Update")."' /> "; } else { print "<input type='submit' class='button'"; - print " value='".__("Create")."' /> "; + print " value='"._("Create")."' /> "; } - print "<input type='reset' class='button' value='".__("Reset")."' />"; + print "<input type='reset' class='button' value='"._("Reset")."' />"; print "</td>"; print "</tr>\n"; @@ -181,44 +181,44 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", $dbh = db_connect(); $error = ""; if (empty($E) || empty($U)) { - $error = __("Missing a required field."); + $error = _("Missing a required field."); } if ($TYPE == "new") { # they need password fields for this type of action # if (empty($P) || empty($C)) { - $error = __("Missing a required field."); + $error = _("Missing a required field."); } } else { if (!$UID) { - $error = __("Missing User ID"); + $error = _("Missing User ID"); } } if (!$error && !valid_username($U) && !user_is_privileged($editor_user)) - $error = __("The username is invalid.") . "<ul>\n" - ."<li>" . __("It must be between %s and %s characters long", + $error = _("The username is invalid.") . "<ul>\n" + ."<li>" . _("It must be between %s and %s characters long", USERNAME_MIN_LEN, USERNAME_MAX_LEN ) . "</li>" - . "<li>" . __("Start and end with a letter or number") . "</li>" - . "<li>" . __("Can contain only one period, underscore or hyphen.") + . "<li>" . _("Start and end with a letter or number") . "</li>" + . "<li>" . _("Can contain only one period, underscore or hyphen.") . "</li>\n</ul>"; if (!$error && $P && $C && ($P != $C)) { - $error = __("Password fields do not match."); + $error = _("Password fields do not match."); } if (!$error && $P != '' && !good_passwd($P)) - $error = __("Your password must be at least %s characters.",PASSWD_MIN_LEN); + $error = _("Your password must be at least %s characters.",PASSWD_MIN_LEN); if (!$error && !valid_email($E)) { - $error = __("The email address is invalid."); + $error = _("The email address is invalid."); } if ($UTYPE == "Trusted User" && $T == 3) { - $error = __("A Trusted User cannot assign Developer status."); + $error = _("A Trusted User cannot assign Developer status."); } if (!$error && !array_key_exists($L, $SUPPORTED_LANGS)) { - $error = __("Language is not currently supported."); + $error = _("Language is not currently supported."); } if (!$error) { # check to see if this username is available @@ -233,7 +233,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", if ($result) { $row = mysql_fetch_array($result); if ($row[0]) { - $error = __("The username, %h%s%h, is already in use.", + $error = _("The username, %h%s%h, is already in use.", "<b>", htmlspecialchars($U,ENT_QUOTES), "</b>"); } } @@ -251,7 +251,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", if ($result) { $row = mysql_fetch_array($result); if ($row[0]) { - $error = __("The address, %h%s%h, is already in use.", + $error = _("The address, %h%s%h, is already in use.", "<b>", htmlspecialchars($E,ENT_QUOTES), "</b>"); } } @@ -273,15 +273,15 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", "VALUES (1, 0, '" . implode("', '", $escaped) . "')"; $result = db_query($q, $dbh); if (!$result) { - print __("Error trying to create account, %h%s%h: %s.", + print _("Error trying to create account, %h%s%h: %s.", "<b>", htmlspecialchars($U,ENT_QUOTES), "</b>", mysql_error($dbh)); } else { # account created/modified, tell them so. # - print __("The account, %h%s%h, has been successfully created.", + print _("The account, %h%s%h, has been successfully created.", "<b>", htmlspecialchars($U,ENT_QUOTES), "</b>"); print "<p>\n"; - print __("Click on the Home link above to login."); + print _("Click on the Home link above to login."); print "</p>\n"; } @@ -310,10 +310,10 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", $q.= " WHERE ID = ".intval($UID); $result = db_query($q, $dbh); if (!$result) { - print __("Error trying to modify account, %h%s%h: %s.", + print _("Error trying to modify account, %h%s%h: %s.", "<b>", htmlspecialchars($U,ENT_QUOTES), "</b>", mysql_error($dbh)); } else { - print __("The account, %h%s%h, has been successfully modified.", + print _("The account, %h%s%h, has been successfully modified.", "<b>", htmlspecialchars($U,ENT_QUOTES), "</b>"); } } @@ -411,7 +411,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", $result = db_query($q, $dbh); if (!$result) { - print __("No results matched your search criteria."); + print _("No results matched your search criteria."); } else { $num_rows = mysql_num_rows($result); if ($num_rows) { @@ -424,19 +424,19 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print " cellspacing='0' width='100%'>\n"; print "<tr>"; print "<th class='header'>"; - print "<span class='f2'>".__("Username")."</span></th>"; + print "<span class='f2'>"._("Username")."</span></th>"; print "<th class='header'>"; - print "<span class='f2'>".__("Type")."</span></th>"; + print "<span class='f2'>"._("Type")."</span></th>"; print "<th class='header'>"; - print "<span class='f2'>".__("Status")."</span></th>"; + print "<span class='f2'>"._("Status")."</span></th>"; print "<th class='header'>"; - print "<span class='f2'>".__("Real Name")."</span></th>"; + print "<span class='f2'>"._("Real Name")."</span></th>"; print "<th class='header'>"; - print "<span class='f2'>".__("IRC Nick")."</span></th>"; + print "<span class='f2'>"._("IRC Nick")."</span></th>"; print "<th class='header'>"; - print "<span class='f2'>".__("Last Voted")."</span></th>"; + print "<span class='f2'>"._("Last Voted")."</span></th>"; print "<th class='header'>"; - print "<span class='f2'>".__("Edit Account")."</span></th>"; + print "<span class='f2'>"._("Edit Account")."</span></th>"; print "</tr>\n"; $i = 0; while ($row = mysql_fetch_assoc($result)) { @@ -453,9 +453,9 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print "</span></td>"; print "<td class='".$c."'><span class='f5'>"; if ($row["Suspended"]) { - print __("Suspended"); + print _("Suspended"); } else { - print __("Active"); + print _("Active"); } print "</span></td>"; print "<td class='".$c."'><span class='f5'>"; @@ -467,7 +467,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print "<td class='".$c."'><span class='f5'>"; $row["LastVoted"] ? print date("Ymd", $row["LastVoted"]) - : print __("Never"); + : print _("Never"); print "</span></td>"; print "<td class='".$c."'><span class='f5'>"; if ($UTYPE == "Trusted User" && $row["AccountType"] == "Developer") { @@ -498,7 +498,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print " value='".${$ind}."' />\n"; } print "<input type='submit' class='button'"; - print " value='<-- ".__("Less")."' />"; + print " value='<-- "._("Less")."' />"; print "</fieldset>"; print "</form>\n"; print "</td>"; @@ -514,7 +514,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print " value='".${$ind}."' />\n"; } print "<input type='submit' class='button'"; - print " value='".__("More")." -->' />"; + print " value='"._("More")." -->' />"; print "</fieldset>"; print "</form>\n"; print "</td>"; @@ -522,7 +522,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print "</table>\n"; } else { print "<p style=\"text-align:center;\">\n"; - print __("No more results to display."); + print _("No more results to display."); print "</p>\n"; } } @@ -546,40 +546,40 @@ function display_account_info($U="", $T="", $E="", $R="", $I="") { print " </tr>\n"; print " <tr>\n"; - print " <td align='left'>".__("Username").":</td>\n"; + print " <td align='left'>"._("Username").":</td>\n"; print " <td align='left'>".$U."</td>\n"; print " </tr>\n"; print " <tr>\n"; - print " <td align='left'>".__("Account Type").":</td>\n"; + print " <td align='left'>"._("Account Type").":</td>\n"; print " <td align='left'>"; if ($T == "User") { - print __("User"); + print _("User"); } elseif ($T == "Trusted User") { - print __("Trusted User"); + print _("Trusted User"); } elseif ($T == "Developer") { - print __("Developer"); + print _("Developer"); } print " </td>\n"; print " </tr>\n"; print " <tr>\n"; - print " <td align='left'>".__("Email Address").":</td>\n"; + print " <td align='left'>"._("Email Address").":</td>\n"; print " <td align='left'><a href='mailto:".htmlspecialchars($E,ENT_QUOTES)."'>".htmlspecialchars($E,ENT_QUOTES)."</a></td>\n"; print " </tr>\n"; print " <tr>\n"; - print " <td align='left'>".__("Real Name").":</td>\n"; + print " <td align='left'>"._("Real Name").":</td>\n"; print " <td align='left'>".htmlspecialchars($R,ENT_QUOTES)."</td>\n"; print " </tr>\n"; print " <tr>\n"; - print " <td align='left'>".__("IRC Nick").":</td>\n"; + print " <td align='left'>"._("IRC Nick").":</td>\n"; print " <td align='left'>".htmlspecialchars($I,ENT_QUOTES)."</td>\n"; print " </tr>\n"; print " <tr>\n"; - print " <td colspan='2'><a href='packages.php?K=".$U."&SeB=m'>".__("View this user's packages")."</a></td>\n"; + print " <td colspan='2'><a href='packages.php?K=".$U."&SeB=m'>"._("View this user's packages")."</a></td>\n"; print " </tr>\n"; print "</table>\n"; @@ -668,7 +668,7 @@ function try_login() { } } else { - $login_error = __("Bad username or password."); + $login_error = _("Bad username or password."); } } return array('SID' => $new_sid, 'error' => $login_error); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 382578c0..8b5787bd 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -7,10 +7,10 @@ header('Pragma: no-cache'); date_default_timezone_set('UTC'); -include_once('translator.inc.php'); +include_once("config.inc.php"); + set_lang(); -include_once("config.inc.php"); include_once("version.inc.php"); include_once("acctfuncs.inc.php"); include_once("cachefuncs.inc.php"); @@ -295,9 +295,10 @@ function set_lang() { setcookie("AURLANG", $LANG, $cookie_time, "/"); } - $streamer = new FileReader('../locale/' . $LANG . - '/LC_MESSAGES/aur.mo'); - $l10n = new gettext_reader($streamer, true); + var_dump(setlocale(LC_MESSAGES, $LANG.".UTF-8")); + bindtextdomain("aur", '../locale'); + textdomain("aur"); + bind_textdomain_codeset("aur", 'UTF-8'); return; } diff --git a/web/lib/gettext.php b/web/lib/gettext.php deleted file mode 100644 index 5064047c..00000000 --- a/web/lib/gettext.php +++ /dev/null @@ -1,432 +0,0 @@ -<?php -/* - Copyright (c) 2003, 2009 Danilo Segan <danilo@kvota.net>. - Copyright (c) 2005 Nico Kaiser <nico@siriux.net> - - This file is part of PHP-gettext. - - PHP-gettext is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - PHP-gettext is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with PHP-gettext; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -/** - * Provides a simple gettext replacement that works independently from - * the system's gettext abilities. - * It can read MO files and use them for translating strings. - * The files are passed to gettext_reader as a Stream (see streams.php) - * - * This version has the ability to cache all strings and translations to - * speed up the string lookup. - * While the cache is enabled by default, it can be switched off with the - * second parameter in the constructor (e.g. whenusing very large MO files - * that you don't want to keep in memory) - */ -class gettext_reader { - //public: - var $error = 0; // public variable that holds error code (0 if no error) - - //private: - var $BYTEORDER = 0; // 0: low endian, 1: big endian - var $STREAM = NULL; - var $short_circuit = false; - var $enable_cache = false; - var $originals = NULL; // offset of original table - var $translations = NULL; // offset of translation table - var $pluralheader = NULL; // cache header field for plural forms - var $total = 0; // total string count - var $table_originals = NULL; // table for original strings (offsets) - var $table_translations = NULL; // table for translated strings (offsets) - var $cache_translations = NULL; // original -> translation mapping - - - /* Methods */ - - - /** - * Reads a 32bit Integer from the Stream - * - * @access private - * @return Integer from the Stream - */ - function readint() { - if ($this->BYTEORDER == 0) { - // low endian - $input=unpack('V', $this->STREAM->read(4)); - return array_shift($input); - } else { - // big endian - $input=unpack('N', $this->STREAM->read(4)); - return array_shift($input); - } - } - - function read($bytes) { - return $this->STREAM->read($bytes); - } - - /** - * Reads an array of Integers from the Stream - * - * @param int count How many elements should be read - * @return Array of Integers - */ - function readintarray($count) { - if ($this->BYTEORDER == 0) { - // low endian - return unpack('V'.$count, $this->STREAM->read(4 * $count)); - } else { - // big endian - return unpack('N'.$count, $this->STREAM->read(4 * $count)); - } - } - - /** - * Constructor - * - * @param object Reader the StreamReader object - * @param boolean enable_cache Enable or disable caching of strings (default on) - */ - function gettext_reader($Reader, $enable_cache = true) { - // If there isn't a StreamReader, turn on short circuit mode. - if (! $Reader || isset($Reader->error) ) { - $this->short_circuit = true; - return; - } - - // Caching can be turned off - $this->enable_cache = $enable_cache; - - $MAGIC1 = "\x95\x04\x12\xde"; - $MAGIC2 = "\xde\x12\x04\x95"; - - $this->STREAM = $Reader; - $magic = $this->read(4); - if ($magic == $MAGIC1) { - $this->BYTEORDER = 1; - } elseif ($magic == $MAGIC2) { - $this->BYTEORDER = 0; - } else { - $this->error = 1; // not MO file - return false; - } - - // FIXME: Do we care about revision? We should. - $revision = $this->readint(); - - $this->total = $this->readint(); - $this->originals = $this->readint(); - $this->translations = $this->readint(); - } - - /** - * Loads the translation tables from the MO file into the cache - * If caching is enabled, also loads all strings into a cache - * to speed up translation lookups - * - * @access private - */ - function load_tables() { - if (is_array($this->cache_translations) && - is_array($this->table_originals) && - is_array($this->table_translations)) - return; - - /* get original and translations tables */ - if (!is_array($this->table_originals)) { - $this->STREAM->seekto($this->originals); - $this->table_originals = $this->readintarray($this->total * 2); - } - if (!is_array($this->table_translations)) { - $this->STREAM->seekto($this->translations); - $this->table_translations = $this->readintarray($this->total * 2); - } - - if ($this->enable_cache) { - $this->cache_translations = array (); - /* read all strings in the cache */ - for ($i = 0; $i < $this->total; $i++) { - $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); - $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); - $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); - $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); - $this->cache_translations[$original] = $translation; - } - } - } - - /** - * Returns a string from the "originals" table - * - * @access private - * @param int num Offset number of original string - * @return string Requested string if found, otherwise '' - */ - function get_original_string($num) { - $length = $this->table_originals[$num * 2 + 1]; - $offset = $this->table_originals[$num * 2 + 2]; - if (! $length) - return ''; - $this->STREAM->seekto($offset); - $data = $this->STREAM->read($length); - return (string)$data; - } - - /** - * Returns a string from the "translations" table - * - * @access private - * @param int num Offset number of original string - * @return string Requested string if found, otherwise '' - */ - function get_translation_string($num) { - $length = $this->table_translations[$num * 2 + 1]; - $offset = $this->table_translations[$num * 2 + 2]; - if (! $length) - return ''; - $this->STREAM->seekto($offset); - $data = $this->STREAM->read($length); - return (string)$data; - } - - /** - * Binary search for string - * - * @access private - * @param string string - * @param int start (internally used in recursive function) - * @param int end (internally used in recursive function) - * @return int string number (offset in originals table) - */ - function find_string($string, $start = -1, $end = -1) { - if (($start == -1) or ($end == -1)) { - // find_string is called with only one parameter, set start end end - $start = 0; - $end = $this->total; - } - if (abs($start - $end) <= 1) { - // We're done, now we either found the string, or it doesn't exist - $txt = $this->get_original_string($start); - if ($string == $txt) - return $start; - else - return -1; - } else if ($start > $end) { - // start > end -> turn around and start over - return $this->find_string($string, $end, $start); - } else { - // Divide table in two parts - $half = (int)(($start + $end) / 2); - $cmp = strcmp($string, $this->get_original_string($half)); - if ($cmp == 0) - // string is exactly in the middle => return it - return $half; - else if ($cmp < 0) - // The string is in the upper half - return $this->find_string($string, $start, $half); - else - // The string is in the lower half - return $this->find_string($string, $half, $end); - } - } - - /** - * Translates a string - * - * @access public - * @param string string to be translated - * @return string translated string (or original, if not found) - */ - function translate($string) { - if ($this->short_circuit) - return $string; - $this->load_tables(); - - if ($this->enable_cache) { - // Caching enabled, get translated string from cache - if (array_key_exists($string, $this->cache_translations)) - return $this->cache_translations[$string]; - else - return $string; - } else { - // Caching not enabled, try to find string - $num = $this->find_string($string); - if ($num == -1) - return $string; - else - return $this->get_translation_string($num); - } - } - - /** - * Sanitize plural form expression for use in PHP eval call. - * - * @access private - * @return string sanitized plural form expression - */ - function sanitize_plural_expression($expr) { - // Get rid of disallowed characters. - $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); - - // Add parenthesis for tertiary '?' operator. - $expr .= ';'; - $res = ''; - $p = 0; - for ($i = 0; $i < strlen($expr); $i++) { - $ch = $expr[$i]; - switch ($ch) { - case '?': - $res .= ' ? ('; - $p++; - break; - case ':': - $res .= ') : ('; - break; - case ';': - $res .= str_repeat( ')', $p) . ';'; - $p = 0; - break; - default: - $res .= $ch; - } - } - return $res; - } - - /** - * Parse full PO header and extract only plural forms line. - * - * @access private - * @return string verbatim plural form header field - */ - function extract_plural_forms_header_from_po_header($header) { - if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) - $expr = $regs[2]; - else - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; - return $expr; - } - - /** - * Get possible plural forms from MO header - * - * @access private - * @return string plural form header - */ - function get_plural_forms() { - // lets assume message number 0 is header - // this is true, right? - $this->load_tables(); - - // cache header field for plural forms - if (! is_string($this->pluralheader)) { - if ($this->enable_cache) { - $header = $this->cache_translations[""]; - } else { - $header = $this->get_translation_string(0); - } - $expr = $this->extract_plural_forms_header_from_po_header($header); - $this->pluralheader = $this->sanitize_plural_expression($expr); - } - return $this->pluralheader; - } - - /** - * Detects which plural form to take - * - * @access private - * @param n count - * @return int array index of the right plural form - */ - function select_string($n) { - $string = $this->get_plural_forms(); - $string = str_replace('nplurals',"\$total",$string); - $string = str_replace("n",$n,$string); - $string = str_replace('plural',"\$plural",$string); - - $total = 0; - $plural = 0; - - eval("$string"); - if ($plural >= $total) $plural = $total - 1; - return $plural; - } - - /** - * Plural version of gettext - * - * @access public - * @param string single - * @param string plural - * @param string number - * @return translated plural form - */ - function ngettext($single, $plural, $number) { - if ($this->short_circuit) { - if ($number != 1) - return $plural; - else - return $single; - } - - // find out the appropriate form - $select = $this->select_string($number); - - // this should contains all strings separated by NULLs - $key = $single . chr(0) . $plural; - - - if ($this->enable_cache) { - if (! array_key_exists($key, $this->cache_translations)) { - return ($number != 1) ? $plural : $single; - } else { - $result = $this->cache_translations[$key]; - $list = explode(chr(0), $result); - return $list[$select]; - } - } else { - $num = $this->find_string($key); - if ($num == -1) { - return ($number != 1) ? $plural : $single; - } else { - $result = $this->get_translation_string($num); - $list = explode(chr(0), $result); - return $list[$select]; - } - } - } - - function pgettext($context, $msgid) { - $key = $context . chr(4) . $msgid; - $ret = $this->translate($key); - if (strpos($ret, "\004") !== FALSE) { - return $msgid; - } else { - return $ret; - } - } - - function npgettext($context, $singular, $plural, $number) { - $key = $context . chr(4) . $singular; - $ret = $this->ngettext($key, $plural, $number); - if (strpos($ret, "\004") !== FALSE) { - return $singular; - } else { - return $ret; - } - - } -} - -?> diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 46768f2b..3bf0c7bc 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -288,12 +288,12 @@ function package_details($id=0, $SID="") { $results = db_query($q, $dbh); if (!$results) { - print __("Error retrieving package details.") . "<br />\n"; + print _("Error retrieving package details.") . "<br />\n"; } else { $row = mysql_fetch_assoc($results); if (empty($row)) { - print __("Package details could not be found.") . "<br />\n"; + print _("Package details could not be found.") . "<br />\n"; } else { @@ -540,8 +540,8 @@ function pkg_search_page($SID="") { $templ_pages = array(); if ($current > 1) { - $templ_pages[__('First')] = 0; - $templ_pages[__('Previous')] = ($current - 2) * $per_page; + $templ_pages[_('First')] = 0; + $templ_pages[_('Previous')] = ($current - 2) * $per_page; } if ($current - 5 > 1) @@ -555,8 +555,8 @@ function pkg_search_page($SID="") { $templ_pages["... "] = false; if ($current < $pages) { - $templ_pages[__('Next')] = $current * $per_page; - $templ_pages[__('Last')] = ($pages - 1) * $per_page; + $templ_pages[_('Next')] = $current * $per_page; + $templ_pages[_('Last')] = ($pages - 1) * $per_page; } include('pkg_search_form.php'); @@ -597,18 +597,18 @@ function sanitize_ids($ids) { function pkg_flag ($atype, $ids, $action = True) { if (!$atype) { if ($action) { - return __("You must be logged in before you can flag packages."); + return _("You must be logged in before you can flag packages."); } else { - return __("You must be logged in before you can unflag packages."); + return _("You must be logged in before you can unflag packages."); } } $ids = sanitize_ids($ids); if (empty($ids)) { if ($action) { - return __("You did not select any packages to flag."); + return _("You did not select any packages to flag."); } else { - return __("You did not select any packages to unflag."); + return _("You did not select any packages to unflag."); } } @@ -648,9 +648,9 @@ function pkg_flag ($atype, $ids, $action = True) { } if ($action) { - return __("The selected packages have been flagged out-of-date."); + return _("The selected packages have been flagged out-of-date."); } else { - return __("The selected packages have been unflagged."); + return _("The selected packages have been unflagged."); } } @@ -664,24 +664,24 @@ function pkg_flag ($atype, $ids, $action = True) { */ function pkg_delete ($atype, $ids) { if (!$atype) { - return __("You must be logged in before you can delete packages."); + return _("You must be logged in before you can delete packages."); } # If they're a TU or dev, can delete if ($atype != "Trusted User" && $atype != "Developer") { - return __("You do have permission to delete packages."); + return _("You do have permission to delete packages."); } $ids = sanitize_ids($ids); if (empty($ids)) { - return __("You did not select any packages to delete."); + return _("You did not select any packages to delete."); } $dbh = db_connect(); $q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")"; $result = db_query($q, $dbh); - return __("The selected packages have been deleted."); + return _("The selected packages have been deleted."); } /** @@ -696,18 +696,18 @@ function pkg_delete ($atype, $ids) { function pkg_adopt ($atype, $ids, $action = True) { if (!$atype) { if ($action) { - return __("You must be logged in before you can adopt packages."); + return _("You must be logged in before you can adopt packages."); } else { - return __("You must be logged in before you can disown packages."); + return _("You must be logged in before you can disown packages."); } } $ids = sanitize_ids($ids); if (empty($ids)) { if ($action) { - return __("You did not select any packages to adopt."); + return _("You did not select any packages to adopt."); } else { - return __("You did not select any packages to disown."); + return _("You did not select any packages to disown."); } } @@ -736,9 +736,9 @@ function pkg_adopt ($atype, $ids, $action = True) { if ($action) { pkg_notify(account_from_sid($_COOKIE["AURSID"]), $ids); - return __("The selected packages have been adopted."); + return _("The selected packages have been adopted."); } else { - return __("The selected packages have been disowned."); + return _("The selected packages have been disowned."); } } @@ -754,18 +754,18 @@ function pkg_adopt ($atype, $ids, $action = True) { function pkg_vote ($atype, $ids, $action = True) { if (!$atype) { if ($action) { - return __("You must be logged in before you can vote for packages."); + return _("You must be logged in before you can vote for packages."); } else { - return __("You must be logged in before you can un-vote for packages."); + return _("You must be logged in before you can un-vote for packages."); } } $ids = sanitize_ids($ids); if (empty($ids)) { if ($action) { - return __("You did not select any packages to vote for."); + return _("You did not select any packages to vote for."); } else { - return __("Your votes have been removed from the selected packages."); + return _("Your votes have been removed from the selected packages."); } } @@ -823,9 +823,9 @@ function pkg_vote ($atype, $ids, $action = True) { } if ($action) { - return __("Your votes have been cast for the selected packages."); + return _("Your votes have been cast for the selected packages."); } else { - return __("Your votes have been removed from the selected packages."); + return _("Your votes have been removed from the selected packages."); } } @@ -838,13 +838,13 @@ function pkg_vote ($atype, $ids, $action = True) { */ function pkg_notify ($atype, $ids, $action = True) { if (!$atype) { -# return __("You must be logged in before you can get notifications on comments."); +# return _("You must be logged in before you can get notifications on comments."); return; } $ids = sanitize_ids($ids); if (empty($ids)) { - return __("Couldn't add to notification list."); + return _("Couldn't add to notification list."); } $dbh = db_connect(); @@ -895,10 +895,10 @@ function pkg_notify ($atype, $ids, $action = True) { } if ($action) { - $output = __("You have been added to the comment notification list for %s.", $output); + $output = sprintf(_("You have been added to the comment notification list for %s."), $output); } else { - $output = __("You have been removed from the comment notification list for %s.", $output); + $output = sprintf(_("You have been removed from the comment notification list for %s."), $output); } return $output; @@ -914,14 +914,14 @@ function pkg_notify ($atype, $ids, $action = True) { */ function pkg_delete_comment($atype) { if (!$atype) { - return __("You must be logged in before you can edit package information."); + return _("You must be logged in before you can edit package information."); } # Get ID of comment to be removed if (isset($_POST["comment_id"])) { $comment_id = $_POST["comment_id"]; } else { - return __("Missing comment ID."); + return _("Missing comment ID."); } $uid = uid_from_sid($_COOKIE["AURSID"]); @@ -932,9 +932,9 @@ function pkg_delete_comment($atype) { $q.= "SET DelUsersID = ".$uid." "; $q.= "WHERE ID = ".intval($comment_id); db_query($q, $dbh); - return __("Comment has been deleted."); + return _("Comment has been deleted."); } else { - return __("You are not allowed to delete this comment."); + return _("You are not allowed to delete this comment."); } } @@ -946,25 +946,25 @@ function pkg_delete_comment($atype) { */ function pkg_change_category($atype) { if (!$atype) { - return __("You must be logged in before you can edit package information."); + return _("You must be logged in before you can edit package information."); } # Get ID of the new category if (isset($_POST["category_id"])) { $category_id = $_POST["category_id"]; } else { - return __("Missing category ID."); + return _("Missing category ID."); } $catArray = pkgCategories(); if (!array_key_exists($category_id, $catArray)) { - return __("Invalid category ID."); + return _("Invalid category ID."); } if (isset($_GET["ID"])) { $pid = $_GET["ID"]; } else { - return __("Missing package ID."); + return _("Missing package ID."); } # Verify package ownership @@ -977,7 +977,7 @@ function pkg_change_category($atype) { $pkg = mysql_fetch_assoc($result); } else { - return __("You are not allowed to change this package category."); + return _("You are not allowed to change this package category."); } $uid = uid_from_sid($_COOKIE["AURSID"]); @@ -987,8 +987,8 @@ function pkg_change_category($atype) { $q.= "SET CategoryID = ".intval($category_id)." "; $q.= "WHERE ID = ".intval($pid); db_query($q, $dbh); - return __("Package category changed."); + return _("Package category changed."); } else { - return __("You are not allowed to change this package category."); + return _("You are not allowed to change this package category."); } } diff --git a/web/lib/translator.inc.php b/web/lib/translator.inc.php deleted file mode 100644 index 44c87bda..00000000 --- a/web/lib/translator.inc.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR . '../lang'); - -# This file provides support for i18n - -# usage: -# use the __() function for returning translated strings of -# text. The string can contain escape codes %h for HTML -# and %s for regular text. -# -# examples: -# print __("%s has %s apples.", "Bill", "5"); -# print __("This is a %hmajor%h problem!", "<b>", "</b>"); - -include_once('config.inc.php'); -include_once('gettext.php'); -include_once('streams.php'); - -global $streamer, $l10n; - -function __() { - global $LANG; - global $l10n; - - # Create the translation. - $args = func_get_args(); - - # First argument is always string to be translated - $tag = $args[0]; - - # Translate using gettext_reader initialized before. - $translated = $l10n->translate($tag); - $translated = htmlspecialchars($translated, ENT_QUOTES); - - $num_args = sizeof($args); - - # Subsequent arguments are strings to be formatted - # - # TODO: make this more robust. - # '%%' should translate to a literal '%' - - if ( $num_args > 1 ) { - for ($i = 1; $i < $num_args; $i++) { - $translated = preg_replace("/\%[sh]/", $args[$i], $translated, 1); - } - } - - return $translated; -} - |