Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi lang hintting #600

Open
testt23 opened this issue Nov 30, 2021 · 2 comments
Open

Multi lang hintting #600

testt23 opened this issue Nov 30, 2021 · 2 comments

Comments

@testt23
Copy link

testt23 commented Nov 30, 2021

Hi, thanks for this brilliant packet!

But.. I have a one small problem. What I want to make?
If someone people is visit my site: www.site.com is the look for default language: English..but if is want to change to France...

    SimpleRouter::partialGroup( '{lang}/', function ($lang = 'en') {
        SimpleRouter::get('/', 'DefaultController@index')->setName('home');  //output: Route not found: "/"
        SimpleRouter::get('/contact', 'DefaultController@contact')->setName('contact');
        SimpleRouter::basic('/companies/{id?}', 'DefaultController@companies')->setName('companies');
    });

I make this.
site.com/ and site.com/en => is default
site.com/fr/ => France language

the small problem is that the way i do it is .. that i want the pages that are added to the language itself to also get the default language.
If you looking the www.site.com/contact (this is the english version) , but to now is not working. To now is working www.ste.com/en/contact

www.site.com/ -> error no working | www.site.com/en -> working correctly
www.site.com/contact -> error no working | www.site.com/en/contact -> working correctly
www.site.com/companies/id/1 -> error no working | www.site.com/en/companies/id/1 -> working correctly

I experimented only with a group: but it still doesn't work the way I want. What can I do?


    Router::group([
        'prefix' => '{lang}',
    ], function ($lang = 'en'){
        SimpleRouter::get('/', 'DefaultController@index')->setName('home'); //output: Route not found: "/"
        SimpleRouter::get('/contact', 'DefaultController@contact')->setName('contact');
        SimpleRouter::basic('/companies/{id?}', 'DefaultController@companies')->setName('companies');
    });

And I check and with this:
'prefix' => '{lang?}',

But nothing.

@DeveloperMarius
Copy link
Contributor

Hello,

my code for that isn't perfect, but here is how I did it.
First I registered three routes:

Router::get('/', '\rpcms\website\controllers\RedirectController@noLanguage');
Router::get('/{language}/', 'IndexController@renderPageView')->where(array('language' => 'de'));
Router::get('/{language}/', 'IndexController@renderPageView')->where(array('language' => 'en'));

OR

Router::get('/{language}/ueber-uns', 'AboutController@renderPageView')->where(array('language' => 'de'));
Router::get('/ueber-uns', '\rpcms\website\controllers\RedirectController@noLanguage');
Router::get('/{language}/about', 'AboutController@renderPageView')->where(array('language' => 'en'));
Router::get('/about', '\rpcms\website\controllers\RedirectController@noLanguage');

Providing a RegEx for language using ->where() I ensure that I still get the language as a parameter.
The IndexController then provides the user with the content in the correct language.

In the RedirectController you then have to handle a request if no language is provided.
I did this by finding the correct Controller by the route and then called him with the language as a parameter. This can be done by a redirect.
The language can be a default language, the language provided by the request headers or the language of the previous page stored in for example a session.

I hope that I could help you.

~ Marius

@DeveloperMarius
Copy link
Contributor

Hello,
if you don't need this functionality anymore or my comment helped you, please close your issue.
Thank you.

~ Marius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants