per-seo / locale
Language in URI for Slim 4. This Middleware add an attribute 'locale' to the request object, to help with page translation for SEO.
1.1.1
2024-11-20 11:12 UTC
Requires
- php: >=7.4
- psr/http-server-middleware: ^1
Requires (Dev)
- friendsofphp/php-cs-fixer: >=2
- overtrue/phplint: ^2
- phpstan/phpstan: >=1
- phpunit/phpunit: ^11.4
- slim/psr7: ^1
- slim/slim: ^4
- squizlabs/php_codesniffer: ^3
README
A simple middleware for Slim4 framework for using locale in uri. Usage is very simple, just add in your container settings this array:
'settings_global' => [
'language' => 'it',
'languages' => ['it', 'en'],
'locale' => true,
]
And enable this Middleware (in the Middleware part of your Slim4 Project) with:
<?php
use PerSeo\Middleware\Locale\Locale;
$app->add(Locale::class);
After this, all your Slim 4 routes works without the language prefix in routes (because this Middleware check the language before routes are called). To retrive what language the project is using, just call:
$request->getAttribute('locale');
Simple, isn't it?