[Snippet] Switch language with URL |
Some people around net are digging about how to make their website using multiple languages and allow users to switch this from within URL without modifying routes, adding new routes or using some prefixes/parameters in your controllers.
Some examples on what we are trying to get: http://example.com/content - content with default language http://example.com/en/content - content with english language http://example.com/de/content - content with german language http://example.com/ru/content - content with russian language The simple trick is in modifying query url and checking if first element is withing langeages list. Then just to remove this one, to get modified url parameter. First, you will need to alter your "config.php" file and add a list of all available languages. Code: $config['language'] = 'english'; Now we will have to create new file "MY_Router.php" in "/application/core" folder, with following content: Code: <?php Thats it. Now for example default "welcome" route will be accessible thru "/", "/en", "/de", "/ru" url, you will just have to add some text There is also some other magic, how you can use your Database to get all text translated Enjoy! |
Messages In This Thread |
[Snippet] Switch language with URL - by V I R U S - 03-01-2018, 03:49 AM
RE: [Snippet] Switch language with URL - by Elias - 03-21-2018, 09:30 AM
RE: [Snippet] Switch language with URL - by alamowais - 05-21-2018, 01:56 AM
RE: [Snippet] Switch language with URL - by Abin2015 - 11-10-2019, 10:38 PM
RE: [Snippet] Switch language with URL - by InsiteFX - 11-11-2019, 08:57 AM
RE: [Snippet] Switch language with URL - by ixidev - 07-16-2020, 09:35 AM
RE: [Snippet] Switch language with URL - by mgandy6565 - 07-16-2020, 04:35 PM
RE: [Snippet] Switch language with URL - by InsiteFX - 07-17-2020, 03:24 AM
|