library slim-multilanguage
Multilanguage support for slim framework 2
simotod/slim-multilanguage
Multilanguage support for slim framework 2
- Monday, January 25, 2016
- by SimoTod
- Repository
- 1 Watchers
- 14 Stars
- 236 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 2 Forks
- 0 Open issues
- 1 Versions
- 2 % Grown
slim-multilanguage
This is an extension to the SLIM framework vers.2 to enable simple route localization., (*1)
Installation
Add dependecy to composer.json, (*2)
{
"require": {
"simotod/slim-multilanguage": "dev-master"
}
}
Usage
require 'vendor/autoload.php';
$defaultLanguage = "en";
$availableLanguages = array("en", "it");
$app = new \Slim\Slim();
$app->add(new \SimoTod\Language\LanguageMiddleware($availableLanguages, $defaultLanguage));
$app->get('/hello', function () use ($app) {
//This route works for "/hello", "/en/hello", "/it/hello"
if($app->locale->get() == "it") {
echo "Ciao mondo!";
} else {
echo "Hello world!";
}
});
$app->run();