Welcome Guest, Not a member yet? Register   Sign In
Routing Advice
#1

Hi all,

I would like to ask your suggestions about an issue on which I am working:

Imagine a website which has been prepared in a few languages, such as english (en), German (de), Italian (it) etc.

By the way, English is the main/base one.

If I set up the base url for the domain like mywebsite.com, there is no problem to switch to other languages such as : mywebsite.com/de or mywebsite.com/it. Because the site works for English as the base : mywebsite.com/about-us, mywebsite.com/blog-detail etc.

But if I set up the base url for /en , then how can I route for the other languages?
Because my pages are like these:

Code:
$routes->get('en', 'SiteEn::index_en');
$routes->get('en/products', 'SiteEn::product_categories_en');
$routes->get('en/product-detail/(:segment)', 'SiteEn::product_detail_en/$1');
$routes->get('en/contact', 'SiteEn::contact_en');;

$routes->get('en/(:segment)', 'SiteEn::other_pages_en');

//For Other Languages

???

As I don't know which language can the site owner sets in admin panel, I cannot fix it like :

PHP Code:
$routes->get('it/prodotti''SiteIt::categori_dei_prodotti_it'); 

On the contrary it must be aranged automaticaly: (What I want and need):

PHP Code:
$routes->get('-any-language-/-any-segment-''SiteOtherLangs::products_other_lang'); 


As I said if I set the base url for "/en" ,  it works like: mywebsite.com/en/it, not like mywebsite.com/it

What would you suggest for this kind of problem and how do you handle this kind of problem?

Regards
Reply
#2

(01-07-2021, 03:29 AM)demyr Wrote: Hi all,

I would like to ask your suggestions about an issue on which I am working:

Imagine a website which has been prepared in a few languages, such as english (en), German (de), Italian (it) etc.

By the way, English is the main/base one.

If I set up the base url for the domain like mywebsite.com, there is no problem to switch to other languages such as : mywebsite.com/de or mywebsite.com/it. Because the site works for English as the base : mywebsite.com/about-us, mywebsite.com/blog-detail etc.

But if I set up the base url for /en , then how can I route for the other languages?
Because my pages are like these:

Code:
$routes->get('en', 'SiteEn::index_en');
$routes->get('en/products', 'SiteEn::product_categories_en');
$routes->get('en/product-detail/(:segment)', 'SiteEn::product_detail_en/$1');
$routes->get('en/contact', 'SiteEn::contact_en');;

$routes->get('en/(:segment)', 'SiteEn::other_pages_en');

//For Other Languages

???

As I don't know which language can the site owner sets in admin panel, I cannot fix it like :

PHP Code:
$routes->get('it/prodotti''SiteIt::categori_dei_prodotti_it'); 

On the contrary it must be aranged automaticaly: (What I want and need):

PHP Code:
$routes->get('-any-language-/-any-segment-''SiteOtherLangs::products_other_lang'); 


As I said if I set the base url for "/en" ,  it works like: mywebsite.com/en/it, not like mywebsite.com/it

What would you suggest for this kind of problem and how do you handle this kind of problem?

Regards


Hi, have you tried with the {locale} parameter?

https://codeigniter4.github.io/userguide...#in-routes
Reply
#3

(This post was last modified: 01-07-2021, 01:22 PM by demyr.)

@nicojmb Thanks for the suggestion but I believe it is not the thing I need. Because in documentation, for routes, it says

PHP Code:
$routes->get('{locale}/books''App\Books::index'); 

I can understand the "{locale}" part, but it is not "books" in each language. It is different.

books for english pages, it is "libri" for italian or "kitaplar" for Turkish or "bucher" for German. ??
Reply
#4

(01-07-2021, 01:18 PM)demyr Wrote: @nicojmb Thanks for the suggestion but I believe it is not the thing I need. Because in documentation, for routes, it says

PHP Code:
$routes->get('{locale}/books''App\Books::index'); 

I can understand the "{locale}" part, but it is not "books" in each language. It is different.

books for english pages, it is "libri" for italian or "kitaplar" for Turkish or "bucher" for German. ??

Router doesnt have this level of flexibility right now. the only way you can do this is using multiple routes for each language.

for ex:

PHP Code:
$routes->get('en/books''App\Books::index');
$routes->get('de/bucher''App\Books::index'); 
Reply
#5

(This post was last modified: 01-07-2021, 11:56 PM by demyr.)

So, we cannot talk about creating a complete dynamic and flexible cms for customers. They will need us for any kind of routing issue. Unfortunately using such systems like wix or godady things are much wiser for them. It's sad.

Routing system must accept link parameters from the menu which is created by the customer or there must be a menu system like the one you can find within Joomla.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB