bluespoon
Threadersteller
Dabei seit: 10.11.2006
Ort: Hannover
Alter: 41
Geschlecht:
|
Verfasst Di 23.01.2007 10:08
Titel Automatische Spracherkennung des Browsers ohne JS möglich? |
|
|
Hallo!
Jemand eine Ahnung, ob ich auch ohne JS die Sprache des
Browsers / bevorzugte Sprache des Seitenbesuchers einer
Internetseite herausbekomme?
Geht um eine zweisprachige Internetseite. Bis jetzt habe ich
zwei Sprach-Dateien, die includet werden. Und zwar gibt es
oben in jeder Datei gleich eine Variable, welche ich an jeden
Link der Seite übergebe, die dann dafür sorgt, dass auch
immer die richtige Sprache angezeigt ist. Zu Anfang muss
man sie natürlich ersteinmal wählen ... ohne Auswahl ist es
Deutsch.
Eleganter wäre natürlich die Wahlmöglichkeit PLUS eine Auto-
Erkennung.
LG
bluespoon
|
|
tacker
Dabei seit: 22.03.2002
Ort: Trondheim, Norwegen
Alter: 43
Geschlecht:
|
Verfasst Di 23.01.2007 11:34
Titel
|
|
|
Code: | // +----------------------------------------------------------------------+
// | Copyright (C) 2007 Markus Tacker | http://m.tacker.org |
// +----------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU Lesser General Public |
// | License as published by the Free Software Foundation; either |
// | version 2.1 of the License, or (at your option) any later version. |
// | |
// | This library is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | Lesser General Public License for more details. |
// | |
// | You should have received a copy of the GNU Lesser General Public |
// | License along with this library; if not, write to the |
// | Free Software Foundation, Inc. |
// | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
// +----------------------------------------------------------------------+
/**
* Returns an array with the accepted locales from the useragent
* ordered by their priority
* converted into gnu locale strings
* @copyright Markus Tacker <m@tacker.org>
*
* @return array
*/
public static function getAcceptLocales()
{
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) return array();
$return = array();
$lastprio = 0;
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $localeprio) {
if (strstr($localeprio, ';')) {
list($locale, $prio) = explode(';', $localeprio);
$prio = floatval(substr($prio, 2));
} else {
$locale = $localeprio;
$prio = 1;
}
if (strstr($locale, '-')) {
list($lfirst, $llast) = explode('-', $locale);
$locale = $lfirst . '_' . strtoupper($llast);
}
if ($prio > $lastprio) {
array_unshift($return, trim($locale));
} else {
array_push($return, trim($locale));
}
$lastprio = $prio;
}
return $return;
} |
|
|