Skip to content

Commit 63dd50e

Browse files
committed
Update README
1 parent 62bf8bc commit 63dd50e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#### A convenient way to set up, manage and use localized routes in a Laravel app.
1111

1212
- [Automatically register](#register-routes) a route for each locale you wish to support.
13+
- Optionally remove the locale slug from the URL for your main language.
1314
- [Generate localized route URL's](#generate-route-urls) in the simplest way using the `route()` helper.
1415
- [Redirect to localized routes](#redirect-to-routes) using the `redirect()->route()` helper.
1516
- Allow routes to be [cached](#cache-routes).
@@ -37,14 +38,26 @@ php artisan vendor:publish --provider="CodeZero\LocalizedRoutes\LocalizedRoutesS
3738

3839
You will now find a `localized-routes.php` file in the `config` folder.
3940

40-
#### Configure Supported Locales
41+
#### Configure
4142

4243
Add any locales you wish to support to your published `config/localized-routes.php` file:
4344

4445
```php
4546
'supported-locales' => ['en', 'nl', 'fr'],
4647
```
4748

49+
Specify your main locale if you want to omit its slug from the URL:
50+
51+
```php
52+
'omit_url_prefix_for_locale' => null
53+
```
54+
55+
Setting this option to `'en'` will result, for example, in URL's like this:
56+
57+
- English: `/some-url` instead of the default `/en/some-url`
58+
- Dutch: `/nl/some-url` as usual
59+
- French: `/fr/some-url` as usual
60+
4861
## Register Routes
4962

5063
Example:
@@ -78,6 +91,18 @@ In the above example there are 5 routes being registered. The routes defined in
7891
| /en/admin/reports | en.admin.reports.index |
7992
| /nl/admin/reports | nl.admin.reports.index |
8093

94+
If you set `omit_url_prefix_for_locale` to `'en'` in the configuration file, the resulting routes look like this:
95+
96+
| URI | Name |
97+
| ----------------- | ---------------------- |
98+
| /home | home |
99+
| /about | en.about |
100+
| /nl/about | nl.about |
101+
| /admin/reports | en.admin.reports.index |
102+
| /nl/admin/reports | nl.admin.reports.index |
103+
104+
**Beware that you don't register the same URL twice when omitting the locale.** You can't have a localized `/about` route and also register a non-localized `/about` route in this case. The same idea applies to the `/` (root) route! Also note that the route names still have the locale prfix.
105+
81106
### Generate Route URL's
82107

83108
You can get the URL of your named routes as usual, using the `route()` helper.

0 commit comments

Comments
 (0)