2 set_include_path(get_include_path() . PATH_SEPARATOR
. '../lib' . PATH_SEPARATOR
. '../lang');
4 # This file provides support for i18n
7 # use the __() function for returning translated strings of
8 # text. The string can contain escape codes "%s".
11 # print __("%s has %s apples.", "Bill", "5");
12 # print __("This is a %smajor%s problem!", "<strong>", "</strong>");
14 include_once("confparser.inc.php");
15 include_once('DB.class.php');
16 include_once('gettext.php');
17 include_once('streams.php');
19 global $streamer, $l10n;
21 # Languages we have translations for
22 $SUPPORTED_LANGS = array(
31 "es_419" => "Español (Latinoamérica)",
42 "pt_BR" => "Português (Brasil)",
43 "pt_PT" => "Português (Portugal)",
58 # Create the translation.
59 $args = func_get_args();
61 # First argument is always string to be translated
62 $tag = array_shift($args);
64 # Translate using gettext_reader initialized before.
65 $translated = $l10n->translate($tag);
66 $translated = htmlspecialchars($translated, ENT_QUOTES
);
68 # Subsequent arguments are strings to be formatted
69 if (count($args) > 0) {
70 $translated = vsprintf($translated, $args);
76 function _n($msgid1, $msgid2, $n) {
79 $translated = sprintf($l10n->ngettext($msgid1, $msgid2, $n), $n);
80 return htmlspecialchars($translated, ENT_QUOTES
);
83 # set up the visitor's language
87 global $SUPPORTED_LANGS;
88 global $streamer, $l10n;
91 if (isset($_POST['setlang'])) {
92 # visitor is requesting a language change
94 $LANG = $_POST['setlang'];
97 } elseif (isset($_COOKIE['AURLANG'])) {
98 # If a cookie is set, use that
100 $LANG = $_COOKIE['AURLANG'];
102 } elseif (isset($_COOKIE["AURSID"])) {
103 # No language but a session; use default lang preference
105 $dbh = DB
::connect();
106 $q = "SELECT LangPreference FROM Users, Sessions ";
107 $q.= "WHERE Users.ID = Sessions.UsersID ";
108 $q.= "AND Sessions.SessionID = '";
109 $q.= $dbh->quote($_COOKIE["AURSID"]);
110 $result = $dbh->query($q);
113 $row = $result->fetchAll();
119 # Set $LANG to default if nothing is valid.
120 if (!array_key_exists($LANG, $SUPPORTED_LANGS)) {
121 $LANG = config_get('options', 'default_lang');
124 if ($update_cookie) {
125 $timeout = intval(config_get('options', 'persistent_cookie_timeout'));
126 $cookie_time = time() +
$timeout;
127 setcookie("AURLANG", $LANG, $cookie_time, "/");
130 $streamer = new FileReader('../locale/' . $LANG .
131 '/LC_MESSAGES/aur.mo');
132 $l10n = new gettext_reader($streamer, true);