[aur-dev] [PATCH 2/2] Move SUPPORTED_LANGS out of config.inc.php

Dan McGee dan at archlinux.org
Fri Oct 21 16:15:56 EDT 2011


This has no real business being here, and is a pain to update when new
languages are shipped. Move it and the set_lang() function to
translator.inc.php instead so it doesn't overwhelm the user-configurable
settings file with static stuff.

Signed-off-by: Dan McGee <dan at archlinux.org>
---

v2- move translation/language setup stuff to translator.inc.php instead so
dependences are more carefully noted. Tested and seems to work as expected.

 web/lib/aur.inc.php          |   56 ----------------------------
 web/lib/config.inc.php.proto |   28 --------------
 web/lib/translator.inc.php   |   84 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 84 deletions(-)

diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index 315092c..3745577 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -261,62 +261,6 @@ function db_query($query="", $db_handle="") {
 	return $result;
 }
 
-# set up the visitor's language
-#
-function set_lang($dbh=NULL) {
-	global $LANG;
-	global $SUPPORTED_LANGS;
-	global $PERSISTENT_COOKIE_TIMEOUT;
-	global $streamer, $l10n;
-
-	$update_cookie = 0;
-	if (isset($_REQUEST['setlang'])) {
-		# visitor is requesting a language change
-		#
-		$LANG = $_REQUEST['setlang'];
-		$update_cookie = 1;
-
-	} elseif (isset($_COOKIE['AURLANG'])) {
-		# If a cookie is set, use that
-		#
-		$LANG = $_COOKIE['AURLANG'];
-
-	} elseif (isset($_COOKIE["AURSID"])) {
-		# No language but a session; use default lang preference
-		#
-		if(!$dbh) {
-			$dbh = db_connect();
-		}
-		$q = "SELECT LangPreference FROM Users, Sessions ";
-		$q.= "WHERE Users.ID = Sessions.UsersID ";
-		$q.= "AND Sessions.SessionID = '";
-		$q.= mysql_real_escape_string($_COOKIE["AURSID"])."'";
-		$result = db_query($q, $dbh);
-
-		if ($result) {
-			$row = mysql_fetch_array($result);
-			$LANG = $row[0];
-		}
-		$update_cookie = 1;
-	}
-
-	# Set $LANG to default if nothing is valid.
-	if (!array_key_exists($LANG, $SUPPORTED_LANGS)) {
-		$LANG = DEFAULT_LANG;
-	}
-
-	if ($update_cookie) {
-		$cookie_time = time() + $PERSISTENT_COOKIE_TIMEOUT;
-		setcookie("AURLANG", $LANG, $cookie_time, "/");
-	}
-
-	$streamer = new FileReader('../locale/' . $LANG .
-		'/LC_MESSAGES/aur.mo');
-	$l10n = new gettext_reader($streamer, true);
-
-	return;
-}
-
 
 # common header
 #
diff --git a/web/lib/config.inc.php.proto b/web/lib/config.inc.php.proto
index 3230815..1f19651 100644
--- a/web/lib/config.inc.php.proto
+++ b/web/lib/config.inc.php.proto
@@ -33,34 +33,6 @@ define("SQL_DEBUG", 0);
 # to '127.0.0.1:11211'.
 #define("MEMCACHE_SERVERS", '127.0.0.1:11211');
 
-# Languages we have translations for
-$SUPPORTED_LANGS = array(
-	"ca" => "Català",
-	"cs" => "česky",
-	"da" => "Dansk",
-	"de" => "Deutsch",
-	"en" => "English",
-	"el" => "Ελληνικά",
-	"es" => "Español",
-	"fi" => "Finnish",
-	"fr" => "Français",
-	"he" => "עברית",
-	"hr" => "Hrvatski",
-	"hu" => "Magyar",
-	"it" => "Italiano",
-	"nb_NO" => "Norsk",
-	"nl" => "Dutch",
-	"pl" => "Polski",
-	"pt" => "Português",
-	"pt_BR" => "Português (Brasil)",
-	"ro" => "Română",
-	"ru" => "Русский",
-	"sr" => "Srpski",
-	"tr" => "Türkçe",
-	"uk" => "Українська",
-	"zh_CN" => "简体中文"
-);
-
 # Session limit per user
 $MAX_SESSIONS_PER_USER = 8;
 
diff --git a/web/lib/translator.inc.php b/web/lib/translator.inc.php
index 54e8cbb..0bcfb9c 100644
--- a/web/lib/translator.inc.php
+++ b/web/lib/translator.inc.php
@@ -17,6 +17,34 @@ include_once('streams.php');
 
 global $streamer, $l10n;
 
+# Languages we have translations for
+$SUPPORTED_LANGS = array(
+	"ca" => "Català",
+	"cs" => "česky",
+	"da" => "Dansk",
+	"de" => "Deutsch",
+	"en" => "English",
+	"el" => "Ελληνικά",
+	"es" => "Español",
+	"fi" => "Finnish",
+	"fr" => "Français",
+	"he" => "עברית",
+	"hr" => "Hrvatski",
+	"hu" => "Magyar",
+	"it" => "Italiano",
+	"nb_NO" => "Norsk",
+	"nl" => "Dutch",
+	"pl" => "Polski",
+	"pt" => "Português",
+	"pt_BR" => "Português (Brasil)",
+	"ro" => "Română",
+	"ru" => "Русский",
+	"sr" => "Srpski",
+	"tr" => "Türkçe",
+	"uk" => "Українська",
+	"zh_CN" => "简体中文"
+);
+
 function __() {
 	global $LANG;
 	global $l10n;
@@ -39,3 +67,59 @@ function __() {
 	return $translated;
 }
 
+# set up the visitor's language
+#
+function set_lang($dbh=NULL) {
+	global $LANG;
+	global $SUPPORTED_LANGS;
+	global $PERSISTENT_COOKIE_TIMEOUT;
+	global $streamer, $l10n;
+
+	$update_cookie = 0;
+	if (isset($_REQUEST['setlang'])) {
+		# visitor is requesting a language change
+		#
+		$LANG = $_REQUEST['setlang'];
+		$update_cookie = 1;
+
+	} elseif (isset($_COOKIE['AURLANG'])) {
+		# If a cookie is set, use that
+		#
+		$LANG = $_COOKIE['AURLANG'];
+
+	} elseif (isset($_COOKIE["AURSID"])) {
+		# No language but a session; use default lang preference
+		#
+		if(!$dbh) {
+			$dbh = db_connect();
+		}
+		$q = "SELECT LangPreference FROM Users, Sessions ";
+		$q.= "WHERE Users.ID = Sessions.UsersID ";
+		$q.= "AND Sessions.SessionID = '";
+		$q.= mysql_real_escape_string($_COOKIE["AURSID"])."'";
+		$result = db_query($q, $dbh);
+
+		if ($result) {
+			$row = mysql_fetch_array($result);
+			$LANG = $row[0];
+		}
+		$update_cookie = 1;
+	}
+
+	# Set $LANG to default if nothing is valid.
+	if (!array_key_exists($LANG, $SUPPORTED_LANGS)) {
+		$LANG = DEFAULT_LANG;
+	}
+
+	if ($update_cookie) {
+		$cookie_time = time() + $PERSISTENT_COOKIE_TIMEOUT;
+		setcookie("AURLANG", $LANG, $cookie_time, "/");
+	}
+
+	$streamer = new FileReader('../locale/' . $LANG .
+		'/LC_MESSAGES/aur.mo');
+	$l10n = new gettext_reader($streamer, true);
+
+	return;
+}
+
-- 
1.7.7



More information about the aur-dev mailing list