• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multilanguage

#1
Hello everyone, I read the Localization documentation, I did everything, everything works, but here's how to do it so that if we have, for example, the default language EN, then if we are on the main one so that this prefix is not in the link.
I made a filter like this

PHP Code:
<?php namespace MVP\Core\Filters;

use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;

class 
Locales implements FilterInterface
{
    public function before(RequestInterface $request$arguments null)
    {
        $namec 'MVP\Pages\Controllers\Site';
        if (class_exists($namec)) {

            $config config('MVP');
            if ($config->multiLang) {
                $supportedLocales $request->config->supportedLocales;
                $seg $request->uri->getSegment(1);

                if ($seg == '')
                    return redirect()->to(service('request')->getLocale());
                if (!in_array($seg$supportedLocales))
                    return redirect()->back();
            }
        }
        else{
            $seg $request->uri->getPath();
            $supportedLocales $request->config->supportedLocales;
            if($seg == '/' or in_array($seg$supportedLocales))
                return redirect()->to(site_url_lang('login'));
        }
    }

    //--------------------------------------------------------------------

    public function after(RequestInterface $requestResponseInterface $response$arguments null)
    {
        // Do something here
    }

and that's how the routes are
PHP Code:
<?php namespace MVP\Pages\Config;

$routes->group('/'.config('MVP')->urlAdmin, ['namespace' => 'MVP\Pages\Controllers'], function($routes) {
    $routes->get('pages''Admin::index/all');
    $routes->get('pages/(:any)''Admin::index/$1');
    $routes->post('pages/(:any)''Admin::indexPost/$1');
    $routes->get('pages/(:any)/(:num)''Admin::index/$1/$2');
    $routes->post('pages/(:any)/(:num)''Admin::indexPost/$1/$2');
});
$routes->group('/modal', ['namespace' => 'MVP\Pages\Controllers'], function($routes) {
    /*$routes->get('users/group-del/(:num)', 'Modal::modalDel/$1');
    $routes->post('users/group-del/(:num)', 'Modal::modalDel/$1');
    $routes->get('users/del/(:num)', 'Modal::modalDelUs/$1');
    $routes->post('users/del/(:num)', 'Modal::modalDelUs/$1');*/
});

$routes->group('/', ['namespace' => 'MVP\Pages\Controllers'], function ($routes) {
    $routes->get('''Site::index');
});
$routes->group(config('MVP')->multiLang?'{locale}':'/', ['namespace' => 'MVP\Pages\Controllers'], function($routes) {
    $routes->get('''Site::index');
    $routes->get('(:any)''Site::index/$1');
}); 
and this is how it works if I go to the address / then it will redirect me to the default language and get it like this / en. And I need if the default language is not for this EN prefix. I thought of adding routes not yet for localizations, but it works so crookedly.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.