[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Librefm-commits] [1423] If the language gets set explicitly by the user
From: |
Michael Sheldon |
Subject: |
[Librefm-commits] [1423] If the language gets set explicitly by the user then store it in a cookie for future usage |
Date: |
Fri, 08 May 2009 22:29:27 +0000 |
Revision: 1423
http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1423
Author: elleo
Date: 2009-05-08 22:29:27 +0000 (Fri, 08 May 2009)
Log Message:
-----------
If the language gets set explicitly by the user then store it in a cookie for
future usage
Otherwise attempt to magically work out the locale from HTTP_ACCEPT_LANGUAGE
Modified Paths:
--------------
trunk/nixtape/templating.php
Modified: trunk/nixtape/templating.php
===================================================================
--- trunk/nixtape/templating.php 2009-05-08 21:38:55 UTC (rev 1422)
+++ trunk/nixtape/templating.php 2009-05-08 22:29:27 UTC (rev 1423)
@@ -25,9 +25,23 @@
if($_GET['lang']) {
$languages = array($_GET['lang'] . ".UTF-8");
+ setcookie('lang', $_GET['lang'] . ".UTF-8", time() + 31536000);
+} elseif (isset($_COOKIE['lang'])) {
+ $languages = array($_COOKIE['lang']);
} else {
- //TODO: Convert HTTP_ACCEPT_LANGUAGE to a gettext locale
+ // Attempt to mangle browser language strings in to valid gettext
locales (needs a big lookup table to be 100% accurate)
$languages = preg_split("/,/", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ for($i = 0; $i < count($languages); $i++) {
+ $languages[$i] = preg_replace('/;q=\d\.\d/', '',
$languages[$i]);
+ if(strlen($languages[$i]) == 2) {
+ $languages[$i] = $languages[$i] . '_' .
strtoupper($languages[$i]);
+ } elseif (stristr($languages[$i], '-')) {
+ $lcomponents = preg_split('/-/', $languages[$i]);
+ $languages[$i] = $lcomponents[0] . '_' .
strtoupper($lcomponents[1]);
+ }
+
+ $languages[$i] = $languages[$i] . ".UTF-8";
+ }
}
setlocale(LC_ALL, $languages);
bindtextdomain("nixtape", $install_path . '/themes/' . $default_theme .
'/locale/');
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Librefm-commits] [1423] If the language gets set explicitly by the user then store it in a cookie for future usage,
Michael Sheldon <=