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(
32 "es_419" => "Español (Latinoamérica)",
43 "pt_BR" => "Português (Brasil)",
44 "pt_PT" => "Português (Portugal)",
59 # Create the translation.
60 $args = func_get_args();
62 # First argument is always string to be translated
63 $tag = array_shift($args);
65 # Translate using gettext_reader initialized before.
66 $translated = $l10n->translate($tag);
67 $translated = htmlspecialchars($translated, ENT_QUOTES
);
69 # Subsequent arguments are strings to be formatted
70 if (count($args) > 0) {
71 $translated = vsprintf($translated, $args);
77 function _n($msgid1, $msgid2, $n) {
80 $translated = sprintf($l10n->ngettext($msgid1, $msgid2, $n), $n);
81 return htmlspecialchars($translated, ENT_QUOTES
);
84 # set up the visitor's language
88 global $SUPPORTED_LANGS;
89 global $streamer, $l10n;
92 if (isset($_POST['setlang'])) {
93 # visitor is requesting a language change
95 $LANG = $_POST['setlang'];
98 } elseif (isset($_COOKIE['AURLANG'])) {
99 # If a cookie is set, use that
101 $LANG = $_COOKIE['AURLANG'];
103 } elseif (isset($_COOKIE["AURSID"])) {
104 # No language but a session; use default lang preference
106 $dbh = DB
::connect();
107 $q = "SELECT LangPreference FROM Users, Sessions ";
108 $q.= "WHERE Users.ID = Sessions.UsersID ";
109 $q.= "AND Sessions.SessionID = '";
110 $q.= $dbh->quote($_COOKIE["AURSID"]);
111 $result = $dbh->query($q);
114 $row = $result->fetchAll();
120 # Set $LANG to default if nothing is valid.
121 if (!array_key_exists($LANG, $SUPPORTED_LANGS)) {
122 $LANG = config_get('options', 'default_lang');
125 if ($update_cookie) {
126 $timeout = intval(config_get('options', 'persistent_cookie_timeout'));
127 $cookie_time = time() +
$timeout;
128 setcookie("AURLANG", $LANG, $cookie_time, "/");
131 $streamer = new FileReader('../locale/' . $LANG .
132 '/LC_MESSAGES/aur.mo');
133 $l10n = new gettext_reader($streamer, true);