Commit 50ad1d30 authored by Stephan Kreutzer's avatar Stephan Kreutzer

HTTP Accept-Language header negotiation added to the languagelib.

parent 2e569c82
<?php
/* Copyright (C) 2016-2017 Stephan Kreutzer
/* Copyright (C) 2016-2019 Stephan Kreutzer
*
* This file is part of VoterFlow.
*
......@@ -19,6 +19,8 @@
* @file $/web/api/libraries/negotiation.inc.php
* @author Stephan Kreutzer
* @since 2016-09-23
* @todo Update $/web/api/libraries/Negotiation from
* https://github.com/willdurand/Negotiation).
*/
......@@ -101,6 +103,19 @@ function NegotiateContentType($supportedContentTypes)
header("Content-Type: ".CONTENT_TYPE_REQUESTED);
}
function NegotiateLanguage($acceptLanguageHeader, $languagePriorities)
{
$negotiator = new \Negotiation\LanguageNegotiator();
$language = $negotiator->getBest($acceptLanguageHeader, $languagePriorities);
if ($language != null)
{
return $language->getType();
}
return null;
}
?>
<?php
/* Copyright (C) 2013-2017 Stephan Kreutzer
/* Copyright (C) 2013-2019 Stephan Kreutzer
*
* This file is part of VoterFlow.
*
......@@ -16,6 +16,12 @@
* along with VoterFlow. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(dirname(__FILE__)."/../api/libraries/negotiation.inc.php");
class LanguageDefinition
{
const DirectionLTR = 1;
......@@ -100,9 +106,13 @@ function getLanguageFile($caller, $baseDirectory = ".")
if (isset($_SESSION['language']) !== true &&
isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) === true)
{
/** @todo Use $/web/api/libraries/Negotiation after update from
* https://github.com/willdurand/Negotiation) to determine
* a reasonable setting on the first encounter. */
$negotiationResult = NegotiateLanguage($_SERVER['HTTP_ACCEPT_LANGUAGE'], array_keys(getLanguageList()));
if ($negotiationResult != null)
{
$language = $negotiationResult;
$_SESSION['language'] = $negotiationResult;
}
}
if (isset($_SESSION['language']) === true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment