PHP code example of germania-kg / language-negotiation

1. Go to this page and download the library: Download germania-kg/language-negotiation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

germania-kg / language-negotiation example snippets



use Germania\LanguageNegotiation\LanguageNegotiationMiddleware;
use Negotiation\LanguageNegotiator;

$negotiator = new LanguageNegotiator();  
$priorities = array('de', 'fu', 'en');

new LanguageNegotiationMiddleware($negotiator, $priorities);

// Defaults:
$accept_header = "Accept-Language";
$attr_name = "X-language-negotiated";
$logger = new Monolog // Any PSR-3 Logger; 

new LanguageNegotiationMiddleware($negotiator, $priorities, $accept_header, $attr_name, $logger);

$middleware = new LanguageNegotiationMiddleware($negotiator, $priorities);
$middleware->setAcceptLanguageHeader("Accept-Language");
$middleware->setRequestAttributeName("X-language-negotiated");
$middleware->setLogger( $psr3_logger );


class MyController
{
  public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $args)
  {
    	// S.th. like 'fu'
    	echo $request->getAttribute("X-language-negotiated");
  }
}