|
10 | 10 | #### A convenient way to set up, manage and use localized routes in a Laravel app.
|
11 | 11 |
|
12 | 12 | - [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. |
13 | 14 | - [Generate localized route URL's](#generate-route-urls) in the simplest way using the `route()` helper.
|
14 | 15 | - [Redirect to localized routes](#redirect-to-routes) using the `redirect()->route()` helper.
|
15 | 16 | - Allow routes to be [cached](#cache-routes).
|
@@ -37,14 +38,26 @@ php artisan vendor:publish --provider="CodeZero\LocalizedRoutes\LocalizedRoutesS
|
37 | 38 |
|
38 | 39 | You will now find a `localized-routes.php` file in the `config` folder.
|
39 | 40 |
|
40 |
| -#### Configure Supported Locales |
| 41 | +#### Configure |
41 | 42 |
|
42 | 43 | Add any locales you wish to support to your published `config/localized-routes.php` file:
|
43 | 44 |
|
44 | 45 | ```php
|
45 | 46 | 'supported-locales' => ['en', 'nl', 'fr'],
|
46 | 47 | ```
|
47 | 48 |
|
| 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 | + |
48 | 61 | ## Register Routes
|
49 | 62 |
|
50 | 63 | Example:
|
@@ -78,6 +91,18 @@ In the above example there are 5 routes being registered. The routes defined in
|
78 | 91 | | /en/admin/reports | en.admin.reports.index |
|
79 | 92 | | /nl/admin/reports | nl.admin.reports.index |
|
80 | 93 |
|
| 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 | + |
81 | 106 | ### Generate Route URL's
|
82 | 107 |
|
83 | 108 | You can get the URL of your named routes as usual, using the `route()` helper.
|
|
0 commit comments