1. Go to this page and download the library: Download xfra35/f3-multilang 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/ */
$f3->reroute('@contact'); // OK => reroute to /xx/contact where xx is the current language
$f3->reroute('/en/contact'); // OK
$f3->reroute('/contact'); // Error => 404 Not Found
$ml->reroute('/en/contact'); // OK
$ml->reroute('/contact'); // OK => reroute to /xx/contact where xx is the current language
$f3->set('ONREROUTE',function($url,$permanent) use($f3,$ml){
$f3->clear('ONREROUTE');
$ml->reroute($url,$permanent);
});
// then in your controller, existing reroutes will keep on working:
$f3->reroute('/contact'); // OK => reroute to /xx/contact where xx is the current language
$ml = Multilang::instance();
echo $ml->current;// ja
echo $ml->primary;// en
echo $ml->auto;//FALSE
echo $ml->passthru;//FALSE
echo $ml->locale();// en_GB.UTF-8
// on a Danish route (with intl)
echo $ml->displayLanguage('fr');// fransk
// on a Russian route (with intl)
echo $ml->displayLanguage('fr');// французский
// on any route (without intl)
echo $ml->displayLanguage('fr');// French
// on a Danish route (with intl)
echo $ml->displayCountry('ru');// Rusland
// on a Russian route (with intl)
echo $ml->displayCountry('ru');// Россия
// on any route (without intl)
echo $ml->displayCountry('ru');// Russia