You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,8 @@
1
+
### 2.0.0
2
+
- Support [contextual binding](https://laravel.com/docs/container#contextual-binding) ([#879](https://github.com/mcamara/laravel-localization/pull/879))
3
+
4
+
For guidance on the upgrade process, please refer to the [UPGRADING.md](/UPGRADING.md) file.
Copy file name to clipboardExpand all lines: README.md
+92-14Lines changed: 92 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Laravel Localization
2
2
3
-
[](https://gitter.im/mcamara/laravel-localization?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://packagist.org/packages/mcamara/laravel-localization)
Return current locale's direction as string (ltr/rtl).
@@ -360,11 +398,14 @@ Note that Route Model Binding is supported.
360
398
You may translate your routes. For example, http://url/en/about and http://url/es/acerca (acerca is about in spanish)
361
399
or http://url/en/article/important-article and http://url/es/articulo/important-article (article is articulo in spanish) would be redirected to the same controller/view as follows:
362
400
363
-
It is necessary that at least the `localize` middleware in loaded in your `Route::group` middleware (See [installation instruction](#LaravelLocalizationRoutes)).
401
+
It is necessary that at least the `localize` middleware in loaded in your `Route::group` middleware (See [installation instruction](#installation)).
364
402
365
403
For each language, add a `routes.php` into `resources/lang/**/routes.php` folder.
366
404
The file contains an array with all translatable routes. For example, like this:
367
405
406
+
> Keep in mind: starting from [Laravel 9](https://laravel.com/docs/9.x/upgrade#the-lang-directory), the `resources/lang` folder is now located in the root project folder (`lang`).
407
+
> If your project has `lang` folder in the root, you must add a `routes.php` into `lang/**/routes.php` folder.
408
+
368
409
```php
369
410
<?php
370
411
// resources/lang/en/routes.php
@@ -461,7 +502,40 @@ To cache your routes, use:
461
502
php artisan route:trans:cache
462
503
```
463
504
464
-
... instead of the normal `route:cache` command.
505
+
... instead of the normal `route:cache` command. Using `artisan route:cache` will **not** work correctly!
506
+
507
+
For the route caching solution to work, it is required to make a minor adjustment to your application route provision.
508
+
509
+
**before laravel 11**
510
+
511
+
In your App's `RouteServiceProvider`, use the `LoadsTranslatedCachedRoutes` trait:
512
+
513
+
```php
514
+
<?php
515
+
class RouteServiceProvider extends ServiceProvider
516
+
{
517
+
use \Mcamara\LaravelLocalization\Traits\LoadsTranslatedCachedRoutes;
518
+
```
519
+
520
+
**after laravel 11**
521
+
522
+
In your App's `AppServiceProvider`, use the `CachedTranslatedRouteLoader` class in register method:
523
+
524
+
```php
525
+
<?php
526
+
class AppServiceProvider extends ServiceProvider
527
+
{
528
+
use \Mcamara\LaravelLocalization\Traits\LoadsTranslatedCachedRoutes;
This package now uses [dependency injection](https://laravel.com/docs/container#introduction) to retrieve dependencies from the container.
3
+
4
+
This modification is a breaking change, especially if you had made extensions to the `__construct` method within the `Mcamara\LaravelLocalization\LaravelLocalization` class.
5
+
You may now use depdency injection in your own implementation and forward the dependencies to the parent constructor.
6
+
```php
7
+
use Mcamara\LaravelLocalization\LaravelLocalization;
8
+
use Illuminate\Contracts\Config\Repository as ConfigRepository;
9
+
use Illuminate\Contracts\Foundation\Application;
10
+
use Illuminate\Contracts\Routing\UrlGenerator;
11
+
use Illuminate\Contracts\Translation\Translator;
12
+
use Illuminate\Http\Request;
13
+
use Illuminate\Routing\Router;
14
+
15
+
class MyLaravelLocalization extends LaravelLocalization
If your previous approach involved overriding the `LaravelLocalization` singleton in the container and generating a new instance of your custom implementation, there's now a more straightforward method for binding. This will automatically inject the correct dependencies for you.
32
+
```diff
33
+
use Mcamara\LaravelLocalization\LaravelLocalization;
34
+
35
+
-$this->app->singleton(LaravelLocalization::class, function () {
0 commit comments