Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 782 Bytes

README.md

File metadata and controls

39 lines (28 loc) · 782 Bytes

slim-multilanguage

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