Merge pull request #198 from Fraenkiman/upstream/issue197
The setup, the blog and the admin area starts automatically in the language of the user.
This commit is contained in:
commit
61aee176b8
@ -93,7 +93,8 @@ define('IMAGES_DIR', FP_CONTENT . 'images/');
|
|||||||
// here is where all the attachments will be saved
|
// here is where all the attachments will be saved
|
||||||
define('ATTACHS_DIR', FP_CONTENT . 'attachs/');
|
define('ATTACHS_DIR', FP_CONTENT . 'attachs/');
|
||||||
|
|
||||||
define('LANG_DEFAULT', 'en-us');
|
include(LANG_DIR . 'browserlang.php');
|
||||||
|
define('LANG_DEFAULT', $browserLang);
|
||||||
define('BPT_SORT', SORT_DESC);
|
define('BPT_SORT', SORT_DESC);
|
||||||
|
|
||||||
set_include_path(ABS_PATH);
|
set_include_path(ABS_PATH);
|
||||||
|
@ -21,7 +21,7 @@ $fp_config = array(
|
|||||||
'dateformat' => '%A, %B %e, %Y',
|
'dateformat' => '%A, %B %e, %Y',
|
||||||
'dateformatshort' => '%Y-%m-%d',
|
'dateformatshort' => '%Y-%m-%d',
|
||||||
'charset' => 'utf-8',
|
'charset' => 'utf-8',
|
||||||
'lang' => 'en-us'
|
'lang' => ''
|
||||||
),
|
),
|
||||||
'plugins' => array(
|
'plugins' => array(
|
||||||
'blockparser' => array(
|
'blockparser' => array(
|
||||||
@ -37,4 +37,6 @@ $fp_config = array(
|
|||||||
'url-maxlen' => 40,
|
'url-maxlen' => 40,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
?>
|
||||||
|
64
fp-interface/lang/browserlang.php
Normal file
64
fp-interface/lang/browserlang.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Get the language code from the browser
|
||||||
|
*
|
||||||
|
* @param array Allowed Languages "array('cs-cz','de-de','en-us','it-it','ja-jp','nl-nl','pt-br')"
|
||||||
|
* @param string Default language
|
||||||
|
* @param string Language string from HTTP-Header
|
||||||
|
* @param bool Strict-Mode
|
||||||
|
* @return array|int Data as array or null
|
||||||
|
*/
|
||||||
|
error_reporting(0);
|
||||||
|
function getBrowserLanguage($arrAllowedLanguages, $strDefaultLanguage, $strLangVariable = null, $boolStrictMode = true) {
|
||||||
|
if (isset($_REQUEST ['language'])) {
|
||||||
|
if (strlen($_REQUEST ['language']) == 2) {
|
||||||
|
return strtolower($_REQUEST ['language']);
|
||||||
|
}
|
||||||
|
foreach ($arrAllowedLanguages as $strValue) {
|
||||||
|
if (preg_match('/^' . $strValue . '\-/i', $_REQUEST ['language'])) {
|
||||||
|
return strtolower($strValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_array($arrAllowedLanguages)) {
|
||||||
|
if (strpos($arrAllowedLanguages,';')) {
|
||||||
|
$array = explode(';', $arrAllowedLanguages);
|
||||||
|
$arrAllowedLanguages = $array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isset($_SERVER ['HTTP_ACCEPT_LANGUAGE'])) {
|
||||||
|
return $arrAllowedLanguages [0];
|
||||||
|
}
|
||||||
|
if ($strLangVariable === null) $strLangVariable = $_SERVER ['HTTP_ACCEPT_LANGUAGE'];
|
||||||
|
if (empty($strLangVariable)) return $strDefaultLanguage;
|
||||||
|
$arrAcceptedLanguages = preg_split('/,\s*/', $strLangVariable);
|
||||||
|
$strCurrentLanguage = $strDefaultLanguage;
|
||||||
|
$intCurrentQ = 0;
|
||||||
|
foreach ($arrAcceptedLanguages as $arrAcceptedLanguage) {
|
||||||
|
$boolResult = preg_match ('/^([a-z]{1,8}(?:-[a-z]{1,8})*)' . '(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $arrAcceptedLanguage, $arrMatches);
|
||||||
|
if (!$boolResult) continue;
|
||||||
|
$arrLangCode = explode ('-', $arrMatches [1]);
|
||||||
|
if (isset($arrMatches [2]))
|
||||||
|
$intLangQuality = (float)$arrMatches [2];
|
||||||
|
else
|
||||||
|
$intLangQuality = 1.0;
|
||||||
|
while (count ($arrLangCode)) {
|
||||||
|
if (!is_array($arrAllowedLanguages)) $arrAllowedLanguages = array($arrAllowedLanguages);
|
||||||
|
if (in_array (strtolower (join ('-', $arrLangCode)), $arrAllowedLanguages)) {
|
||||||
|
if ($intLangQuality > $intCurrentQ) {
|
||||||
|
$strCurrentLanguage = strtolower (join ('-', $arrLangCode));
|
||||||
|
$intCurrentQ = $intLangQuality;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($boolStrictMode) break;
|
||||||
|
array_pop ($arrLangCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $strCurrentLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// accept the following languages, otherwise fall back to "en-us"
|
||||||
|
$browserLang = getBrowserLanguage(array('cs-cz', 'de-de', 'en-us', 'it-it', 'ja-jp', 'nl-nl', 'pt-br'), 'en-us');
|
||||||
|
|
||||||
|
?>
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
$language = @$_POST ['language']? $_POST ['language'] : $browserLang;
|
||||||
$language = @$_POST['language']? $_POST['language'] :'en-us';
|
|
||||||
|
|
||||||
$lf = "lang.$language.php";
|
$lf = "lang.$language.php";
|
||||||
if (!preg_match('|^lang\.[a-z]{2}-[a-z]{2}\.php$|', $lf))
|
if (!preg_match('|^lang\.[a-z]{2}-[a-z]{2}\.php$|', $lf))
|
||||||
@ -13,12 +12,10 @@ $step = null;
|
|||||||
|
|
||||||
$id = getstep($step);
|
$id = getstep($step);
|
||||||
|
|
||||||
$l =& $lang[$step];
|
$l =& $lang [$step];
|
||||||
|
|
||||||
|
|
||||||
include("./setup/tpls/header.tpl.php");
|
include("./setup/tpls/header.tpl.php");
|
||||||
include("./setup/tpls/{$step}.tpl.php");
|
include("./setup/tpls/{$step}.tpl.php");
|
||||||
include("./setup/tpls/footer.tpl.php");
|
include("./setup/tpls/footer.tpl.php");
|
||||||
|
|
||||||
|
?>
|
||||||
?>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user