[med-svn] r653 - trunk/community/website/inc

hanska-guest at alioth.debian.org hanska-guest at alioth.debian.org
Sat Oct 6 16:29:35 UTC 2007


Author: hanska-guest
Date: 2007-10-06 16:29:35 +0000 (Sat, 06 Oct 2007)
New Revision: 653

Added:
   trunk/community/website/inc/dynlocale.inc.php
   trunk/community/website/inc/locales.txt
Modified:
   trunk/community/website/inc/header.inc.php
   trunk/community/website/inc/locale.inc.php
Log:
Trying to simplify (and automate) inc/locale.inc.php


Added: trunk/community/website/inc/dynlocale.inc.php
===================================================================
--- trunk/community/website/inc/dynlocale.inc.php	                        (rev 0)
+++ trunk/community/website/inc/dynlocale.inc.php	2007-10-06 16:29:35 UTC (rev 653)
@@ -0,0 +1,91 @@
+<?php
+// _SERVER["HTTP_ACCEPT_LANGUAGE"] it-it,it;q=0.8,en-gb;q=0.6,en-us;q=0.4,en;q=0.2
+
+// this odd name is to avoid conflict with
+// po-stats.inc.php's clean()
+function __clean__($item) {
+	if (is_array($item)) {
+		if (!count($item))
+			$item = null;
+		else {
+			foreach ($item as $key => $value) {
+				$item[$key] = __clean__($value);
+				if (empty($item[$key]))
+					unset($item[$key]);
+			}
+		}
+	} else {
+		if (empty($item))
+			$item = null;
+	}
+	return $item;
+}
+
+$languages = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
+$lang_arr = explode(",", $languages);
+$lang_arr[0] .= ";q=1.0";
+
+$locales_dir = "../locale/";
+$def_locale = "en_US";
+$priority = "0.0";
+
+$i = 0;
+foreach ($lang_arr as $lang_code) {
+	$tmp[] = explode(";", $lang_code);
+	
+	// let's use the aa_BB format
+	preg_match("/([a-zA-Z]+)-([a-zA-Z]+)/", $tmp[$i][0], $matches);
+	$tmp[$i][0] = ($matches) ? strtolower($matches[1]) . "_" . strtoupper($matches[2]) : $tmp[$i][0];
+	$langs[str_replace("q=", "", $tmp[$i][1])] = $tmp[$i][0];
+	$i++;
+}
+
+// let's sort them by priority, highest first
+krsort($langs);
+
+if ($fp = fopen("locales.txt", "r")) {
+	while (!feof($fp)) {
+		$raw .= fgets($fp, 4096);
+	}
+	fclose($fp);
+} else {
+	die ("Please contact the site administrators: debian-med at lists.debian.org -- Cannot open locales.txt");
+}
+
+// let's remove comments and empty lines
+$raw = preg_replace("/^\\#.*\\n/m", "", $raw);
+$raw = preg_replace("/^[ ]*\\n/m", "", $raw);
+
+$tmp_installed = __clean__(explode("\n", $raw));
+foreach ($tmp_installed as $pair) {
+	$row = explode("\t", $pair);
+	$installed[$row[0]] = $row[1];
+}
+
+foreach ($langs as $index => $language) {
+	if ($installed[$language]) {
+		$locale = $installed[$language];
+		$priority = $index;
+	} else {
+		$locale = $def_locale;
+	}
+}
+
+// we'll use this in a <meta> tag in our header
+// and in the xml declaration.
+preg_match("/([a-z]+)_[A-Z]+/", $locale, $matches);
+$lang = $matches[1];
+
+if ($priority < "0.8") {
+	$show_locale_warning = true;
+}
+
+putenv("LC_ALL=$locale.UTF-8");
+putenv("LANG=$locale.UTF-8");
+putenv("LANGUAGE=$locale.UTF-8");
+setlocale(LC_ALL, "$locale.UTF-8");
+$domain = "messages";
+bindtextdomain($domain, "./locale");
+textdomain($domain);
+
+?>

Modified: trunk/community/website/inc/header.inc.php
===================================================================
--- trunk/community/website/inc/header.inc.php	2007-10-06 15:47:14 UTC (rev 652)
+++ trunk/community/website/inc/header.inc.php	2007-10-06 16:29:35 UTC (rev 653)
@@ -1,5 +1,5 @@
 <?php
-	require_once("locale.inc.php");
+	require_once("dynlocale.inc.php");
 
 	$type = "text/html; charset=UTF-8";
 	$xml = "";

Modified: trunk/community/website/inc/locale.inc.php
===================================================================
--- trunk/community/website/inc/locale.inc.php	2007-10-06 15:47:14 UTC (rev 652)
+++ trunk/community/website/inc/locale.inc.php	2007-10-06 16:29:35 UTC (rev 653)
@@ -5,7 +5,6 @@
 $lang_arr = explode(",", $languages);
 $lang_arr[0] .= ";q=1.0";
 
-//$locales_dir = "/srv/alioth.debian.org/chroot/home/groups/debian-med/htdocs/locale/";
 $locales_dir = "../locale/";
 
 $available = array(

Added: trunk/community/website/inc/locales.txt
===================================================================
--- trunk/community/website/inc/locales.txt	                        (rev 0)
+++ trunk/community/website/inc/locales.txt	2007-10-06 16:29:35 UTC (rev 653)
@@ -0,0 +1,51 @@
+###
+# PLEASE, DON'T MANUALLY EDIT THIS FILE.
+# OTHERWISE YOU MIGHT BREAK UP LOCALIZATION.
+###
+
+###
+# The format of this file is:
+#
+# alias<TAB>locale
+#
+# For example, the "it" locale points to the real locale
+# on the server, it_IT.
+###
+
+# Italian
+it	it_IT
+it_CH	it_IT
+it_IT	it_IT
+
+# German
+de	de_DE
+de_DE	de_DE
+de_CH	de_DE
+de_BE	de_DE
+de_AT	de_DE
+de_LU	de_DE
+
+# French
+fr	fr_FR
+fr_FR	fr_FR
+fr_BE	fr_FR
+fr_CA	fr_FR
+fr_CH	fr_FR
+fr_LU	fr_FR
+
+# English
+en	en_US
+en_US	en_US
+en_GB	en_US
+en_AU	en_US
+en_BW	en_US
+en_CA	en_US
+en_DK	en_US
+en_HK	en_US
+en_IN	en_US
+en_NZ	en_US
+en_IE	en_US
+en_PH	en_US
+en_SG	en_US
+en_ZA	en_US
+en_ZW	en_US




More information about the debian-med-commit mailing list