Comments (12)
{slug?} done the trick, thx a lot!
from laravel-localized-routes.
Hello,
The /
route needs to get the active locale from the session, which is done by Localizer
.
So I think it should work when you set use_localizer
to true
.
from laravel-localized-routes.
have the same issue with or without localizer
tried:
Route::localized(function () {
Route::get('/', 'PageController@renderIndex');
Route::get('{page}', 'PageController@render');
});
and
Route::localized(function () {
Route::get('{page}', 'PageController@render')->where('page', '.*');
});
from laravel-localized-routes.
Hi,
I think i found the solution.
In the config file ( localized-routes.php ), if your omit_url_prefix_for_locale
is set to en
so in supported-locales
you have to add en
in the last postition like this example below.
return [
'supported-locales' => ['pt', 'fr', 'en'],
'omit_url_prefix_for_locale' => 'en',
'use_locale_middleware' => true,
'use_localizer' => false,
];
I hope it helps you
from laravel-localized-routes.
Hi,
I was able to reproduce it in a test.
It seems the routes are being registered like this:
#items: array:4 [
0 => "/"
1 => "{slug}"
2 => "nl"
3 => "nl/{slug}"
]
So in this case /nl can not be accessed. The {slug} intercepts it.
Looking into it now. 👍
from laravel-localized-routes.
yep, i have the same route registration sequence. Sorry to not attach it before.
Thx for a fast responce!
from laravel-localized-routes.
@NadjmanDev moving the omitted locale to the end seems like the best solution, thanks 👍
Will tag it when tests completed.
from laravel-localized-routes.
Fix has been tagged in 2.2.7 👍
from laravel-localized-routes.
moving the omitted locale works only when you register the same route twice(for root and for anything else)
Route::localized(function () {
Route::get('/', 'PageController@renderIndex');
Route::get('{page}', 'PageController@render');
});
and doesnt work when i tried
Route::localized(function () {
Route::get('{page}', 'PageController@render')->where('page', '.*');
});
checked with 2.2.7 tag
from laravel-localized-routes.
What is the behavior you see?
I don't immediately see why it would make any difference. (but then again it is confusing) :)
from laravel-localized-routes.
I created draft project with 3 route groups(api,admin, web)
at web section i have only
Route::localized(function () {
Route::get('{page}', 'PageController@render')->where('page', '.*');
});
definition for render function:
public function render(Request $request, $page = null)
config:
'supported-locales' => ['be','en','ru'],
'omit_url_prefix_for_locale' => 'ru',
'use_locale_middleware' => true,
'use_localizer' => false,
roule list:
POST | admin/api/token | |
GET|HEAD | api/test | |
GET|HEAD | be/{page} | be. |
GET|HEAD | en/{page} | en. |
GET|HEAD | {page} | ru. |
with this config
domain.com/ - get page variable value null
domain.com/en - get page variable value "en"
domain.com/be - get page variable value "be"
domain.com/ololo - get page variable value "ololo"
domain.com/en/ololo - get page variable value "ololo"
domain.com/be/ololo - get page variable value "ololo"
workaround - change routes to:
Route::localized(function () {
Route::get('/', 'PageController@render');
Route::get('{page}', 'PageController@render')->where('page', '.*');
});
from laravel-localized-routes.
This test passes for me.
Notice the {slug?}
placeholder.
Does this solve your use case?
/** @test */
public function it_registers_a_dynamic_root_route_without_prefix_for_a_configured_main_locale()
{
$this->setSupportedLocales(['en', 'nl']);
$this->setOmitUrlPrefixForLocale('en');
$this->setUseLocaleMiddleware(true);
Route::localized(function () {
Route::get('{slug?}', function ($slug = null) {
return ($slug ?? 'null') . ' ' . App::getLocale();
})->where('page', '.*');
});
$this->assertEquals(
['nl/{slug?}', '{slug?}'],
$this->getRoutes()->pluck('uri')->toArray()
);
$response = $this->call('GET', '/');
$response->assertOk();
$this->assertEquals('null en', $response->original);
$response = $this->call('GET', '/nl');
$response->assertOk();
$this->assertEquals('null nl', $response->original);
$response = $this->call('GET', '/dynamic');
$response->assertOk();
$this->assertEquals('dynamic en', $response->original);
$response = $this->call('GET', '/nl/dynamic');
$response->assertOk();
$this->assertEquals('dynamic nl', $response->original);
}
from laravel-localized-routes.
Related Issues (20)
- How to use with Laravel Route Attributes
- Redirect Issue with Octane HOT 3
- Call to undefined method Composer\Util\Platform::getCwd() HOT 5
- Advanced Scoped Options - Multi-site (domain localization & slug localization) HOT 7
- Scoped Options supported_locales overridden not working
- Fallback Controller Invalid Route Action HOT 4
- Authentication Breaks on Localized Routes HOT 5
- Route not defined. HOT 3
- * Use Localizer to Detect and Set the Locale HOT 1
- Resource routes HOT 2
- composer-include-files dependency breaks autoload-dev files HOT 3
- How to override route helper? HOT 4
- Share routes with front frameworks like Inertia/VueJS HOT 4
- What's the best way to deal with more complex locales like 'ch-fr'? HOT 1
- Subdomain localized urls HOT 6
- How to remove route parameters? HOT 5
- auto redirect HOT 5
- Redirect request with default locale to omitted locale url HOT 4
- Locale Switcher HOT 2
- Call to a member function getAction() on null HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-localized-routes.