1. Go to this page and download the library: Download mcaskill/slim-polyglot 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/ */
mcaskill / slim-polyglot example snippets
use Slim\App;
use McAskill\Slim\Polyglot\Polyglot;
$app = new App();
// Fetch DI Container
$container = $app->getContainer();
// Register Middleware
$app->add(new Polyglot([ 'en', 'fr', 'es' ]));
// Example route with ETag header
$app->get('/foo', function ($request, $response) {
$language = $response->getHeader('Content-Language');
// Handle response!
});
$app->run();
use Slim\App;
use McAskill\Slim\Polyglot\Polyglot;
$app = new App();
// Fetch DI Container
$container = $app->getContainer();
// Register Middleware
$app->add(
new Polyglot([
'languages' => [ 'en', 'fr', 'es' ],
'fallbackLanguage' => 'fr',
// Hooks to call after language is resolved
'callbacks' => [
function ($language) use ($container) {
$container['environment']['language.current'] = $language;
},
[ 'MySuperApp', 'set_language' ]
]
])
);
// Example route with ETag header
$app->get('/foo', function ($request, $response) {
$language = $this->environment['language.current'];
// Handle response!
});
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.