dev-master
9999999-devSlim Framework middleware to set your applications locale
MIT
The Requires
- php >=5.6.0
- psr/http-message ^1.0
The Development Requires
by Ian Grindley
middleware psr7 locale slim framework
Slim Framework middleware to set your applications locale
Slim Framework middleware to set your applications locale, (*2)
This middleware sets your applications locale to the best match between your applications supported locales and your visitors preferred locales., (*3)
It's designed to be used with the Slim Framework but is PSR7 compatible so should work elsewhere too., (*4)
The visitors locale is determined in this order:, (*5)
When a match has been found the middleware sets:, (*6)
Install via composer, (*7)
$ composer require dijix/setlocale ```` ## Usage ```php // In Slim PHP framework 3 // add the middleware to your app, often in the middleware.php or dependencies.php file // pass your settings as an array to the constructor. $app->add(new Dijix\Locale\setLocaleMiddleware([ // set the locales supported by your application "app_locales" => ["de_DE", "en_GB", "fr_FR", "pt_PT"], // set a default locale to fallback on if no match is found "app_default" => "en_GB", // call PHP setlocale(LC_ALL) to set the visitors locale? "set_locale" => true, // strict or partial matching of the locale codes, e.g. "en" matches "en_GB" "strict_match" => false, // override uri/headers locale, useful when setting locale from a cookie or user session "override" => "pt_PT" ]));
The locale middleware will set a request attribute which can be accessed as follows:, (*8)
$locale = $request->getAttribute('locale'); // sets $locale to "en_GB"
Slim Framework middleware to set your applications locale
MIT
middleware psr7 locale slim framework