Setting multiligual routes in Laravel

When you are developing a multilingual website you need to create multilingual translated routes depending on selected languages. A little guidance for that is given below.

Their is a lang folder in your app directory, create the translations for your route here. Create route.php files depending  on the number languages you want  each must be in different language directory.

Example: If you want polish, french, english as languages.

For Polish:

 <?php

// app/lang/pl/routes.php

return array(

    'contact' => 'kontakt',

    'about'   => 'o-nas'

);

For English:

<?php

// app/lang/en/routes.php

return array(

    'contact' => 'contact',

    'about'   => 'about-us'

);

For French:

<?php

// app/lang/fr/routes.php

return array(

    'contact' => 'contact-fr',

    'about'   => 'about-fr'

);

After the routes for all languages has been created go to app/config/app.php and find the line:

'locale' =>'en',

change it to the primary language and add the below code too.

/**

 * List of alternative languages (not including the one specified as 'locale')

 */

'alt_langs' => array ('en', 'fr'),

/**

 *  Prefix of selected locale  - leave empty (set in runtime)

 */

'locale_prefix' => '',

Now go to app/routes.php and put their content. In the file check if the first segment of url matches the name of your language, if it does change locale and current language prefix. In tiny loop set the requirements for your route names of your languages.