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(
40 "pt_BR" => "Português (Brasil)",
41 "pt_PT" => "Português (Portugal)",
56 # Create the translation.
57 $args = func_get_args();
59 # First argument is always string to be translated
60 $tag = array_shift($args);
62 # Translate using gettext_reader initialized before.
63 $translated = $l10n->translate($tag);
64 $translated = htmlspecialchars($translated, ENT_QUOTES
);
66 # Subsequent arguments are strings to be formatted
67 if (count($args) > 0) {
68 $translated = vsprintf($translated, $args);
74 function _n($msgid1, $msgid2, $n) {
77 $translated = sprintf($l10n->ngettext($msgid1, $msgid2, $n), $n);
78 return htmlspecialchars($translated, ENT_QUOTES
);
81 # set up the visitor's language
85 global $SUPPORTED_LANGS;
86 global $streamer, $l10n;
89 if (isset($_POST['setlang'])) {
90 # visitor is requesting a language change
92 $LANG = $_POST['setlang'];
95 } elseif (isset($_COOKIE['AURLANG'])) {
96 # If a cookie is set, use that
98 $LANG = $_COOKIE['AURLANG'];
100 } elseif (isset($_COOKIE["AURSID"])) {
101 # No language but a session; use default lang preference
103 $dbh = DB
::connect();
104 $q = "SELECT LangPreference FROM Users, Sessions ";
105 $q.= "WHERE Users.ID = Sessions.UsersID ";
106 $q.= "AND Sessions.SessionID = '";
107 $q.= $dbh->quote($_COOKIE["AURSID"]);
108 $result = $dbh->query($q);
111 $row = $result->fetchAll();
117 # Set $LANG to default if nothing is valid.
118 if (!array_key_exists($LANG, $SUPPORTED_LANGS)) {
119 $LANG = config_get('options', 'default_lang');
122 if ($update_cookie) {
123 $timeout = intval(config_get('options', 'persistent_cookie_timeout'));
124 $cookie_time = time() +
$timeout;
125 setcookie("AURLANG", $LANG, $cookie_time, "/");
128 $streamer = new FileReader('../locale/' . $LANG .
129 '/LC_MESSAGES/aur.mo');
130 $l10n = new gettext_reader($streamer, true);