Right now I'm working on a project, which has a multi lingual project i.e. English, Chinese, Danish, Korean etc. The page URL must be changed based on a selected language. Like :
English : example.com/pages/fullpage
Chinese : example.com/ch/頁面/整頁
Danish : example.com/dk/sider/fuldside
I have read the CakePhp 3.x document, but I can't get a proper answer for it. I do it through routing. Like :
Router::scope('/', function (RouteBuilder $routes) {
$routes->connect('/pages/fullpage', ['controller' => 'pages', 'action' => 'fullpage'] );
$routes->connect('/頁面/整頁', ['controller' => 'pages', 'action' => 'fullpage'] );
$routes->connect('/sider/fuldside', ['controller' => 'pages', 'action' => 'fullpage'] );
});
It works perfectly, but I want reliable concept because in this scenario, I need to define the routing for all actions.
So if you have any thoughts about this please help.
Thanks in advance.
Instead of writing thousands of routes just use the translation methods and toggle the language on whatever parameter you use to set it:
// Detect and set language before, we use a middleware
$routes->connect('/' . __d('routes', 'pages') . '/' . __d('routes', 'fullpage'), [ /*...*/]);
That's the way we use for ~20 languages on our site.