1. Go to this page and download the library: Download bedita/i18n library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bedita / i18n example snippets
$this->addPlugin('BEdita/I18n');
/*
* I18n configuration.
*/
Configure::write('I18n', [
// list of locales supported
// locale => primary language code for that locale
'locales' => [
'en_US' => 'en',
'it_IT' => 'it',
],
// default primary language code
'default' => 'en',
// list of languages supported
// primary language code => humanized language
'languages' => [
'en' => 'English',
'it' => 'Italiano',
],
/** Middleware specific conf **/
// array of URL paths, if there's an exact match rule is applied
'match' => ['/'],
// array of URL paths, if current URL path starts with one of these rule is applied
'startWith' => ['/help', '/about'],
//reserved URL (for example `/lang`) used to switch language and redirect to referer URL.
'switchLangUrl' => '/lang',
// array for cookie that keeps the locale value. By default no cookie is used.
'cookie' => [
'name' => 'i18n-lang', //cookie name
'create' => true, // set to `true` if the middleware is responsible of cookie creation
'expire' => '+1 year', // used when `create` is `true` to define when the cookie must expire
],
// session key where store the locale. Set null to disable (default)
'sessionKey' => 'i18n-session-locale',
]);
namespace App;
use Cake\Http\BaseApplication;
/**
* Application setup class.
*/
class Application extends BaseApplication
{
/**
* {inheritDoc}
*/
public function bootstrap(): void
{
parent::bootstrap();
$this->addPlugin('BEdita/I18n');
}
// other stuff here
}
namespace App;
use BEdita\I18n\Middleware\I18nMiddleware;
use Cake\Http\BaseApplication;
use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;
/**
* Application setup class.
*/
class Application extends BaseApplication
{
/**
* {inheritDoc}
*/
public function bootstrap(): void
{
parent::bootstrap();
// Do not add I18nMiddleware automatically
$this->addPlugin('BEdita/I18n', ['middleware' => false]);
}
/**
* {@inheritDoc}
*/
public function middleware($middlewareQueue) : MiddlewareQueue
{
$middlewareQueue
->add(ErrorHandlerMiddleware::class)
->add(AssetMiddleware::class)
// Add programmatically I18n middleware.
->add(new I18nMiddleware())
->add(new RoutingMiddleware($this));
return $middlewareQueue;
}
}