1. Go to this page and download the library: Download luism-s/multilingualslim 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/ */
luism-s / multilingualslim example snippets
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
tContainer();
$app->add( new \MultilingualSlim\LanguageMiddleware($available_languages, $default_language, $container) );
$app->get('/', function (Request $request, Response $response) {
// This works with '/', '/pt' and '/en',
// and prints 'Hello' in each language.
if ($this->language === 'pt') {
return $response->write("Olá Mundo");
} elseif($this->language === 'en') {
return $response->write("Hello World");
}
});
$app->run();
$container['renderer'] = new \Slim\Views\PhpRenderer("../views/");
$app->get('/home', function (Request $request, Response $response) {
// This works with '/home', '/pt/home' and '/en/home',
// and returns the template views/base.php.
// It also passes the chosen language as an argument accessible from the chosen template.
return $this->renderer->render($response, "base.php", [
"language" => $this->language
]);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.