simotod/slim-multilanguage

Multilanguage support for slim framework 2

dev-master 2016-01-24 23:10 UTC

This package is auto-updated.

Last update: 2022-11-16 03:23:36 UTC


README

This is an extension to the SLIM framework vers.2 to enable simple route localization.

##Installation Add dependecy to composer.json

    {
        "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();