Setup should use the user's browser language.
This closes issue #197 Please check if it works with php8.1. Tested with php 7.4 Update main.php 'el-gr','es-es','fr-fr' removed as browser language, because the FlatPress setup currently has no language files for it Update lang.de-de.php Update main.php some code formatting
This commit is contained in:
parent
024508392b
commit
2849e97311
@ -63,7 +63,7 @@ $lang ['step3'] = array(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$lang ['buttonbar'] = array(
|
$lang ['buttonbar'] = array(
|
||||||
'next' => 'Next >'
|
'next' => 'Weiter >'
|
||||||
);
|
);
|
||||||
|
|
||||||
$lang ['samplecontent'] = array();
|
$lang ['samplecontent'] = array();
|
||||||
|
@ -1,6 +1,66 @@
|
|||||||
<?php
|
<?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
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
$language = @$_POST['language']? $_POST['language'] :'en-us';
|
// 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');
|
||||||
|
|
||||||
|
$language = @$_POST ['language']? $_POST ['language'] : $browserLang;
|
||||||
|
|
||||||
$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 +73,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