2017-04-03 554 views
0

現在我正在開發一個項目,該項目有一個多語種項目,即英語,中文,丹麥語,韓語等。頁面URL必須根據所選語言進行更改。像:多種語言的網址

English : example.com/pages/fullpage 
Chinese : example.com/ch/頁面/整頁 
Danish : example.com/dk/sider/fuldside 

我已經閱讀CakePhp 3.x文件,但我無法得到正確的答案。我通過路由來完成。 像:

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']); 
}); 

它完美,但我想可靠的概念,因爲在這種情況下,我需要定義路由的所有操作。

所以,如果你有任何想法,請幫助。

在此先感謝。

回答

1

相反只不過是你se the translation methodstoggle the language你用它來設置任何參數編寫數千條路徑的:

// Detect and set language before, we use a middleware 
$routes->connect('/' . __d('routes', 'pages') . '/' . __d('routes', 'fullpage'), [ /*...*/]); 

這就是我們使用的方法〜20種語言在我們的網站。