You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I add a class for multi language I encounter a problem with the Router class. How can we together adjust a Router class to add an option and check if there is any added language and if that language opens in any of the following examples:
https://**en.site.com https://site.com**/en/
or.... https://site.com -> en
https:/site.de -> de https://site.it -> it
The text was updated successfully, but these errors were encountered:
The Router class is only to render a page. This doesn't work exactly as other frameworks but I recommend that you instead create a separate layout or a view for other languages.
For example, if someone visits https://site.com/de you could capture that /de and render a view e.g. app/views/languages/de.php (Option #1) or if the domain is like https:/site.de you can instead use the Option #2
Add a route inside app/routes.php (You can use :any:int or :str): get('/:any', 'HomeController@index');
Modify app/controllers/HomeController.php:
<?php
class HomeController
{
// based on the route we added above, access it as a parameter:
public function index($language = null) {
if (!empty($language)) {
return View::render("languages/$language"); // auto load view based on url.
}
else {
return View::render('index'); // default view
}
}
}
You don't need to touch the app/routes.php, now in your app/controllers/HomeController:
<?php
class HomeController
{
public function index() {
// do your necessary logic here to capture the TLD
$tld = 'de';
return View::render("languages/$tld");
}
}
I hope this will help you. You can help me improve this project let me know if you're interested.
If I add a class for multi language I encounter a problem with the Router class. How can we together adjust a Router class to add an option and check if there is any added language and if that language opens in any of the following examples:
https://**en.site.com
https://site.com**/en/
or....
https://site.com -> en
https:/site.de -> de
https://site.it -> it
The text was updated successfully, but these errors were encountered: